Sfoglia il codice sorgente

pygrass: Fixed wrong stdout and stderr handling that result in an exception when the module is run twice and stderr was set to PIPE. (backport from trunk)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@61568 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 10 anni fa
parent
commit
653d7f5bb4
1 ha cambiato i file con 34 aggiunte e 6 eliminazioni
  1. 34 6
      lib/python/pygrass/modules/interface/module.py

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

@@ -46,6 +46,37 @@ u'r.neighbors method=average size=3 quantile=0.5'
 >>> new_neighbors3.get_bash()
 u'r.neighbors input=mapA method=average size=3 quantile=0.5 output=mapB'
 
+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,
@@ -334,10 +365,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_']
@@ -475,10 +506,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,