[GRASS-SVN] r61083 - grass/trunk/lib/python/pygrass/modules/interface
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 30 17:20:40 PDT 2014
Author: huhabla
Date: 2014-06-30 17:20:40 -0700 (Mon, 30 Jun 2014)
New Revision: 61083
Modified:
grass/trunk/lib/python/pygrass/modules/interface/module.py
Log:
Fixed wrong stdout and stderr handling that result in an exception
when the module is run twice and stderr was set to PIPE.
Modified: grass/trunk/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/module.py 2014-06-30 22:03:01 UTC (rev 61082)
+++ grass/trunk/lib/python/pygrass/modules/interface/module.py 2014-07-01 00:20:40 UTC (rev 61083)
@@ -93,6 +93,37 @@
>>> 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 @@
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 @@
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