[GRASS-SVN] r33718 - in grass/trunk: lib/python scripts/d.polar scripts/db.test scripts/i.in.spotvgt scripts/i.spectral scripts/m.proj scripts/r.in.aster scripts/r.in.srtm scripts/v.db.reconnect.all scripts/v.in.e00

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 7 06:20:53 EDT 2008


Author: glynn
Date: 2008-10-07 06:20:53 -0400 (Tue, 07 Oct 2008)
New Revision: 33718

Modified:
   grass/trunk/lib/python/grass.py
   grass/trunk/scripts/d.polar/d.polar.py
   grass/trunk/scripts/db.test/db.test.py
   grass/trunk/scripts/i.in.spotvgt/i.in.spotvgt.py
   grass/trunk/scripts/i.spectral/i.spectral.py
   grass/trunk/scripts/m.proj/m.proj.py
   grass/trunk/scripts/r.in.aster/r.in.aster.py
   grass/trunk/scripts/r.in.srtm/r.in.srtm.py
   grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py
   grass/trunk/scripts/v.in.e00/v.in.e00.py
Log:
Add, use interface to subprocess module


Modified: grass/trunk/lib/python/grass.py
===================================================================
--- grass/trunk/lib/python/grass.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/lib/python/grass.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -5,6 +5,30 @@
 import re
 import atexit
 
+# subprocess wrapper that uses shell on Windows
+
+class Popen(subprocess.Popen):
+    def __init__(self, args, bufsize=0, executable=None,
+                 stdin=None, stdout=None, stderr=None,
+                 preexec_fn=None, close_fds=False, shell=None,
+                 cwd=None, env=None, universal_newlines=False,
+                 startupinfo=None, creationflags=0):
+
+	if shell == None:
+	    shell = (sys.platform == "win32")
+
+	subprocess.Popen.__init__(self, args, bufsize, executable,
+                 stdin, stdout, stderr,
+                 preexec_fn, close_fds, shell,
+                 cwd, env, universal_newlines,
+                 startupinfo, creationflags)
+
+PIPE = subprocess.PIPE
+STDOUT = subprocess.STDOUT
+
+def call(*args, **kwargs):
+    return Popen(*args, **kwargs).wait()
+
 # GRASS-oriented interface to subprocess module
 
 _popen_args = ["bufsize", "executable", "stdin", "stdout", "stderr",
@@ -46,18 +70,18 @@
 	else:
 	    options[opt] = val
     args = make_command(prog, flags, overwrite, quiet, verbose, **options)
-    return subprocess.Popen(args, **popts)
+    return Popen(args, **popts)
 
 def run_command(*args, **kwargs):
     ps = start_command(*args, **kwargs)
     return ps.wait()
 
 def pipe_command(*args, **kwargs):
-    kwargs['stdout'] = subprocess.PIPE
+    kwargs['stdout'] = PIPE
     return start_command(*args, **kwargs)
 
 def feed_command(*args, **kwargs):
-    kwargs['stdin'] = subprocess.PIPE
+    kwargs['stdin'] = PIPE
     return start_command(*args, **kwargs)
 
 def read_command(*args, **kwargs):
@@ -66,7 +90,7 @@
 
 def write_command(*args, **kwargs):
     stdin = kwargs['stdin']
-    kwargs['stdin'] = subprocess.PIPE
+    kwargs['stdin'] = PIPE
     p = start_command(*args, **kwargs)
     p.stdin.write(stdin)
     p.stdin.close()
@@ -300,7 +324,7 @@
 def find_program(pgm, args = []):
     nuldev = file(os.devnull, 'w+')
     try:
-	subprocess.call([pgm] + args, stdin = nuldev, stdout = nuldev, stderr = nuldev)
+	call([pgm] + args, stdin = nuldev, stdout = nuldev, stderr = nuldev)
 	found = True
     except:
 	found = False

Modified: grass/trunk/scripts/d.polar/d.polar.py
===================================================================
--- grass/trunk/scripts/d.polar/d.polar.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/d.polar/d.polar.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -54,7 +54,6 @@
 import types
 import math
 import atexit
-import subprocess
 import glob
 import shutil
 import grass
@@ -66,7 +65,7 @@
 
 def plot_xgraph():
     newline = ['\n']
-    p = subprocess.Popen(['xgraph'], stdin = subprocess.PIPE)
+    p = grass.Popen(['xgraph'], stdin = grass.PIPE)
     for point in sine_cosine_replic + newline + outercircle + newline + vector:
 	if isinstance(point, types.TupleType):
 	    p.stdin.write("%f %f\n" % point)

Modified: grass/trunk/scripts/db.test/db.test.py
===================================================================
--- grass/trunk/scripts/db.test/db.test.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/db.test/db.test.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -27,7 +27,6 @@
 
 import sys
 import os
-import subprocess
 import grass
 
 def main():
@@ -71,7 +70,7 @@
 	expf.close()
 
 	if type == 'S':
-	    if subprocess.call(['diff', result, expected]) != 0:
+	    if grass.call(['diff', result, expected]) != 0:
 		grass.error("RESULT: ******** ERROR ********")
 	    else:
 		grass.message("RESULT: OK")

Modified: grass/trunk/scripts/i.in.spotvgt/i.in.spotvgt.py
===================================================================
--- grass/trunk/scripts/i.in.spotvgt/i.in.spotvgt.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/i.in.spotvgt/i.in.spotvgt.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -54,7 +54,6 @@
 
 import sys
 import os
-import subprocess
 import atexit
 import grass
 
@@ -143,7 +142,7 @@
 	grass.fatal("Please extract %s before import." % infile)
 
     try:
-	p = subprocess.Popen(['file', '-ib', infile], stdout = subprocess.PIPE)
+	p = grass.Popen(['file', '-ib', infile], stdout = grass.PIPE)
 	s = p.communicate()[0]
 	if s == "application/x-zip":
 	    grass.fatal("Please extract %s before import." % infile)

Modified: grass/trunk/scripts/i.spectral/i.spectral.py
===================================================================
--- grass/trunk/scripts/i.spectral/i.spectral.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/i.spectral/i.spectral.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -63,7 +63,6 @@
 
 import sys
 import os
-import subprocess
 import atexit
 import glob
 import grass
@@ -182,9 +181,9 @@
     plotf.close()
 
     if output:
-	subprocess.call(['gnuplot', plotfile])
+	grass.call(['gnuplot', plotfile])
     else:
-	subprocess.call(['gnuplot', '-persist', plotfile])
+	grass.call(['gnuplot', '-persist', plotfile])
 
 if __name__ == "__main__":
     options, flags = grass.parser()

Modified: grass/trunk/scripts/m.proj/m.proj.py
===================================================================
--- grass/trunk/scripts/m.proj/m.proj.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/m.proj/m.proj.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -74,7 +74,6 @@
 
 import sys
 import os
-import subprocess
 import grass
 
 def main():
@@ -180,7 +179,7 @@
     #   cs2cs | sed -e 's/d/:/g' -e "s/'/:/g"  -e 's/"//g'
 
     cmd = ['cs2cs'] + outfmt + in_proj.split() + ['+to'] + out_proj.split()
-    p = subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = outf)
+    p = grass.Popen(cmd, stdin = grass.PIPE, stdout = outf)
 
     while True:
 	line = inf.readline()

Modified: grass/trunk/scripts/r.in.aster/r.in.aster.py
===================================================================
--- grass/trunk/scripts/r.in.aster/r.in.aster.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/r.in.aster/r.in.aster.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -60,7 +60,6 @@
 
 import sys
 import os
-import subprocess
 import platform
 import grass
 
@@ -159,13 +158,11 @@
         cmd = ["arch", "-i386", "gdalwarp", "-t_srs", proj, srcfile, tempfile ]
     else:
         cmd = ["gdalwarp", "-t_srs", proj, srcfile, tempfile ]
-    p = subprocess.call(cmd)
+    p = grass.call(cmd)
     if p != 0:
         #check to see if gdalwarp executed properly
         return
 
-    #p = subprocess.call(["gdal_translate", srcfile, tempfile])
-
     #import geotiff to GRASS
     grass.message("Importing into GRASS ...")
     outfile = "%s.%s" % (output, band)

Modified: grass/trunk/scripts/r.in.srtm/r.in.srtm.py
===================================================================
--- grass/trunk/scripts/r.in.srtm/r.in.srtm.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/r.in.srtm/r.in.srtm.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -110,7 +110,6 @@
 
 import sys
 import os
-import subprocess
 import shutil
 import atexit
 import grass
@@ -160,7 +159,7 @@
 	# make it quiet in a safe way (just in case -qq isn't portable)
 	tenv = os.environ.copy()
 	tenv['UNZIP'] = '-qq'
-	if subprocess.call(['unzip', '-t', zipfile], env = tenv) != 0:
+	if grass.call(['unzip', '-t', zipfile], env = tenv) != 0:
 	    grass.fatal("'%s' does not appear to be a valid zip file." % zipfile)
 
 	is_zip = True
@@ -191,7 +190,7 @@
     if is_zip:
         #unzip & rename data file:
 	grass.message("Extracting '%s'..." % infile)
-	if subprocess.call(['unzip', zipfile], env = tenv) != 0:
+	if grass.call(['unzip', zipfile], env = tenv) != 0:
 	    grass.fatal("Unable to unzip file.")
 
     grass.message("Converting input file to BIL...")

Modified: grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py
===================================================================
--- grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/v.db.reconnect.all/v.db.reconnect.all.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -45,7 +45,6 @@
 import sys
 import os
 import grass
-import subprocess
 
 def main():
     old_database = options['old_database']

Modified: grass/trunk/scripts/v.in.e00/v.in.e00.py
===================================================================
--- grass/trunk/scripts/v.in.e00/v.in.e00.py	2008-10-07 10:01:59 UTC (rev 33717)
+++ grass/trunk/scripts/v.in.e00/v.in.e00.py	2008-10-07 10:20:53 UTC (rev 33718)
@@ -54,7 +54,6 @@
 import sys
 import os
 import shutil
-import subprocess
 import glob
 import grass
 
@@ -126,15 +125,15 @@
     nuldev = file(os.devnull, 'w+')
 
     grass.message("An error may appear next which will be ignored...")
-    if subprocess.call(['avcimport', filename, e00shortname], stdout = nuldev, stderr = nuldev) == 1:
+    if grass.call(['avcimport', filename, e00shortname], stdout = nuldev, stderr = nuldev) == 1:
 	grass.message("E00 ASCII found and converted to Arc Coverage in current directory")
     else:
 	grass.message("E00 Compressed ASCII found. Will uncompress first...")
 	grass.try_remove(e00shortname)
 	grass.try_remove(info)
-	subprocess.call(['e00conv', filename, e00tmp + '.e00'])
+	grass.call(['e00conv', filename, e00tmp + '.e00'])
 	grass.message("...converted to Arc Coverage in current directory")
-	subprocess.call(['avcimport', e00tmp + '.e00', e00shortname], stderr = nuldev)
+	grass.call(['avcimport', e00tmp + '.e00', e00shortname], stderr = nuldev)
 
     #SQL name fix:
     name = name.replace('-', '_')



More information about the grass-commit mailing list