From 19c8820134605ee6cc72a18624e56041952e9ae4 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 30 Sep 2008 16:08:13 +0000 Subject: [PATCH] Use objects to represent form parameters. This allows us to abstract away some of the details of HTML rendering of form parameters, and also us with the ability to delegate other actions (such as in the filling in of default values) to specific parameter objects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56851 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/scan-view/Reporter.py | 41 +++++++++++++++++++++++++++++++------ tools/scan-view/ScanView.py | 21 ++++++++----------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/tools/scan-view/Reporter.py b/tools/scan-view/Reporter.py index 07102cff47..ba7b733be2 100644 --- a/tools/scan-view/Reporter.py +++ b/tools/scan-view/Reporter.py @@ -30,12 +30,41 @@ from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText +#===------------------------------------------------------------------------===# +# ReporterParameter +#===------------------------------------------------------------------------===# + +class ReporterParameter: + def __init__(self, n): + self.name = n + + def getName(self): + return self.name + + def saveConfigValue(self): + return True + +class TextParameter (ReporterParameter): + def getValue(self,r,bugtype,getConfigOption): + return getConfigOption(r.getName(),self.getName()) + + def getHTML(self,r,bugtype,getConfigOption): + return """\ + + %s: + +"""%(self.getName(),r.getName(),self.getName(),self.getValue(r,bugtype,getConfigOption)) + +#===------------------------------------------------------------------------===# +# Reporters +#===------------------------------------------------------------------------===# + class EmailReporter: def getName(self): return 'Email' - def getParameterNames(self): - return ['To', 'From', 'SMTP Server', 'SMTP Port'] + def getParameters(self): + return map(lambda x:TextParameter(x),['To', 'From', 'SMTP Server', 'SMTP Port']) # Lifted from python email module examples. def attachFile(self, outer, path): @@ -102,8 +131,8 @@ class BugzillaReporter: def getName(self): return 'Bugzilla' - def getParameterNames(self): - return ['URL', 'Product'] + def getParameters(self): + return map(lambda x:TextParameter(x),['URL','Product']) def fileReport(self, report, parameters): raise NotImplementedError @@ -126,8 +155,8 @@ class RadarReporter: def getName(self): return 'Radar' - def getParameterNames(self): - return ['Component', 'Component Version'] + def getParameters(self): + return map(lambda x:TextParameter(x),['Component', 'Component Version']) def fileReport(self, report, parameters): component = parameters.get('Component', '') diff --git a/tools/scan-view/ScanView.py b/tools/scan-view/ScanView.py index 76a790dabc..8ee28f7862 100644 --- a/tools/scan-view/ScanView.py +++ b/tools/scan-view/ScanView.py @@ -129,8 +129,8 @@ class ScanViewServer(BaseHTTPServer.HTTPServer): self.config.add_section('ScanView') for r in self.reporters: self.config.add_section(r.getName()) - for p in r.getParameterNames(): - self.config.set(r.getName(), p, '') + for p in r.getParameters(): + self.config.set(r.getName(), p.getName(), '') # Ignore parse errors try: @@ -304,19 +304,20 @@ class ScanViewRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): # Get the reporter and parameters. reporter = self.server.reporters[reporterIndex] parameters = {} - for o in reporter.getParameterNames(): - name = '%s_%s'%(reporter.getName(),o) + for o in reporter.getParameters(): + name = '%s_%s'%(reporter.getName(),o.getName()) if name not in self.fields: return (False, 'Missing field "%s" for %s report method.'%(name, reporter.getName())) - parameters[o] = self.get_scalar_field(name) + parameters[o.getName()] = self.get_scalar_field(name) # Update config defaults. if report != 'None': self.server.config.set('ScanView', 'reporter', reporterIndex) - for o in reporter.getParameterNames(): - self.server.config.set(reporter.getName(), o, parameters[o]) + for o in reporter.getParameters(): + name = o.getName() + self.server.config.set(reporter.getName(), name, parameters[name]) # Create the report. bug = Reporter.BugReport(title, description, files) @@ -529,11 +530,7 @@ Line: %s else: selectedStr = '' reporterSelections.append(''%(i,selectedStr,r.getName())) - options = '\n'.join(["""\ - - %s: - -"""%(o,r.getName(),o,getConfigOption(r.getName(),o)) for o in r.getParameterNames()]) + options = '\n'.join([ o.getHTML(r,title,getConfigOption) for o in r.getParameters()]) display = ('none','')[selected] reporterOptions.append("""\