[GRASS-SVN] r37117 - grass/trunk/lib/python

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


Author: glynn
Date: 2009-05-10 14:47:33 -0400 (Sun, 10 May 2009)
New Revision: 37117

Modified:
   grass/trunk/lib/python/grass.py
Log:
Remove parsing functionality from read_command; moved to parse_command


Modified: grass/trunk/lib/python/grass.py
===================================================================
--- grass/trunk/lib/python/grass.py	2009-05-10 18:46:56 UTC (rev 37116)
+++ grass/trunk/lib/python/grass.py	2009-05-10 18:47:33 UTC (rev 37117)
@@ -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]
+        res 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