From deab3914a965aa587631d120fe60c932e23b3d70 Mon Sep 17 00:00:00 2001 From: alvinpenner Date: Mon, 22 Jun 2009 22:59:36 +0000 Subject: [PATCH] LP bug 387446, try subprocess module instead of popen3 --- share/extensions/perspective.py | 20 ++++++++++++++++---- share/extensions/restack.py | 14 +++++++++++++- share/extensions/summersnight.py | 20 ++++++++++++++++---- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/share/extensions/perspective.py b/share/extensions/perspective.py index 456cde580..1c5fb9e3a 100755 --- a/share/extensions/perspective.py +++ b/share/extensions/perspective.py @@ -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'): diff --git a/share/extensions/restack.py b/share/extensions/restack.py index 1f61bd3af..e4fb7d25e 100644 --- a/share/extensions/restack.py +++ b/share/extensions/restack.py @@ -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() diff --git a/share/extensions/summersnight.py b/share/extensions/summersnight.py index 2c08c35c4..86b51d227 100755 --- a/share/extensions/summersnight.py +++ b/share/extensions/summersnight.py @@ -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) -- 2.30.2