diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index f976c90..301d9e7 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -15,6 +15,7 @@ import StringIO """ Import scyther components """ import Scyther.Scyther import Scyther.Error +from Scyther.Misc import * """ Import scyther-gui components """ import Tempfile @@ -153,12 +154,14 @@ class AttackThread(threading.Thread): return graphLine("%s [%s]" % (edge,atxt)) - # Precompute font name - # Set a font with sans - # We only retrieve the name, so the size '9' here is - # irrelevant. - font = wx.Font(9,wx.SWISS,wx.NORMAL,wx.NORMAL) - self.fontname = font.GetFaceName() + if sys.platform.startswith("darwin"): + self.fontname = "Helvetica" + elif sys.platform.startswith("win"): + self.fontname = "Courier" + else: + #font = wx.Font(9,wx.SWISS,wx.NORMAL,wx.NORMAL) + #self.fontname = font.GetFaceName() + self.fontname = "\"Helvetica\"" # write all graph lines but add layout modifiers for l in txt.splitlines(): @@ -174,8 +177,9 @@ class AttackThread(threading.Thread): #graphLine("mindist=0.1") # Set fontname - fontstring = "fontname=%s" % (self.fontname) - setAttr(fontstring,EDGE) + if self.fontname: + fontstring = "fontname=%s" % (self.fontname) + setAttr(fontstring) # Stupid Mac <> Graphviz bug fix if (sys.platform.startswith("mac")) or (sys.platform.startswith("darwin")): @@ -194,6 +198,7 @@ class AttackThread(threading.Thread): def makeImage(self,attack): """ create image for this particular attack """ + if Preference.usePIL(): # If we have the PIL library, we can do postscript! great # stuff. @@ -207,23 +212,21 @@ class AttackThread(threading.Thread): # command to write to temporary file (fd2,fpname2) = Tempfile.tempcleaned(ext) f = os.fdopen(fd2,'w') + (fd3,fpname3) = Tempfile.tempcleaned(ext) + dotfile = os.fdopen(fd3,'w') + self.writeGraph(attack.scytherDot,dotfile) + dotfile.flush() + dotfile.seek(0) - cmd = "dot -T%s >%s" % (type,fpname2) + cmd = "dot -T%s -o%s %s" % (type,fpname2,fpname3) # execute command - cin,cout = os.popen2(cmd,'b') - - self.writeGraph(attack.scytherDot,cin) - cin.flush() - cin.close() - cout.close() - - f.flush() - f.close() + # Start the process + safeCommand(cmd) # Print - print fpname2 - raw_input() + #print fpname2 + #raw_input() # if this is done, store and report attack.filetype = type diff --git a/gui/Scyther/Misc.py b/gui/Scyther/Misc.py index 4346491..1a1a212 100644 --- a/gui/Scyther/Misc.py +++ b/gui/Scyther/Misc.py @@ -5,7 +5,14 @@ #--------------------------------------------------------------------------- """ Import externals """ +import sys import os.path +try: + from subprocess import Popen + AvailablePopen = True +except: + import os + AvailablePopen = False #--------------------------------------------------------------------------- @@ -43,3 +50,21 @@ def mypath(file): basedir = os.path.dirname(__file__) return os.path.join(basedir,file) +def safeCommand(cmd): + """ Execute a command with some arguments. Safe cross-platform + version, I hope. """ + + global AvailablePopen + + if AvailablePopen: + if sys.platform.startswith("win"): + shell=False + else: + shell=True + p = Popen(cmd, shell=shell) + sts = p.wait() + else: + sts = os.system(cmd) + + return sts + diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 63a9475..a29c2d6 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -12,6 +12,7 @@ import sys import StringIO import tempfile + #--------------------------------------------------------------------------- """ Import scyther components """ @@ -226,7 +227,7 @@ class Scyther(object): ##print self.cmd # Start the process - os.system(self.cmd) + safeCommand(self.cmd) # reseek fhe = os.fdopen(fde)