[GRASS-user] info: overwrite option in r.mask

Glynn Clements glynn at gclements.plus.com
Wed Apr 27 11:14:57 EDT 2011


Martin Landa wrote:

> > I just wanted to inform you (developers), but the overwrite option
> > in r.mask is somehow different from the other modules.
> >
> > Especially if it comes to python scripts usually the
> > overwrite option is set with "overwrite=True" but for
> > r.mask it has to be set with a flag like "flags="o"".
> 
> this flag (o) has been already removed in GRASS 7 and replaced by
> `--overwrite`. There is just small bug - the parser doesn't note
> --overwrite flag.

It seems to work for me. Taking r.mask.py and changing the main()
function to just:

	def main():
	    print grass.overwrite()

results in it printing "True" if --o is given or if the
GRASS_OVERWRITE environment variable is set, and "False" otherwise.

r.mask.py checks whether MASK exists. If it does, it aborts with a
fatal error if grass.overwrite() is false.

The mechanism is as follows:

1. G_parser() sets GRASS_OVERWRITE if the --o flag is used, so that
the setting is inherited by any child processes.
[check_overwrite(), lib/gis/parser.c:1302]

2. If g.parser is run without the -s flag, it executes the script, and
the script will inherit all environment variables.
[reinvoke_script(), general/g.parser/main.c:366]

3. If g.parser is run with the -s flag, it writes all option values to
stdout. The values of the GRASS_OVERWRITE and GRASS_VERBOSE
environment variables are included in the output.
[print_options(), general/g.parser/main.c:292 and 295]

4. The Python grass.script.parser() function recognises these settings
and adds them to the environment.
[_parse_opts(), lib/python/core.py:408]

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


More information about the grass-user mailing list