зеркало из https://github.com/microsoft/clang-1.git
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:
Родитель
037cda5282
Коммит
19c8820134
|
@ -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 """\
|
||||
<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:
|
||||
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', '')
|
||||
|
|
|
@ -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('<option value="%d"%s>%s</option>'%(i,selectedStr,r.getName()))
|
||||
options = '\n'.join(["""\
|
||||
<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()])
|
||||
options = '\n'.join([ o.getHTML(r,title,getConfigOption) for o in r.getParameters()])
|
||||
display = ('none','')[selected]
|
||||
reporterOptions.append("""\
|
||||
<tr id="%sReporterOptions" style="display:%s">
|
||||
|
|
Загрузка…
Ссылка в новой задаче