From 4e2b7c405b935b258ac5642387f99d86f5073e66 Mon Sep 17 00:00:00 2001 From: ccremers Date: Thu, 14 Dec 2006 14:06:50 +0000 Subject: [PATCH] - Improved error handling. --- gui/Gui/Attackwindow.py | 12 ++++++-- gui/Gui/Scytherthread.py | 19 +++++++++---- gui/Scyther/Scyther.py | 59 ++++++++++++++++++++++++++++++++-------- gui/Scyther/__init__.py | 1 + 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/gui/Gui/Attackwindow.py b/gui/Gui/Attackwindow.py index 545c99f..5987f5e 100644 --- a/gui/Gui/Attackwindow.py +++ b/gui/Gui/Attackwindow.py @@ -31,7 +31,10 @@ class AttackDisplay(wx.ScrolledWindow): # [CC][X] The below statement might be iffy on older versions. # (Python 2.3? What settings?) # Cf. bug report Vimal Subra - self.SetBackgroundColour(wx.Colour(255,255,255)) + try: + self.SetBackgroundColour(wx.Colour(255,255,255)) + except: + pass self.Bind(wx.EVT_SIZE, self.OnSize) self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(1,1)) @@ -137,8 +140,13 @@ class AttackDisplay(wx.ScrolledWindow): class AttackWindow(wx.Frame): def __init__(self,cl): super(AttackWindow, self).__init__(None, size=(800,800)) + # [CC][X] Same here; no background set for safety. - #self.SetBackgroundColour('Default') + try: + self.SetBackgroundColour('Default') + except: + pass + self.claim = cl # TODO maybe fitting defaults should come from Preferences. diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index 1f143b1..ac69f3c 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -13,15 +13,15 @@ import StringIO #--------------------------------------------------------------------------- """ Import scyther components """ -import Scyther.XMLReader as XMLReader -import Scyther.Claim as Claim -import Scyther.Scyther as Scyther +import Scyther.Scyther +import Scyther.Error """ Import scyther-gui components """ import Tempfile import Preference import Attackwindow import Icon +import Error #--------------------------------------------------------------------------- if Preference.usePIL(): @@ -54,7 +54,8 @@ class ScytherThread(threading.Thread): """ Convert spdl to result (using Scyther) """ - scyther = Scyther.Scyther() + scyther = Scyther.Scyther.Scyther() + scyther.options = self.options scyther.setInput(self.spdl) @@ -496,10 +497,18 @@ class ScytherRun(object): self.verifywin.Center() self.verifywin.Show(True) + # Check sanity of Scyther thing here (as opposed to the thread) + # which makes error reporting somewhat easier + try: + Scyther.Scyther.Check() + except Scyther.Error.BinaryError, e: + # e.file is the supposed location of the binary + text = "Could not find Scyther binary at\n%s" % (e.file) + Error.ShowAndExit(text) + # start the thread self.verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) - t = ScytherThread(self.spdl, self.options, self.verificationDone) t.start() diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 41965c4..aac0133 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -16,10 +16,19 @@ import tempfile """ Import scyther components """ import XMLReader +import Error from Misc import * #--------------------------------------------------------------------------- +""" +Globals +""" + +FirstCheck = True + +#--------------------------------------------------------------------------- + """ The default path for the binaries is set in __init__.py in the (current) directory 'Scyther'. @@ -37,6 +46,39 @@ def getBinDir(): #--------------------------------------------------------------------------- +def Check(): + """ + Various dynamic checks that can be performed before starting the + backend. + """ + + global FirstCheck + + # First time + if FirstCheck: + """ + Perform any checks that only need to be done the first time. + """ + FirstCheck = False + + # Every time + + # Check Scyther backend program availability + program = getScytherBackend() + CheckSanity(program) + +#--------------------------------------------------------------------------- + +def CheckSanity(program): + """ + This is where the existence is checked of the Scyther backend. + """ + + if not os.path.isfile(program): + raise Error.BinaryError, program + +#--------------------------------------------------------------------------- + def getScytherBackend(): # Where is my executable? # @@ -47,12 +89,12 @@ def getScytherBackend(): """ linux """ scythername = "scyther-linux" - elif "darwin" in sys.platform: + # elif "darwin" in sys.platform: - """ OS X """ - # Preferably, we test for architecture (PPC/Intel) until we - # know how to build a universal binary - scythername = "scyther-osx" + # """ OS X """ + # # Preferably, we test for architecture (PPC/Intel) until we + # # know how to build a universal binary + # scythername = "scyther-osx" elif sys.platform.startswith('win'): @@ -62,14 +104,9 @@ def getScytherBackend(): else: """ Unsupported""" - print "ERROR: I'm sorry, the %s platform is unsupported at the moment" % (sys.platform) - sys.exit() + raise Error.UnknownPlatformError, sys.platform program = os.path.join(getBinDir(),scythername) - if not os.path.isfile(program): - print "I can't find the Scyther executable at %s" % (program) - return None - return program #--------------------------------------------------------------------------- diff --git a/gui/Scyther/__init__.py b/gui/Scyther/__init__.py index b16dd9f..c2b35da 100644 --- a/gui/Scyther/__init__.py +++ b/gui/Scyther/__init__.py @@ -9,3 +9,4 @@ import os.path bindir = os.path.join(__path__[0],"Bin") Scyther.setBinDir(bindir) +