Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Cheers.

share|improve this question
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 Nov 14 '11 at 22:06
add comment

1 Answer

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.

Update 1: 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.

Update 2: From today onwards, GRASS 7 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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