- Improved error handling.

This commit is contained in:
ccremers 2006-12-14 14:06:50 +00:00
parent 2886e1a7e5
commit 4e2b7c405b
4 changed files with 73 additions and 18 deletions

View File

@ -31,7 +31,10 @@ class AttackDisplay(wx.ScrolledWindow):
# [CC][X] The below statement might be iffy on older versions. # [CC][X] The below statement might be iffy on older versions.
# (Python 2.3? What settings?) # (Python 2.3? What settings?)
# Cf. bug report Vimal Subra # Cf. bug report Vimal Subra
try:
self.SetBackgroundColour(wx.Colour(255,255,255)) self.SetBackgroundColour(wx.Colour(255,255,255))
except:
pass
self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_SIZE, self.OnSize)
self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(1,1)) self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(1,1))
@ -137,8 +140,13 @@ class AttackDisplay(wx.ScrolledWindow):
class AttackWindow(wx.Frame): class AttackWindow(wx.Frame):
def __init__(self,cl): def __init__(self,cl):
super(AttackWindow, self).__init__(None, size=(800,800)) super(AttackWindow, self).__init__(None, size=(800,800))
# [CC][X] Same here; no background set for safety. # [CC][X] Same here; no background set for safety.
#self.SetBackgroundColour('Default') try:
self.SetBackgroundColour('Default')
except:
pass
self.claim = cl self.claim = cl
# TODO maybe fitting defaults should come from Preferences. # TODO maybe fitting defaults should come from Preferences.

View File

@ -13,15 +13,15 @@ import StringIO
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
""" Import scyther components """ """ Import scyther components """
import Scyther.XMLReader as XMLReader import Scyther.Scyther
import Scyther.Claim as Claim import Scyther.Error
import Scyther.Scyther as Scyther
""" Import scyther-gui components """ """ Import scyther-gui components """
import Tempfile import Tempfile
import Preference import Preference
import Attackwindow import Attackwindow
import Icon import Icon
import Error
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
if Preference.usePIL(): if Preference.usePIL():
@ -54,7 +54,8 @@ class ScytherThread(threading.Thread):
""" Convert spdl to result (using Scyther) """ Convert spdl to result (using Scyther)
""" """
scyther = Scyther.Scyther() scyther = Scyther.Scyther.Scyther()
scyther.options = self.options scyther.options = self.options
scyther.setInput(self.spdl) scyther.setInput(self.spdl)
@ -496,10 +497,18 @@ class ScytherRun(object):
self.verifywin.Center() self.verifywin.Center()
self.verifywin.Show(True) 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 # start the thread
self.verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) self.verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
t = ScytherThread(self.spdl, self.options, self.verificationDone) t = ScytherThread(self.spdl, self.options, self.verificationDone)
t.start() t.start()

View File

@ -16,10 +16,19 @@ import tempfile
""" Import scyther components """ """ Import scyther components """
import XMLReader import XMLReader
import Error
from Misc import * from Misc import *
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
"""
Globals
"""
FirstCheck = True
#---------------------------------------------------------------------------
""" """
The default path for the binaries is set in __init__.py in the (current) The default path for the binaries is set in __init__.py in the (current)
directory 'Scyther'. 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(): def getScytherBackend():
# Where is my executable? # Where is my executable?
# #
@ -47,12 +89,12 @@ def getScytherBackend():
""" linux """ """ linux """
scythername = "scyther-linux" scythername = "scyther-linux"
elif "darwin" in sys.platform: # elif "darwin" in sys.platform:
""" OS X """ # """ OS X """
# Preferably, we test for architecture (PPC/Intel) until we # # Preferably, we test for architecture (PPC/Intel) until we
# know how to build a universal binary # # know how to build a universal binary
scythername = "scyther-osx" # scythername = "scyther-osx"
elif sys.platform.startswith('win'): elif sys.platform.startswith('win'):
@ -62,14 +104,9 @@ def getScytherBackend():
else: else:
""" Unsupported""" """ Unsupported"""
print "ERROR: I'm sorry, the %s platform is unsupported at the moment" % (sys.platform) raise Error.UnknownPlatformError, sys.platform
sys.exit()
program = os.path.join(getBinDir(),scythername) 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 return program
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------

View File

@ -9,3 +9,4 @@ import os.path
bindir = os.path.join(__path__[0],"Bin") bindir = os.path.join(__path__[0],"Bin")
Scyther.setBinDir(bindir) Scyther.setBinDir(bindir)