[cfe-commits] r56851 - in /cfe/trunk/tools/scan-view: Reporter.py ScanView.py

Ted Kremenek kremenek at apple.com
Tue Sep 30 09:08:14 PDT 2008


Author: kremenek
Date: Tue Sep 30 11:08:13 2008
New Revision: 56851

URL: http://llvm.org/viewvc/llvm-project?rev=56851&view=rev
Log:
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.

Modified:
    cfe/trunk/tools/scan-view/Reporter.py
    cfe/trunk/tools/scan-view/ScanView.py

Modified: cfe/trunk/tools/scan-view/Reporter.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-view/Reporter.py?rev=56851&r1=56850&r2=56851&view=diff

==============================================================================
--- cfe/trunk/tools/scan-view/Reporter.py (original)
+++ cfe/trunk/tools/scan-view/Reporter.py Tue Sep 30 11:08:13 2008
@@ -30,12 +30,41 @@
 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 @@
     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 @@
     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', '')

Modified: cfe/trunk/tools/scan-view/ScanView.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-view/ScanView.py?rev=56851&r1=56850&r2=56851&view=diff

==============================================================================
--- cfe/trunk/tools/scan-view/ScanView.py (original)
+++ cfe/trunk/tools/scan-view/ScanView.py Tue Sep 30 11:08:13 2008
@@ -129,8 +129,8 @@
         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 @@
         # 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 @@
             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">





More information about the cfe-commits mailing list