[GRASS-SVN] r42685 - grass/branches/develbranch_6/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 1 07:46:54 EDT 2010


Author: glynn
Date: 2010-07-01 11:46:54 +0000 (Thu, 01 Jul 2010)
New Revision: 42685

Modified:
   grass/branches/develbranch_6/lib/python/raster.py
Log:
Fix handling of quiet, verbose, overwrite


Modified: grass/branches/develbranch_6/lib/python/raster.py
===================================================================
--- grass/branches/develbranch_6/lib/python/raster.py	2010-07-01 11:44:33 UTC (rev 42684)
+++ grass/branches/develbranch_6/lib/python/raster.py	2010-07-01 11:46:54 UTC (rev 42685)
@@ -75,7 +75,7 @@
 
 # interface to r.mapcalc
 
-def mapcalc(exp, **kwargs):
+def mapcalc(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
     """!Interface to r.mapcalc.
 
     @param exp expression
@@ -83,17 +83,14 @@
     """
     t = string.Template(exp)
     e = t.substitute(**kwargs)
-    verbose = os.getenv('GRASS_VERBOSE')
-    if kwargs.has_key('quiet') and kwargs['quiet']:
-        os.environ['GRASS_VERBOSE'] = '0'
-    if kwargs.has_key('verbose') and kwargs['verbose']:
-        os.environ['GRASS_VERBOSE'] = '3'
-    
-    if write_command('r.mapcalc', stdin = e) != 0:
-	fatal("An error occurred while running r.mapcalc")
-    
+
+    env = os.environ.copy()
+    if quiet:
+        env['GRASS_VERBOSE'] = '0'
     if verbose:
-        os.environ['GRASS_VERBOSE'] = verbose
-    elif os.getenv('GRASS_VERBOSE'):
-        del os.environ['GRASS_VERBOSE']
-    
+        env['GRASS_VERBOSE'] = '3'
+    if overwrite:
+        env['GRASS_OVERWRITE'] = '1'
+
+    if write_command('r.mapcalc', stdin = e, env = env) != 0:
+	fatal("An error occurred while running r.mapcalc")



More information about the grass-commit mailing list