[GRASS-dev] No "overwrite" option in grass 7 addon scripts?

Anna Petrášová kratochanna at gmail.com
Wed Feb 25 16:53:37 PST 2015


On Wed, Feb 25, 2015 at 4:49 PM, Isaac Ullah <isaac.ullah at asu.edu> wrote:

> Hi all, sorry for the spat of messages today, but as you can tell, I'm
> having trouble getting my addon scripts up to par for GRASS7 standard. I'm
> trying to figure these issues out on my own, but I can't seem to find any
> documentation that can help me do so. My current issue is that I'm noticing
> that my python scripts are lacking the automatically generated flag for
> --overwrite in the GUI. One can add --overwrite to the command line (and it
> works fine), but it's not there in the GUI. I'm trying to use the
> grass.overwrite() syntax for all internal grass module calls in the script,
> and this issue is making that difficult.
>
> I've updated my g.parser header code in the scripts to reflect what I
> believe is the latest syntax (based on other addon scripts in the svn). eg:
>
> #%option G_OPT_R_ELEV
>
> #% key: elev
>
> #% description: Input elevation map (DEM)
>
> #% required : yes
>
> #%END
>
>
> #%option G_OPT_R_INPUT
>
> #% key: output
>
> #% description: Output CVA raster
>
> #% required : yes
>
> #%END
>
>
> But with this I get no overwrite flag option in the GUI, even though other
> addon scripts that seem to be using this DO get overwrite flags added.
>
>
> If I do it the old way:
>
> #%option
>
> #% key: elev
>
> #% type: string
>
> #% gisprompt: old,cell,raster
>
> #% description: Input elevation map (DEM)
>
> #% required : yes
>
> #%END
>
>
> #%option
>
> #% key: output
>
> #% type: string
>
> #% gisprompt: old,cell,raster
>
> #% description: Output CVA raster
>
> #% required : yes
>
> #%END
>
>
> I also get no overwrite option in the module GUI.
>
>
> However, if I do this:
>
>
> #%option
>
> #% key: elev
>
> #% type: string
>
> #% gisprompt: new,cell,raster
>
> #% description: Input elevation map (DEM)
>
> #% required : yes
>
> #%END
>
>
> #%option
>
> #% key: output
>
> #% type: string
>
> #% gisprompt: new,cell,raster
>
> #% description: Output CVA raster
>
> #% required : yes
>
> #%END
>
>
> Then I DO get the overwrite option! However, when I do this, I then get
> the error that my input maps already exist (even though these are just
> input maps, and not output).
>
>
> So, I suppose I'm confused about how I'm supposed to do this now? I've
> looked through the many new pages of python code documentation on the wiki,
> etc, and can't find anything at all about this... Again, any help is
> greatly appreciated!
>

You should be using standardized option G_OPT_R_INPUT, the definition can
be found here:
http://grass.osgeo.org/programming7/parser__standard__options_8c_source.html

The key here is to specify 'new' in gisprompt, but only for output map.
'new' means that a new map will be created and parser then knows that it
should check whether there is already a map of such name and if yes,
require overwrite. Based on 'new', the overwrite flag is created.

Anna


> --
> Isaac I Ullah, Ph.D.
>
> Arizona State University
> School of Human Evolution and Social Change
> PO Box 2402
> Tempe, AZ 85287-2402
> (480) 727-1054 office
> (650) 201-0479 cell
> iullah at asu.edu
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20150225/f9104197/attachment.html>


More information about the grass-dev mailing list