Explorar o código

Fixed wrong stdout and stderr handling that result in an exception
when the module is run twice and stderr was set to PIPE.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61083 15284696-431f-4ddb-bdfa-cd5b030d7da7

Soeren Gebbert %!s(int64=11) %!d(string=hai) anos
pai
achega
74b57034d0
Modificáronse 1 ficheiros con 34 adicións e 6 borrados
  1. 34 6
      lib/python/pygrass/modules/interface/module.py

+ 34 - 6
lib/python/pygrass/modules/interface/module.py

@@ -93,6 +93,37 @@ Module('r.colors')
 >>> stderr.strip()
 "Color table for raster map <test_a> set to 'rules'"
 
+Run a second time
+>>> colors.run()
+Module('r.colors')
+>>> stdout, stderr = colors.popen.communicate(input="1 blue")
+>>> colors.popen.returncode
+0
+>>> stdout
+>>> stderr.strip()
+"Color table for raster map <test_a> set to 'rules'"
+
+Multiple run test
+>>> colors = pymod.Module("r.colors", map="test_a",
+...                                            color="ryb", run_=False)
+>>> colors.run()
+Module('r.colors')
+>>> colors(color="gyr")
+>>> colors.run()
+Module('r.colors')
+>>> colors(color="ryg")
+>>> colors(stderr_=PIPE)
+>>> colors.run()
+Module('r.colors')
+>>> print(colors.outputs["stderr"].value.strip())
+Color table for raster map <test_a> set to 'ryg'
+>>> colors(color="byg")
+>>> colors(stdout_=PIPE)
+>>> colors.run()
+Module('r.colors')
+>>> print(colors.outputs["stderr"].value.strip())
+Color table for raster map <test_a> set to 'byg'
+
 @endcode
 """
 from __future__ import (nested_scopes, generators, division, absolute_import,
@@ -383,10 +414,10 @@ class Module(object):
             self.inputs['stdin'].value = kargs['stdin_']
             del(kargs['stdin_'])
         if 'stdout_' in kargs:
-            self.outputs['stdout'].value = kargs['stdout_']
+            self.stdout_ = kargs['stdout_']
             del(kargs['stdout_'])
         if 'stderr_' in kargs:
-            self.outputs['stderr'].value = kargs['stderr_']
+            self.stderr_ = kargs['stderr_']
             del(kargs['stderr_'])
         if 'env_' in kargs:
             self.env_ = kargs['env_']
@@ -524,10 +555,7 @@ class Module(object):
         if self.inputs['stdin'].value:
             self.stdin = self.inputs['stdin'].value
             self.stdin_ = PIPE
-        if self.outputs['stdout'].value:
-            self.stdout_ = self.outputs['stdout'].value
-        if self.outputs['stderr'].value:
-            self.stderr_ = self.outputs['stderr'].value
+        
         cmd = self.make_cmd()
         start = time.time()
         self.popen = Popen(cmd,