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

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