Blame SOURCES/0005-PATCH-clang-Partially-Revert-scan-view-Remove-Report.patch

6c15a0
From ea01f898fd74bae23d8be31f1a29b542e886e3a5 Mon Sep 17 00:00:00 2001
6c15a0
From: Tom Stellard <tstellar@redhat.com>
6c15a0
Date: Tue, 9 Feb 2021 13:35:43 -0800
6c15a0
Subject: [PATCH 5/6] [PATCH][clang] Partially Revert "scan-view: Remove
6c15a0
 Reporter.py and associated AppleScript files"
6c15a0
6c15a0
This reverts some of commit dbb01536f6f49fa428f170e34466072ef439b3e9.
6c15a0
6c15a0
The Reporter module was still being used by the ScanView.py module and deleting
6c15a0
it caused scan-view to fail.  This commit adds back Reporter.py but removes the
6c15a0
code the references the AppleScript files which were removed in
6c15a0
dbb01536f6f49fa428f170e34466072ef439b3e9.
6c15a0
6c15a0
Differential Revision: https://reviews.llvm.org/D96367
6c15a0
---
6c15a0
 clang/tools/scan-view/CMakeLists.txt    |   1 +
6c15a0
 clang/tools/scan-view/share/Reporter.py | 183 ++++++++++++++++++++++++++++++++
6c15a0
 2 files changed, 184 insertions(+)
6c15a0
 create mode 100644 clang/tools/scan-view/share/Reporter.py
6c15a0
6c15a0
diff --git a/clang/tools/scan-view/CMakeLists.txt b/clang/tools/scan-view/CMakeLists.txt
6c15a0
index dd3d334..eccc6b8 100644
6c15a0
--- a/clang/tools/scan-view/CMakeLists.txt
6c15a0
+++ b/clang/tools/scan-view/CMakeLists.txt
6c15a0
@@ -5,6 +5,7 @@ set(BinFiles
6c15a0
 
6c15a0
 set(ShareFiles
6c15a0
       ScanView.py
6c15a0
+      Reporter.py
6c15a0
       startfile.py
6c15a0
       bugcatcher.ico)
6c15a0
 
6c15a0
diff --git a/clang/tools/scan-view/share/Reporter.py b/clang/tools/scan-view/share/Reporter.py
6c15a0
new file mode 100644
6c15a0
index 0000000..31a14fb
6c15a0
--- /dev/null
6c15a0
+++ b/clang/tools/scan-view/share/Reporter.py
6c15a0
@@ -0,0 +1,183 @@
6c15a0
+#!/usr/bin/env python
6c15a0
+# -*- coding: utf-8 -*-
6c15a0
+
6c15a0
+"""Methods for reporting bugs."""
6c15a0
+
6c15a0
+import subprocess, sys, os
6c15a0
+
6c15a0
+__all__ = ['ReportFailure', 'BugReport', 'getReporters']
6c15a0
+
6c15a0
+#
6c15a0
+
6c15a0
+class ReportFailure(Exception):
6c15a0
+    """Generic exception for failures in bug reporting."""
6c15a0
+    def __init__(self, value):        
6c15a0
+        self.value = value
6c15a0
+
6c15a0
+# Collect information about a bug.
6c15a0
+
6c15a0
+class BugReport(object):
6c15a0
+    def __init__(self, title, description, files):
6c15a0
+        self.title = title
6c15a0
+        self.description = description
6c15a0
+        self.files = files
6c15a0
+
6c15a0
+# Reporter interfaces.
6c15a0
+
6c15a0
+import os
6c15a0
+
6c15a0
+import email, mimetypes, smtplib
6c15a0
+from email import encoders
6c15a0
+from email.message import Message
6c15a0
+from email.mime.base import MIMEBase
6c15a0
+from email.mime.multipart import MIMEMultipart
6c15a0
+from email.mime.text import MIMEText
6c15a0
+
6c15a0
+#===------------------------------------------------------------------------===#
6c15a0
+# ReporterParameter
6c15a0
+#===------------------------------------------------------------------------===#
6c15a0
+
6c15a0
+class ReporterParameter(object):
6c15a0
+  def __init__(self, n):
6c15a0
+    self.name = n
6c15a0
+  def getName(self):
6c15a0
+    return self.name
6c15a0
+  def getValue(self,r,bugtype,getConfigOption):
6c15a0
+     return getConfigOption(r.getName(),self.getName())
6c15a0
+  def saveConfigValue(self):
6c15a0
+    return True
6c15a0
+
6c15a0
+class TextParameter (ReporterParameter):
6c15a0
+  def getHTML(self,r,bugtype,getConfigOption):
6c15a0
+    return """\
6c15a0
+
6c15a0
+%s:
6c15a0
+<input type="text" name="%s_%s" value="%s">
6c15a0
+"""%(self.getName(),r.getName(),self.getName(),self.getValue(r,bugtype,getConfigOption))
6c15a0
+
6c15a0
+class SelectionParameter (ReporterParameter):
6c15a0
+  def __init__(self, n, values):
6c15a0
+    ReporterParameter.__init__(self,n)
6c15a0
+    self.values = values
6c15a0
+    
6c15a0
+  def getHTML(self,r,bugtype,getConfigOption):
6c15a0
+    default = self.getValue(r,bugtype,getConfigOption)
6c15a0
+    return """\
6c15a0
+
6c15a0
+%s:<select name="%s_%s">
6c15a0
+%s
6c15a0
+</select>"""%(self.getName(),r.getName(),self.getName(),'\n'.join(["""\
6c15a0
+<option value="%s"%s>%s</option>"""%(o[0],
6c15a0
+                                     o[0] == default and ' selected="selected"' or '',
6c15a0
+                                     o[1]) for o in self.values]))
6c15a0
+
6c15a0
+#===------------------------------------------------------------------------===#
6c15a0
+# Reporters
6c15a0
+#===------------------------------------------------------------------------===#
6c15a0
+
6c15a0
+class EmailReporter(object):
6c15a0
+    def getName(self):
6c15a0
+        return 'Email'
6c15a0
+
6c15a0
+    def getParameters(self):
6c15a0
+        return [TextParameter(x) for x in ['To', 'From', 'SMTP Server', 'SMTP Port']]
6c15a0
+
6c15a0
+    # Lifted from python email module examples.
6c15a0
+    def attachFile(self, outer, path):
6c15a0
+        # Guess the content type based on the file's extension.  Encoding
6c15a0
+        # will be ignored, although we should check for simple things like
6c15a0
+        # gzip'd or compressed files.
6c15a0
+        ctype, encoding = mimetypes.guess_type(path)
6c15a0
+        if ctype is None or encoding is not None:
6c15a0
+            # No guess could be made, or the file is encoded (compressed), so
6c15a0
+            # use a generic bag-of-bits type.
6c15a0
+            ctype = 'application/octet-stream'
6c15a0
+        maintype, subtype = ctype.split('/', 1)
6c15a0
+        if maintype == 'text':
6c15a0
+            fp = open(path)
6c15a0
+            # Note: we should handle calculating the charset
6c15a0
+            msg = MIMEText(fp.read(), _subtype=subtype)
6c15a0
+            fp.close()
6c15a0
+        else:
6c15a0
+            fp = open(path, 'rb')
6c15a0
+            msg = MIMEBase(maintype, subtype)
6c15a0
+            msg.set_payload(fp.read())
6c15a0
+            fp.close()
6c15a0
+            # Encode the payload using Base64
6c15a0
+            encoders.encode_base64(msg)
6c15a0
+        # Set the filename parameter
6c15a0
+        msg.add_header('Content-Disposition', 'attachment', filename=os.path.basename(path))
6c15a0
+        outer.attach(msg)
6c15a0
+
6c15a0
+    def fileReport(self, report, parameters):
6c15a0
+        mainMsg = """\
6c15a0
+BUG REPORT
6c15a0
+---
6c15a0
+Title: %s
6c15a0
+Description: %s
6c15a0
+"""%(report.title, report.description)
6c15a0
+
6c15a0
+        if not parameters.get('To'):
6c15a0
+            raise ReportFailure('No "To" address specified.')
6c15a0
+        if not parameters.get('From'):
6c15a0
+            raise ReportFailure('No "From" address specified.')
6c15a0
+
6c15a0
+        msg = MIMEMultipart()
6c15a0
+        msg['Subject'] = 'BUG REPORT: %s'%(report.title)
6c15a0
+        # FIXME: Get config parameters
6c15a0
+        msg['To'] = parameters.get('To')
6c15a0
+        msg['From'] = parameters.get('From')
6c15a0
+        msg.preamble = mainMsg
6c15a0
+
6c15a0
+        msg.attach(MIMEText(mainMsg, _subtype='text/plain'))
6c15a0
+        for file in report.files:
6c15a0
+            self.attachFile(msg, file)
6c15a0
+
6c15a0
+        try:
6c15a0
+            s = smtplib.SMTP(host=parameters.get('SMTP Server'),
6c15a0
+                             port=parameters.get('SMTP Port'))
6c15a0
+            s.sendmail(msg['From'], msg['To'], msg.as_string())
6c15a0
+            s.close()
6c15a0
+        except:
6c15a0
+            raise ReportFailure('Unable to send message via SMTP.')
6c15a0
+
6c15a0
+        return "Message sent!"
6c15a0
+
6c15a0
+class BugzillaReporter(object):
6c15a0
+    def getName(self):
6c15a0
+        return 'Bugzilla'
6c15a0
+    
6c15a0
+    def getParameters(self):
6c15a0
+        return [TextParameter(x) for x in ['URL','Product']]
6c15a0
+
6c15a0
+    def fileReport(self, report, parameters):
6c15a0
+        raise NotImplementedError
6c15a0
+ 
6c15a0
+
6c15a0
+class RadarClassificationParameter(SelectionParameter):
6c15a0
+  def __init__(self):
6c15a0
+    SelectionParameter.__init__(self,"Classification",
6c15a0
+            [['1', 'Security'], ['2', 'Crash/Hang/Data Loss'],
6c15a0
+             ['3', 'Performance'], ['4', 'UI/Usability'], 
6c15a0
+             ['6', 'Serious Bug'], ['7', 'Other']])
6c15a0
+
6c15a0
+  def saveConfigValue(self):
6c15a0
+    return False
6c15a0
+    
6c15a0
+  def getValue(self,r,bugtype,getConfigOption):
6c15a0
+    if bugtype.find("leak") != -1:
6c15a0
+      return '3'
6c15a0
+    elif bugtype.find("dereference") != -1:
6c15a0
+      return '2'
6c15a0
+    elif bugtype.find("missing ivar release") != -1:
6c15a0
+      return '3'
6c15a0
+    else:
6c15a0
+      return '7'
6c15a0
+
6c15a0
+###
6c15a0
+
6c15a0
+def getReporters():
6c15a0
+    reporters = []
6c15a0
+    reporters.append(EmailReporter())
6c15a0
+    return reporters
6c15a0
+
6c15a0
-- 
6c15a0
1.8.3.1
6c15a0