[GRASS-SVN] r37122 - grass/branches/releasebranch_6_4/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 10 15:15:43 EDT 2009


Author: martinl
Date: 2009-05-10 15:15:43 -0400 (Sun, 10 May 2009)
New Revision: 37122

Modified:
   grass/branches/releasebranch_6_4/lib/python/grass.py
Log:
grass.parse_command() - parse output by default
		      (merge from trunk, r37121)


Modified: grass/branches/releasebranch_6_4/lib/python/grass.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/grass.py	2009-05-10 19:11:23 UTC (rev 37121)
+++ grass/branches/releasebranch_6_4/lib/python/grass.py	2009-05-10 19:15:43 UTC (rev 37122)
@@ -113,29 +113,31 @@
     return ps.communicate()[0]
 
 def parse_command(*args, **kwargs):
-    """Passes all arguments to read_command, then optionally parses
-    the output.
+    """Passes all arguments to read_command, then parses the output by
+    parse_key_val().
 
-    Output can be automatically parsed if <b>parse</b> parameter is
-    given. Use True for default parse function -- parse_key_val().
+    Parsing function can be optionally given by <b>parse</b> parameter
+    including its arguments, e.g.
+
+    @code
+    parse_command(..., parse = (grass.parse_key_val, { 'sep' : ':' }))
+    @endcode
     """
-    parse = None # do not parse output
+    parse = None
     if kwargs.has_key('parse'):
         if type(kwargs['parse']) is types.TupleType:
             parse = kwargs['parse'][0]
             parse_args = kwargs['parse'][1]
-        else:
-            parse = parse_key_val # use default fn
-            parse_args = {}
         del kwargs['parse']
-
+    
+    if not parse:
+        parse = parse_key_val # use default fn
+        parse_args = {}
+        
     res = read_command(*args, **kwargs)
 
-    if parse:
-        return parse(res, **parse_args)
+    return parse(res, **parse_args)
 
-    return res
-
 def write_command(*args, **kwargs):
     """Passes all arguments to feed_command, with the string specified
     by the 'stdin' argument fed to the process' stdin.



More information about the grass-commit mailing list