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

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!

···

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@asu.edu

On Wed, Feb 25, 2015 at 4:49 PM, Isaac Ullah <isaac.ullah@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@asu.edu

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

On Thu, Feb 26, 2015 at 1:53 AM, Anna Petrášová <kratochanna@gmail.com> wrote:

On Wed, Feb 25, 2015 at 4:49 PM, Isaac Ullah <isaac.ullah@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.

...

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.

I have added that here:
http://grasswiki.osgeo.org/wiki/Module_command_line_parser#Troubleshooting

Thanks for reporting (and the solution of course!)

Markus

Thank you Anna and Markus. The help is very much appreciated! I will read the linked documentation, and I will review Anna’s proposed changes to r.viewshed.cva and merge them.

May I also suggest that the documentation of the use of “new” for output files be added to the example code in the g.parser man page (http://grass.osgeo.org/grass70/manuals/g.parser.html)? That would make it a lot easier to find for new script writers…

Cheers,

~Isaac

···

On Thu, Feb 26, 2015 at 7:49 AM, Markus Neteler <neteler@osgeo.org> wrote:

On Thu, Feb 26, 2015 at 1:53 AM, Anna Petrášová <kratochanna@gmail.com> wrote:

On Wed, Feb 25, 2015 at 4:49 PM, Isaac Ullah <isaac.ullah@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.

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.

I have added that here:
http://grasswiki.osgeo.org/wiki/Module_command_line_parser#Troubleshooting

Thanks for reporting (and the solution of course!)

Markus

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@asu.edu