From f92af81c0278d36d70348f4534bdc4995bfcca21 Mon Sep 17 00:00:00 2001 From: Juergen Weigert Date: Sun, 21 Jan 2018 22:42:22 +0100 Subject: [PATCH] 0.21 always start a new openscad instance if the command has changed. --- paths2openscad.inx | 2 +- paths2openscad.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/paths2openscad.inx b/paths2openscad.inx index fd7e3dd..85a6c0d 100755 --- a/paths2openscad.inx +++ b/paths2openscad.inx @@ -117,7 +117,7 @@ definition of 96 px = 1 inch = 25.4 mm. (Before inkscape 0.92 the standard was 90 px per inch, Adobe products often use 75 px per inch) -v0.20 +v0.21 Dan Newman (dan newman @ mtbaldy us) Josef Skladanka (jskladan @ redhat com) Juergen Weigert (juergen @ fabmail org) diff --git a/paths2openscad.py b/paths2openscad.py index 1b789fc..e467203 100755 --- a/paths2openscad.py +++ b/paths2openscad.py @@ -66,6 +66,9 @@ # 0.20 do not traverse into objects with style="display:none" # some precondition checks had 'pass' but should have 'continue'. # +# 2018-01-21, juergen@fabmail.org +# 0.21 start a new openscad instance if the command has changed. +# # CAUTION: keep the version numnber in sync with paths2openscad.inx about page # This program is free software; you can redistribute it and/or modify @@ -1257,10 +1260,20 @@ def effect(self): pidfile = tempfile.gettempdir() + os.sep + "paths2openscad.pid" running = False try: - m = re.match(r"(\d+)", open(pidfile).read()) - pid = int(m.group(1)) + m = re.match(r"(\d+)\s+(.*)", open(pidfile).read()) + oldpid = int(m.group(1)) + oldcmd = int(m.group(2)) # print >> sys.stderr, "pid {1} seen in {0}".format(pidfile, pid) - running = IsProcessRunning(pid) + if cmd == oldcmd: + # we found a pidfile and the cmd in there is still identical. + # If we change the filename in the inkscape extension gui, the cmd differs, and + # the still running openscad would not pick up our changes. + # If the command is identical, we check if the pid in the pidfile is alive. + # If so, we assume, the still running openscad will pick up the changes. + # + # WARNING: too much magic here. We cannot really test, if the last assumption holds. + # Comment out the next line to always start a new instance of openscad. + running = IsProcessRunning(oldpid) except: pass if not running: @@ -1275,9 +1288,16 @@ def effect(self): except OSError as e: raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror)) try: - open(pidfile, "w").write(str(proc.pid) + "\n") + open(pidfile, "w").write(str(proc.pid) + "\n" + cmd + "\n") except: pass + else: + ## BUG alert: + # If user changes the file viewed in openscad (save with different name, re-open that name + # without closing openscad, again, the still running openscad does not + # pick up the changes. and we have no way to tell the difference if it did. + pass + if self.options.scad2stl == 'true' or self.options.stlpost == 'true': stl_fname = self.basename + '.stl' @@ -1289,7 +1309,9 @@ def effect(self): import subprocess try: + print >> sys.stderr, "fooo" proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + print >> sys.stderr, "bar" except OSError as e: raise OSError("{0} failed: errno={1} {2}".format(cmd, e.errno, e.strerror)) stdout, stderr = proc.communicate()