[GRASS5] [bug #4331] (grass) delete if file exist - flag

this bug's URL: http://intevation.de/rt/webrt?serial_num=4331
-------------------------------------------------------------------------

Subject: delete if file exist - flag

Platform: GNU/Linux/x86
grass obtained from: Trento Italy site
grass binary for platform: Compiled from Sources
GRASS Version: cvs 24.04.2006

Hello,

a flag for each module to delete a raster/vector if the file already exists
would be good.
A hidden g.remove with the respective name would do the job. That would make
it easier for users to play with certain settings and not substituting each
time the old name or run g.remove.

BTW the delete file handling is not consistent (but I think that has been
discussed earlier) r.mapcalc is just overwriting the file but e.g. r.rescale
does prompt an error message that the file exist.

regards, Martin

-------------------------------------------- Managed by Request Tracker

Request Tracker wrote:

BTW the delete file handling is not consistent (but I think that has been
discussed earlier) r.mapcalc is just overwriting the file but e.g. r.rescale
does prompt an error message that the file exist.

The libgis functions G_open_cell_new() etc will overwrite an existing
map without complaining. However, G_parser() will generate an error if
an option's gisprompt setting indicates a new map and the map already
exists.

In general, modules which use G_parser() won't allow overwriting
existing maps, while those which don't use it will allow it. Changing
r.mapcalc to use G_parser() isn't really an option, as that would
break all of the existing scripts which use it.

--
Glynn Clements <glynn@gclements.plus.com>

You're in luck. This DOES exist.

Just add --o to the end of a command and it will force an overwrite of any
existing file.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Request Tracker <grass-bugs@intevation.de>
Reply-To: Request Tracker <grass-bugs@intevation.de>
Date: Mon, 24 Apr 2006 18:37:29 +0200 (CEST)
To: <grass5@grass.itc.it>
Subject: [GRASS5] [bug #4331] (grass) delete if file exist - flag

this bug's URL: http://intevation.de/rt/webrt?serial_num=4331
-------------------------------------------------------------------------

Subject: delete if file exist - flag

Platform: GNU/Linux/x86
grass obtained from: Trento Italy site
grass binary for platform: Compiled from Sources
GRASS Version: cvs 24.04.2006

Hello,

a flag for each module to delete a raster/vector if the file already exists
would be good.
A hidden g.remove with the respective name would do the job. That would make
it easier for users to play with certain settings and not substituting each
time the old name or run g.remove.

BTW the delete file handling is not consistent (but I think that has been
discussed earlier) r.mapcalc is just overwriting the file but e.g. r.rescale
does prompt an error message that the file exist.

regards, Martin

-------------------------------------------- Managed by Request Tracker

Hello Michael,

to which command do you refer? I looked into the man pages and found no -o
flag there and tried it inside GRASS with r.resample/r.rescale/r.rescale but
received everytime the "-o is not a valid flag".

stop wait; I tried it with --o (two dashes) and it works.
Why two dashes and not one as every other flag?

thanks for pointing me to it.

Shall I (or somebody else) add "--o" to all r.* html pages?

regards, Martin

On Tuesday 25 April 2006 17:43, Michael Barton wrote:

You're in luck. This DOES exist.

Just add --o to the end of a command and it will force an overwrite of any
existing file.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

> From: Request Tracker <grass-bugs@intevation.de>
> Reply-To: Request Tracker <grass-bugs@intevation.de>
> Date: Mon, 24 Apr 2006 18:37:29 +0200 (CEST)
> To: <grass5@grass.itc.it>
> Subject: [GRASS5] [bug #4331] (grass) delete if file exist - flag
>
> this bug's URL: http://intevation.de/rt/webrt?serial_num=4331
> -------------------------------------------------------------------------
>
> Subject: delete if file exist - flag
>
> Platform: GNU/Linux/x86
> grass obtained from: Trento Italy site
> grass binary for platform: Compiled from Sources
> GRASS Version: cvs 24.04.2006
>
> Hello,
>
> a flag for each module to delete a raster/vector if the file already
> exists would be good.
> A hidden g.remove with the respective name would do the job. That would
> make it easier for users to play with certain settings and not
> substituting each time the old name or run g.remove.
>
> BTW the delete file handling is not consistent (but I think that has been
> discussed earlier) r.mapcalc is just overwriting the file but e.g.
> r.rescale does prompt an error message that the file exist.
>
> regards, Martin
>
>
>
> -------------------------------------------- Managed by Request Tracker

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5

--
Martin Wegmann

DLR - German Aerospace Center
German Remote Sensing Data Center
@
Dept.of Geography
Remote Sensing and Biodiversity Unit
&&
Dept. of Animal Ecology and Tropical Biology
University of Wuerzburg
Am Hubland
97074 Würzburg

phone: +49-(0)931 - 888 4797
mobile: +49-(0)175 2091725
fax: +49-(0)931 - 888 4961
http://www.biota-africa.org
http://www.biogis.de

Martin,

I don't know why --o instead of -o.

I just say discussion of it on the list some time back and filed it away
until I needed it.

It should be documented if it is not.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Martin Wegmann <wegmann@biozentrum.uni-wuerzburg.de>
Reply-To: <wegmann@biozentrum.uni-wuerzburg.de>
Date: Tue, 25 Apr 2006 18:14:48 +0200
To: <grass5@grass.itc.it>
Subject: Re: [GRASS5] [bug #4331] (grass) delete if file exist - flag

Hello Michael,

to which command do you refer? I looked into the man pages and found no -o
flag there and tried it inside GRASS with r.resample/r.rescale/r.rescale but
received everytime the "-o is not a valid flag".

stop wait; I tried it with --o (two dashes) and it works.
Why two dashes and not one as every other flag?

thanks for pointing me to it.

Shall I (or somebody else) add "--o" to all r.* html pages?

regards, Martin

On Tuesday 25 April 2006 17:43, Michael Barton wrote:

You're in luck. This DOES exist.

Just add --o to the end of a command and it will force an overwrite of any
existing file.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Request Tracker <grass-bugs@intevation.de>
Reply-To: Request Tracker <grass-bugs@intevation.de>
Date: Mon, 24 Apr 2006 18:37:29 +0200 (CEST)
To: <grass5@grass.itc.it>
Subject: [GRASS5] [bug #4331] (grass) delete if file exist - flag

this bug's URL: http://intevation.de/rt/webrt?serial_num=4331
-------------------------------------------------------------------------

Subject: delete if file exist - flag

Platform: GNU/Linux/x86
grass obtained from: Trento Italy site
grass binary for platform: Compiled from Sources
GRASS Version: cvs 24.04.2006

Hello,

a flag for each module to delete a raster/vector if the file already
exists would be good.
A hidden g.remove with the respective name would do the job. That would
make it easier for users to play with certain settings and not
substituting each time the old name or run g.remove.

BTW the delete file handling is not consistent (but I think that has been
discussed earlier) r.mapcalc is just overwriting the file but e.g.
r.rescale does prompt an error message that the file exist.

regards, Martin

-------------------------------------------- Managed by Request Tracker

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5

--
Martin Wegmann

DLR - German Aerospace Center
German Remote Sensing Data Center
@
Dept.of Geography
Remote Sensing and Biodiversity Unit
&&
Dept. of Animal Ecology and Tropical Biology
University of Wuerzburg
Am Hubland
97074 Würzburg

phone: +49-(0)931 - 888 4797
mobile: +49-(0)175 2091725
fax: +49-(0)931 - 888 4961
http://www.biota-africa.org
http://www.biogis.de

On Tue, Apr 25, 2006 at 10:06:41AM -0700, Michael Barton wrote:

Martin,

I don't know why --o instead of -o.

I just say discussion of it on the list some time back and filed it away
until I needed it.

It should be documented if it is not.

This (documentation) should be implemented into the parser.
A way could be to check if a module used

cd ~/grass61/lib/gis > grep OUTPUT parser.c
        case G_OPT_R_OUTPUT:
        case G_OPT_V_OUTPUT:

If so, a first flag should be predefined with --o and explanation,
the rest follows as usual. This will give us motivation to then
update to G_OPT_R_OUTPUT and G_OPT_V_OUTPUT everywhere, such as

        parm.output = G_define_standard_option(G_OPT_R_OUTPUT);

or
        parm.output = G_define_standard_option(G_OPT_V_OUTPUT);

Second advantage of using these definitions is that the description
is identical and already translated to all supported languages.

Only, I don't know how to make this suggestion possible...

Markus

to which command do you refer? I looked into the man pages and found
no -o flag there and tried it inside GRASS with
r.resample/r.rescale/r.rescale but received everytime the "-o is not
a valid flag".

stop wait; I tried it with --o (two dashes) and it works.
Why two dashes and not one as every other flag?

Because it's not a module flag, it's a parser flag (like --help). It's a
system wide setting and some modules already use a "-o" flag.

Shall I (or somebody else) add "--o" to all r.* html pages?

No, documenting it needs a general solution, not just raster modules.
See Markus's post.
Doing something like "add to all r.* html pages" should be automated,
not done by hand. Makes it 1000% easier to maintain that way.

Also, there is the GIS variable "OVERWRITE" (g.gisenv)
http://grass.ibiblio.org/grass61/manuals/html61_user/variables.html

[all modules]
  toggles map overwrite.
    With 0 maps are protected (default),
    With 1 maps with identical names will be overwritten.
  You can force a protected overwrite by adding "--o" to the command.
e.g.:
g.gisenv set="OVERWRITE=0"

So "--o" is documented somewhere, it is just a bit hidden.

Hamish

This functionaltiy would have been really good to know about! I have been
scripting around the overwrite problem without knowing that the --o flag
existed:

eval `g.findfile mapset=PERMANENT element=cell file=$MAP`
if [ -n "$file" ] ; then
echo "Error: file already exists, removing... "
g.remove rast=$MAP
else
...

Oh well, I get to trim out a lot of useless code from my scripts now :wink:

~ Eric.

-----Original Message-----
From: grass5-admin@grass.itc.it
To: wegmann@biozentrum.uni-wuerzburg.de; grass5@grass.itc.it
Sent: 4/25/2006 1:06 PM
Subject: Re: [GRASS5] [bug #4331] (grass) delete if file exist - flag

Martin,

I don't know why --o instead of -o.

I just say discussion of it on the list some time back and filed it away
until I needed it.

It should be documented if it is not.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Martin Wegmann <wegmann@biozentrum.uni-wuerzburg.de>
Reply-To: <wegmann@biozentrum.uni-wuerzburg.de>
Date: Tue, 25 Apr 2006 18:14:48 +0200
To: <grass5@grass.itc.it>
Subject: Re: [GRASS5] [bug #4331] (grass) delete if file exist - flag

Hello Michael,

to which command do you refer? I looked into the man pages and found

no -o

flag there and tried it inside GRASS with

r.resample/r.rescale/r.rescale but

received everytime the "-o is not a valid flag".

stop wait; I tried it with --o (two dashes) and it works.
Why two dashes and not one as every other flag?

thanks for pointing me to it.

Shall I (or somebody else) add "--o" to all r.* html pages?

regards, Martin

On Tuesday 25 April 2006 17:43, Michael Barton wrote:

You're in luck. This DOES exist.

Just add --o to the end of a command and it will force an overwrite

of any

existing file.

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: Request Tracker <grass-bugs@intevation.de>
Reply-To: Request Tracker <grass-bugs@intevation.de>
Date: Mon, 24 Apr 2006 18:37:29 +0200 (CEST)
To: <grass5@grass.itc.it>
Subject: [GRASS5] [bug #4331] (grass) delete if file exist - flag

this bug's URL: http://intevation.de/rt/webrt?serial_num=4331

------------------------------------------------------------------------
-

Subject: delete if file exist - flag

Platform: GNU/Linux/x86
grass obtained from: Trento Italy site
grass binary for platform: Compiled from Sources
GRASS Version: cvs 24.04.2006

Hello,

a flag for each module to delete a raster/vector if the file already
exists would be good.
A hidden g.remove with the respective name would do the job. That

would

make it easier for users to play with certain settings and not
substituting each time the old name or run g.remove.

BTW the delete file handling is not consistent (but I think that has

been

discussed earlier) r.mapcalc is just overwriting the file but e.g.
r.rescale does prompt an error message that the file exist.

regards, Martin

-------------------------------------------- Managed by Request

Tracker

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5

--
Martin Wegmann

DLR - German Aerospace Center
German Remote Sensing Data Center
@
Dept.of Geography
Remote Sensing and Biodiversity Unit
&&
Dept. of Animal Ecology and Tropical Biology
University of Wuerzburg
Am Hubland
97074 Würzburg

phone: +49-(0)931 - 888 4797
mobile: +49-(0)175 2091725
fax: +49-(0)931 - 888 4961
http://www.biota-africa.org
http://www.biogis.de

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5

Hi,

This (documentation) should be implemented into the parser.
A way could be to check if a module used

cd ~/grass61/lib/gis > grep OUTPUT parser.c
        case G_OPT_R_OUTPUT:
        case G_OPT_V_OUTPUT:

A simpler and more accurate way would be to check, in parser.c, if any of the
options use a gisprompt of new,*. But this option really only works for c
modules. The check_overwrite routine in parser.c will probably reject the map
name again in modules called from a script that was passed the --o flag.

Scripts probably won't notice this nor pass it to modules that the script
calls. I'm not sure if there's even a method for passing this back to the
script from g.parser. There is a grass environment variable OVERWRITE that
parser.c checks as well as the --o flag, but I don't think it's set for
scripts run by g.parser. Should it be for consistency (seems dangerous)?

Perhaps it would be possible for parser.c to tell the difference between a
call from g.parser and a call from other modules to produce this help output
only for c grass modules that use new,*.

Anyway, I didn't find a simple change that won't produce false positives on
scripts.

--Cedric

Cedric Shock wrote:

> This (documentation) should be implemented into the parser.
> A way could be to check if a module used
>
> cd ~/grass61/lib/gis > grep OUTPUT parser.c
> case G_OPT_R_OUTPUT:
> case G_OPT_V_OUTPUT:

A simpler and more accurate way would be to check, in parser.c, if any of the
options use a gisprompt of new,*. But this option really only works for c
modules. The check_overwrite routine in parser.c will probably reject the map
name again in modules called from a script that was passed the --o flag.

Scripts probably won't notice this nor pass it to modules that the script
calls. I'm not sure if there's even a method for passing this back to the
script from g.parser. There is a grass environment variable OVERWRITE that
parser.c checks as well as the --o flag, but I don't think it's set for
scripts run by g.parser. Should it be for consistency (seems dangerous)?

g.parser doesn't pass parser options back to the script, only the
flags and options defined with G_define_{flag,option}.

I would have thought that it would be sufficient for G_parser() to set
OVERWRITE itself if --o was used. That would then be inherited by the
script and by any modules which it calls.

Perhaps it would be possible for parser.c to tell the difference between a
call from g.parser and a call from other modules to produce this help output
only for c grass modules that use new,*.

If that's needed, add a function to parser.c to enable the feature,
and change g.parser to call it. That's more robust than trying to
autodetect g.parser.

--
Glynn Clements <glynn@gclements.plus.com>

Hey,

The help output for modules using a "new,*" gisprompt now includes the --o
flag. It's omitted from the xml output because it doesn't fit the current
scheme.

I would have thought that it would be sufficient for G_parser() to set
OVERWRITE itself if --o was used. That would then be inherited by the
script and by any modules which it calls.

G_parser now sets, but doesn't export, the OVERWRITE environment variable.

> Perhaps it would be possible for parser.c to tell the difference between
> a call from g.parser and a call from other modules to produce this help
> output only for c grass modules that use new,*.

No need for this since it's working for scripts now.

If that's needed, add a function to parser.c to enable the feature,
and change g.parser to call it. That's more robust than trying to
autodetect g.parser.

I'd have done it that way :wink:

--Cedric

G_parser now sets, but doesn't export, the OVERWRITE environment
variable.

For consistency with other g.parser set vars shouldn't it be
GIS_OVERWRITE? ($GIS_OPT_ $GIS_FLAG_)

Does the new fn check G__getenv() for OVERWRITE=1 and if found set the
enviro var even if --o wasn't given? Redundant for the modules, but not
for example the r.blend $.r $.g $.b check.
?

Hamish

Hamish wrote:

> G_parser now sets, but doesn't export, the OVERWRITE environment
> variable.

For consistency with other g.parser set vars shouldn't it be
GIS_OVERWRITE? ($GIS_OPT_ $GIS_FLAG_)

It isn't quite the same thing; $GIS_{OPT,FLAG}_* are purely for
communication between g.parser and the script, while [GRASS_]OVERWRITE
is meant to be propagated down into the commands which the script
runs.

[The GIS_{OPT,FLAG}_* variables will also be propagated, but that's an
unintentional side-effect of using environment variables. With
[GRASS_]OVERWRITE, it's intentional.]

Does the new fn check G__getenv() for OVERWRITE=1 and if found set the
enviro var even if --o wasn't given? Redundant for the modules, but not
for example the r.blend $.r $.g $.b check.
?

It should do now; see Cedric's follow-up.

--
Glynn Clements <glynn@gclements.plus.com>