2

I've created a program that runs externally from GRASS v6.4.1, using python 2.6. It imports an ESRI shapefile, and exports a seperate KML for every polygon in this vector file.

Polygons with islands produce a warning message using "v.out.ogr" saying that features without a category were skipped. Looking into this further, these "skipped" features (islands) are processed later. So the program does what it was designed to do, but I would like it so that this warning message is not printed in the terminal.

VERBOSITY setting were set to "0" using:

os.environ['GRASS_VERBOSE']='0' #runs modules silently

But this doesn't take care of warning messages. I found that there is a gisenv variable called DEBUG, can be set to "0" as well so that all warning messages are silenced too. Problem is, I can't seem to get the proper syntax for my GRASS-python script. I've tried:

grass.gisenv() ['set']='DEBUG=0'

Using this line of code atleast allows the program to run, but warning messages are still printed. Other options I've tried terminate the program.

Has anyone successfully set the DEBUG level to "0" in a GRASS-Python script?

1
  • 1
    BTW: The question title should be changed. The question is not about debugging but to get user warnings to silence. /debug level to "0"/warnings silent/
    – markusN
    Commented Nov 14, 2011 at 22:06

1 Answer 1

4

In C, a warning message can be suppressed by G_suppress_warnings().

http://grass.osgeo.org/programming7/gis_2error_8c.html#a85673d5f53237ae1c016abcc215871c7

I'll verify how to do that in GRASS-Python.


you can suppress most stuff with:

grass.run_command('g.gisenv', set="DEBUG=0")

but DEBUG=0 will not suppress warnings. So for the GRASS GIS version you have there is only one way, to discard stderr. We'll make it more elegant, hopefully for version 6.4.3 and later.


GRASS 7 now supports your wish (see Changeset 51466):

GRASS_VERBOSE=-1 now discards error and warning messages

The source code is available from the GRASS GIS SVN source code repository or next Saturday as SVN snapshot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.