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
This commit is contained in:
Ted Kremenek 2008-09-30 16:08:13 +00:00
Родитель 037cda5282
Коммит 19c8820134
2 изменённых файлов: 44 добавлений и 18 удалений

Просмотреть файл

@ -30,12 +30,41 @@ from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText 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 """\
<tr>
<td class="form_clabel">%s:</td>
<td class="form_value"><input type="text" name="%s_%s" value="%s"></td>
</tr>"""%(self.getName(),r.getName(),self.getName(),self.getValue(r,bugtype,getConfigOption))
#===------------------------------------------------------------------------===#
# Reporters
#===------------------------------------------------------------------------===#
class EmailReporter: class EmailReporter:
def getName(self): def getName(self):
return 'Email' return 'Email'
def getParameterNames(self): def getParameters(self):
return ['To', 'From', 'SMTP Server', 'SMTP Port'] return map(lambda x:TextParameter(x),['To', 'From', 'SMTP Server', 'SMTP Port'])
# Lifted from python email module examples. # Lifted from python email module examples.
def attachFile(self, outer, path): def attachFile(self, outer, path):
@ -102,8 +131,8 @@ class BugzillaReporter:
def getName(self): def getName(self):
return 'Bugzilla' return 'Bugzilla'
def getParameterNames(self): def getParameters(self):
return ['URL', 'Product'] return map(lambda x:TextParameter(x),['URL','Product'])
def fileReport(self, report, parameters): def fileReport(self, report, parameters):
raise NotImplementedError raise NotImplementedError
@ -126,8 +155,8 @@ class RadarReporter:
def getName(self): def getName(self):
return 'Radar' return 'Radar'
def getParameterNames(self): def getParameters(self):
return ['Component', 'Component Version'] return map(lambda x:TextParameter(x),['Component', 'Component Version'])
def fileReport(self, report, parameters): def fileReport(self, report, parameters):
component = parameters.get('Component', '') component = parameters.get('Component', '')

Просмотреть файл

@ -129,8 +129,8 @@ class ScanViewServer(BaseHTTPServer.HTTPServer):
self.config.add_section('ScanView') self.config.add_section('ScanView')
for r in self.reporters: for r in self.reporters:
self.config.add_section(r.getName()) self.config.add_section(r.getName())
for p in r.getParameterNames(): for p in r.getParameters():
self.config.set(r.getName(), p, '') self.config.set(r.getName(), p.getName(), '')
# Ignore parse errors # Ignore parse errors
try: try:
@ -304,19 +304,20 @@ class ScanViewRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
# Get the reporter and parameters. # Get the reporter and parameters.
reporter = self.server.reporters[reporterIndex] reporter = self.server.reporters[reporterIndex]
parameters = {} parameters = {}
for o in reporter.getParameterNames(): for o in reporter.getParameters():
name = '%s_%s'%(reporter.getName(),o) name = '%s_%s'%(reporter.getName(),o.getName())
if name not in self.fields: if name not in self.fields:
return (False, return (False,
'Missing field "%s" for %s report method.'%(name, 'Missing field "%s" for %s report method.'%(name,
reporter.getName())) reporter.getName()))
parameters[o] = self.get_scalar_field(name) parameters[o.getName()] = self.get_scalar_field(name)
# Update config defaults. # Update config defaults.
if report != 'None': if report != 'None':
self.server.config.set('ScanView', 'reporter', reporterIndex) self.server.config.set('ScanView', 'reporter', reporterIndex)
for o in reporter.getParameterNames(): for o in reporter.getParameters():
self.server.config.set(reporter.getName(), o, parameters[o]) name = o.getName()
self.server.config.set(reporter.getName(), name, parameters[name])
# Create the report. # Create the report.
bug = Reporter.BugReport(title, description, files) bug = Reporter.BugReport(title, description, files)
@ -529,11 +530,7 @@ Line: %s
else: else:
selectedStr = '' selectedStr = ''
reporterSelections.append('<option value="%d"%s>%s</option>'%(i,selectedStr,r.getName())) reporterSelections.append('<option value="%d"%s>%s</option>'%(i,selectedStr,r.getName()))
options = '\n'.join(["""\ options = '\n'.join([ o.getHTML(r,title,getConfigOption) for o in r.getParameters()])
<tr>
<td class="form_clabel">%s:</td>
<td class="form_value"><input type="text" name="%s_%s" value="%s"></td>
</tr>"""%(o,r.getName(),o,getConfigOption(r.getName(),o)) for o in r.getParameterNames()])
display = ('none','')[selected] display = ('none','')[selected]
reporterOptions.append("""\ reporterOptions.append("""\
<tr id="%sReporterOptions" style="display:%s"> <tr id="%sReporterOptions" style="display:%s">