- Added scripting support for claim list retrieval and single claim

evaluation.
This commit is contained in:
ccremers 2007-01-27 12:53:19 +00:00
parent 72c081c3cd
commit 0e21a2bd20
2 changed files with 67 additions and 1 deletions

View File

@ -59,5 +59,17 @@ class UnknownPlatformError(Error):
def __str__(self): def __str__(self):
return "The %s platform is currently unsupported." % self.platform return "The %s platform is currently unsupported." % self.platform
class StringListError(Error):
"""Raised when the a string should be a list of strings or a string
Attributes:
obj -- object that did not fit
"""
def __init__(self, obj):
self.obj = obj
def __str__(self):
return "Got %s instead of a (list of) string." % self.obj
# vim: set ts=4 sw=4 et list lcs=tab\:>-: # vim: set ts=4 sw=4 et list lcs=tab\:>-:

View File

@ -79,6 +79,27 @@ def CheckSanity(program):
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
def EnsureString(x,sep=" "):
"""
Takes a thing that is either a list or a string.
Turns it into a string. If it was a list, <sep> is inserted, and the
process iterats.
"""
if type(x) is str:
return x
elif type(x) is list:
newlist = []
for el in x:
newlist.append(EnsureString(el,sep))
return sep.join(newlist)
else:
raise Error.StringListError, x
#---------------------------------------------------------------------------
def getScytherBackend(): def getScytherBackend():
# Where is my executable? # Where is my executable?
# #
@ -225,14 +246,24 @@ class Scyther(object):
return (output,errors) return (output,errors)
def verify(self): def sanitize(self):
""" Sanitize some of the input """
self.options = EnsureString(self.options)
def verify(self,extraoptions=None):
""" Should return a list of results """ """ Should return a list of results """
# Cleanup first
self.sanitize()
# prepare arguments # prepare arguments
args = "" args = ""
if self.xml: if self.xml:
args += " --dot-output --xml-output --plain" args += " --dot-output --xml-output --plain"
args += " %s" % self.options args += " %s" % self.options
if extraoptions:
# extraoptions might need sanitizing
args += " %s" % EnsureString(extraoptions)
# execute # execute
(output,errors) = self.doScytherCommand(self.spdl, args) (output,errors) = self.doScytherCommand(self.spdl, args)
@ -278,6 +309,29 @@ class Scyther(object):
else: else:
return self.output return self.output
def verifyOne(self,claimid):
"""
Verify just a single claim with an ID retrieved from the
procedure below, 'scanClaims'
"""
return self.verify("--filter=%s" % claimid)
def scanClaims(self):
"""
Retrieve the list of claims in a format that can be passed to
--filter=X or 'verifyOne' later.
A result of 'None' means that some errors occurred.
"""
self.verify("--scan-claims")
if self.errorcount > 0:
return None
else:
self.validxml = False # Signal that we should not interpret the output as XML
l = []
for claim in self.claims:
l.append(claim.id)
return l
def getClaim(self,claimid): def getClaim(self,claimid):
if self.claims: if self.claims:
for cl in self.claims: for cl in self.claims: