Integrated XP fixes

This commit is contained in:
Cas Cremers 2007-05-19 16:27:28 +02:00
commit f837d1b000
3 changed files with 50 additions and 21 deletions

View File

@ -15,6 +15,7 @@ import StringIO
""" Import scyther components """ """ Import scyther components """
import Scyther.Scyther import Scyther.Scyther
import Scyther.Error import Scyther.Error
from Scyther.Misc import *
""" Import scyther-gui components """ """ Import scyther-gui components """
import Tempfile import Tempfile
@ -153,12 +154,14 @@ class AttackThread(threading.Thread):
return return
graphLine("%s [%s]" % (edge,atxt)) graphLine("%s [%s]" % (edge,atxt))
# Precompute font name if sys.platform.startswith("darwin"):
# Set a font with sans self.fontname = "Helvetica"
# We only retrieve the name, so the size '9' here is elif sys.platform.startswith("win"):
# irrelevant. self.fontname = "Courier"
font = wx.Font(9,wx.SWISS,wx.NORMAL,wx.NORMAL) else:
self.fontname = font.GetFaceName() #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 # write all graph lines but add layout modifiers
for l in txt.splitlines(): for l in txt.splitlines():
@ -174,8 +177,9 @@ class AttackThread(threading.Thread):
#graphLine("mindist=0.1") #graphLine("mindist=0.1")
# Set fontname # Set fontname
fontstring = "fontname=%s" % (self.fontname) if self.fontname:
setAttr(fontstring,EDGE) fontstring = "fontname=%s" % (self.fontname)
setAttr(fontstring)
# Stupid Mac <> Graphviz bug fix # Stupid Mac <> Graphviz bug fix
if (sys.platform.startswith("mac")) or (sys.platform.startswith("darwin")): if (sys.platform.startswith("mac")) or (sys.platform.startswith("darwin")):
@ -194,6 +198,7 @@ class AttackThread(threading.Thread):
def makeImage(self,attack): def makeImage(self,attack):
""" create image for this particular attack """ """ create image for this particular attack """
if Preference.usePIL(): if Preference.usePIL():
# If we have the PIL library, we can do postscript! great # If we have the PIL library, we can do postscript! great
# stuff. # stuff.
@ -207,23 +212,21 @@ class AttackThread(threading.Thread):
# command to write to temporary file # command to write to temporary file
(fd2,fpname2) = Tempfile.tempcleaned(ext) (fd2,fpname2) = Tempfile.tempcleaned(ext)
f = os.fdopen(fd2,'w') 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 # execute command
cin,cout = os.popen2(cmd,'b') # Start the process
safeCommand(cmd)
self.writeGraph(attack.scytherDot,cin)
cin.flush()
cin.close()
cout.close()
f.flush()
f.close()
# Print # Print
print fpname2 #print fpname2
raw_input() #raw_input()
# if this is done, store and report # if this is done, store and report
attack.filetype = type attack.filetype = type

View File

@ -5,7 +5,14 @@
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
""" Import externals """ """ Import externals """
import sys
import os.path 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__) basedir = os.path.dirname(__file__)
return os.path.join(basedir,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

View File

@ -12,6 +12,7 @@ import sys
import StringIO import StringIO
import tempfile import tempfile
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
""" Import scyther components """ """ Import scyther components """
@ -226,7 +227,7 @@ class Scyther(object):
##print self.cmd ##print self.cmd
# Start the process # Start the process
os.system(self.cmd) safeCommand(self.cmd)
# reseek # reseek
fhe = os.fdopen(fde) fhe = os.fdopen(fde)