Code

LP bug 387446, try subprocess module instead of popen3
authoralvinpenner <alvinpenner@users.sourceforge.net>
Mon, 22 Jun 2009 22:59:36 +0000 (22:59 +0000)
committeralvinpenner <alvinpenner@users.sourceforge.net>
Mon, 22 Jun 2009 22:59:36 +0000 (22:59 +0000)
share/extensions/perspective.py
share/extensions/restack.py
share/extensions/summersnight.py

index 456cde580fcbbcba9441bcba98e78db432257de2..1c5fb9e3ae3b7863ac2e17b3892d60cefebcab25 100755 (executable)
@@ -29,6 +29,12 @@ except:
     inkex.errormsg(_("Failed to import the numpy or numpy.linalg modules. These modules are required by this extension. Please install them and try again.  On a Debian-like system this can be done with the command, sudo apt-get install python-numpy."))
     exit()
 
+try:
+    from subprocess import Popen, PIPE
+    bsubprocess = True
+except:
+    bsubprocess = False
+
 uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0}
 def unittouu(string):
     unit = re.compile('(%s)$' % '|'.join(uuconv.keys()))
@@ -77,10 +83,16 @@ class Project(inkex.Effect):
                 file = self.args[-1]
                 id = self.options.ids[0]
                 for query in q.keys():
-                    f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:]
-                    q[query] = float(f.read())
-                    f.close()
-                    err.close()
+                    if bsubprocess:
+                        p = Popen('inkscape --query-%s --query-id=%s "%s"' % (query,id,file), shell=True, stdout=PIPE, stderr=PIPE)
+                        rc = p.wait()
+                        q[query] = float(p.stdout.read())
+                        err = p.stderr.read()
+                    else:
+                        f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:]
+                        q[query] = float(f.read())
+                        f.close()
+                        err.close()
                 sp = array([[q['x'], q['y']+q['height']],[q['x'], q['y']],[q['x']+q['width'], q['y']],[q['x']+q['width'], q['y']+q['height']]], dtype=float64)
             else:
                 if envelope.tag == inkex.addNS('g','svg'):
index 1f61bd3afb77ce56e8d908a6b04eefcb14bbefd6..e4fb7d25e517214ec412e1d9d4398f0bef5341cc 100644 (file)
@@ -23,6 +23,12 @@ THE SOFTWARE.
 """
 import inkex, os, csv, math
 
+try:
+    from subprocess import Popen, PIPE
+    bsubprocess = True
+except:
+    bsubprocess = False
+
 class Restack(inkex.Effect):
     def __init__(self):
         inkex.Effect.__init__(self)
@@ -50,7 +56,13 @@ class Restack(inkex.Effect):
             file = self.args[ -1 ]
             #get all bounding boxes in file by calling inkscape again with the --querry-all command line option
             #it returns a comma seperated list structured id,x,y,w,h
-            _,f,err = os.popen3( "inkscape --query-all %s" % ( file ) )
+            if bsubprocess:
+                p = Popen('inkscape --query-all "%s"' % (file), shell=True, stdout=PIPE, stderr=PIPE)
+                rc = p.wait()
+                f = p.stdout
+                err = p.stderr
+            else:
+                _,f,err = os.popen3( "inkscape --query-all %s" % ( file ) )
             reader=csv.reader( f.readlines() )
             f.close()
             err.close()
index 2c08c35c4569c874f3f6e88526da360cdc2d6364..86b51d2274176727d947c0c1c911a7972d758be9 100755 (executable)
@@ -22,6 +22,12 @@ from ffgeom import *
 import gettext
 _ = gettext.gettext
 
+try:
+    from subprocess import Popen, PIPE
+    bsubprocess = True
+except:
+    bsubprocess = False
+
 class Project(inkex.Effect):
     def __init__(self):
             inkex.Effect.__init__(self)
@@ -58,10 +64,16 @@ class Project(inkex.Effect):
                 file = self.args[-1]
                 id = self.options.ids[0]
                 for query in self.q.keys():
-                    f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:]
-                    self.q[query] = float(f.read())
-                    f.close()
-                    err.close()
+                    if bsubprocess:
+                        p = Popen('inkscape --query-%s --query-id=%s "%s"' % (query,id,file), shell=True, stdout=PIPE, stderr=PIPE)
+                        rc = p.wait()
+                        self.q[query] = float(p.stdout.read())
+                        err = p.stderr.read()
+                    else:
+                        f,err = os.popen3('inkscape --query-%s --query-id=%s "%s"' % (query,id,file))[1:]
+                        self.q[query] = float(f.read())
+                        f.close()
+                        err.close()
 
                 if obj.tag == inkex.addNS("path",'svg'):
                     self.process_path(obj)