Contents

Scripting

General

See the g.parser module help page. It's an easy way to make your script look and act like a GRASS module, including creating a GUI and help page template for it automatically.

There are a number of other g.* modules which are specifically useful for scripting use.

Verbosity level

Use the "--quiet" (alias --q) and "--verbose" (alias --v) command line arguments to make the script produce more or less messages and info like percent done. This works for almost all modules. The big exception to that is r.mapcalc which doesn't use the standard parser.

For r.mapcalc, or if you want to set a blanket --quiet directive for the whole script, you can set the GRASS_VERBOSE environmental variable. Python's os module has a putenv() function to do that.

Another nice thing about using the enviro variable method is that it is
silently ignored for earlier versions of GRASS. For earlier versions of GRASS
an error happens when "--quiet" isn't recognized as a valid command line
option. (the new 6.2.3 knows to ignore it)