[GRASS-user] GRASS-Python Script: Check if output already exists, overwrite

Johannes Radinger johannesradinger at gmail.com
Thu Apr 11 03:02:18 PDT 2013


Hi,

I would like to check if the file defined as output in a python script
already exists and fire an error when it exists and the overwrite flag is
not set. Furhtermore I'd like
to check this already in the beginning before all calculations in the
script are executed. I thought about something like:

output = options['output']
    if (grass.find_file(name = output, element = 'cell')['file'] and
grass.read_command("g.gisenv", get = "GRASS_OVERWRITE")!=1):
        grass.fatal(_("Output file exists already, either change output
name or set overwrite-flag"))

but what is the correct way to get the information if the overwrite flag is
set
or not for that script? The GRASS-OVERWRITE variable is not set although
the script is launched with --overwrite. So how to get this info?

/Johannes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20130411/05167894/attachment.html>


More information about the grass-user mailing list