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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 10 14:59:33 EDT 2009


Author: martinl
Date: 2009-05-10 14:59:33 -0400 (Sun, 10 May 2009)
New Revision: 37119

Modified:
   grass/branches/develbranch_6/lib/python/grass.py
Log:
glynn: Remove parsing functionality from read_command; moved to parse_command
       (merge from trunk, r37117)


Modified: grass/branches/develbranch_6/lib/python/grass.py
===================================================================
--- grass/branches/develbranch_6/lib/python/grass.py	2009-05-10 18:57:14 UTC (rev 37118)
+++ grass/branches/develbranch_6/lib/python/grass.py	2009-05-10 18:59:33 UTC (rev 37119)
@@ -109,7 +109,14 @@
 def read_command(*args, **kwargs):
     """Passes all arguments to pipe_command, then waits for the process to
     complete, returning its stdout (i.e. similar to shell `backticks`).
+    """
+    ps = pipe_command(*args, **kwargs)
+    return ps.communicate()[0]
 
+def parse_command(*args, **kwargs):
+    """Passes all arguments to read_command, then optionally parses
+    the output.
+
     Output can be automatically parsed if <b>parse</b> parameter is
     given. Use True for default parse function -- parse_key_val().
     """
@@ -122,13 +129,14 @@
             parse = parse_key_val # use default fn
             parse_args = {}
         del kwargs['parse']
-    
-    ps = pipe_command(*args, **kwargs)
+
+    res = read_command(*args, **kwargs)
+
     if parse:
-        return parse(ps.communicate()[0], **parse_args)
-    
-    return ps.communicate()[0]
+        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.
@@ -241,7 +249,7 @@
     by newlines and the key and value are separated by `sep' (default: `=')
     """
     result = {}
-    
+
     if not s:
         return result
     



More information about the grass-commit mailing list