- 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.
# (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.

View File

@ -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()

View File

@ -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
#---------------------------------------------------------------------------

View File

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