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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 4 03:52:23 PDT 2012


Author: hamish
Date: 2012-07-04 03:52:22 -0700 (Wed, 04 Jul 2012)
New Revision: 52301

Modified:
   grass/branches/develbranch_6/lib/python/raster.py
Log:
backport mapcalc_start() from trunk

Modified: grass/branches/develbranch_6/lib/python/raster.py
===================================================================
--- grass/branches/develbranch_6/lib/python/raster.py	2012-07-04 10:51:33 UTC (rev 52300)
+++ grass/branches/develbranch_6/lib/python/raster.py	2012-07-04 10:52:22 UTC (rev 52301)
@@ -108,3 +108,32 @@
 
     if write_command('r.mapcalc', stdin = e, env = env) != 0:
 	fatal(_("An error occurred while running r.mapcalc"))
+
+
+def mapcalc_start(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
+    """!Interface to r.mapcalc, doesn't wait for it to finish, returns Popen object.
+
+    \code
+    >>> expr1 = '"%s" = "%s" * 10' % (output, input)
+    >>> expr2 = '...'   # etc.
+    >>> # launch the jobs:
+    >>> p1 = grass.mapcalc_start(expr1)
+    >>> p2 = grass.mapcalc_start(expr2)   # etc.
+    ...
+    >>> # wait for them to finish:
+    >>> p1.wait()
+    >>> p2.wait()   # etc.
+    \endcode
+
+    @param exp expression
+    @param kwargs
+    
+    @return Popen object
+    """
+    t = string.Template(exp)
+    e = t.substitute(**kwargs)
+
+    return start_command('r.mapcalc', expression = e,
+                        quiet = quiet,
+                        verbose = verbose,
+                        overwrite = overwrite)



More information about the grass-commit mailing list