[GRASS-SVN] r61568 - grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 8 11:44:59 PDT 2014
Author: huhabla
Date: 2014-08-08 11:44:59 -0700 (Fri, 08 Aug 2014)
New Revision: 61568
Modified:
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py
Log:
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)
Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py 2014-08-08 18:43:36 UTC (rev 61567)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py 2014-08-08 18:44:59 UTC (rev 61568)
@@ -46,6 +46,37 @@
>>> 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 @@
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 @@
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,
More information about the grass-commit
mailing list