[Libreoffice-commits] dev-tools.git: esc-reporting/common.py esc-reporting/esc-analyze.py esc-reporting/esc-automate.py esc-reporting/esc-collect.py esc-reporting/esc-report.py

Xisco Fauli xiscofauli at libreoffice.org
Mon Mar 5 19:19:16 UTC 2018


 esc-reporting/common.py       |   43 ++++++++++++++++++++++++++++++++++++++++++
 esc-reporting/esc-analyze.py  |   40 +++++++++++++++------------------------
 esc-reporting/esc-automate.py |   33 +++++++-------------------------
 esc-reporting/esc-collect.py  |   19 ++++++------------
 esc-reporting/esc-report.py   |   24 ++++++++---------------
 5 files changed, 83 insertions(+), 76 deletions(-)

New commits:
commit ec7e13334a1a2e363cda6dc822e89d1609e0d45d
Author: Xisco Fauli <xiscofauli at libreoffice.org>
Date:   Mon Mar 5 16:23:32 2018 +0100

    ESC: replace os.system with subproces

diff --git a/esc-reporting/common.py b/esc-reporting/common.py
new file mode 100644
index 0000000..b7c8420
--- /dev/null
+++ b/esc-reporting/common.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from subprocess import Popen, PIPE
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+from email.mime.application import MIMEApplication
+
+def sendMail(cfg, mail, subject, content, attachFile=None):
+    msg = MIMEMultipart()
+    msg["From"] = "mentoring at documentfoundation.org"
+    msg["To"] = mail
+
+    if cfg['mail']['bcc']:
+        msg["Bcc"] = cfg['mail']['bcc']
+
+    msg["Subject"] = subject
+
+    msg.attach(MIMEText(content))
+
+    if attachFile:
+        fp = open(attachFile, 'rb')
+        attach = MIMEApplication(fp.read(), 'pdf')
+        fp.close()
+        attach.add_header('Content-Disposition', "attachment'; filename=award.pdf")
+        msg.attach(attach)
+
+    p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
+    output, error = p.communicate(msg.as_string().encode('ascii'))
+    return error
+
+def util_errorMail(cfg, text):
+    print(text)
+    subject = "ERROR: esc-automate FAILED"
+    message = text + '\nPlease have a look at vm174'
+    sendMail(cfg, 'mentoring at documentfoundation.org', subject, message)
diff --git a/esc-reporting/esc-analyze.py b/esc-reporting/esc-analyze.py
index 9fe2a84..1305a73 100755
--- a/esc-reporting/esc-analyze.py
+++ b/esc-reporting/esc-analyze.py
@@ -44,7 +44,7 @@
 #
 
 
-
+import common
 import sys
 import csv
 import io
@@ -57,20 +57,6 @@ import re
 
 
 
-def util_errorMail(text):
-    print(text)
-    sendMail = 'mail -r mentoring at documentfoundation.org ' + cfg['mail']['bcc'] + ' -s "ERROR: esc-analyze FAILED" mentoring at documentfoundation.org <<EOF\n' + text + '\nPlease have a look at vm174\nEOF\n'
-    os.system(sendMail)
-
-
-
-
-def util_errorMail(text):
-    print(text)
-    sendMail = 'mail -r mentoring at documentfoundation.org -s "' + text + '" mentoring at documentfoundation.org <<EOF\nPlease have a look at vm174\nEOF\n'
-    os.system(sendMail)
-
-
 def util_load_file(fileName, isJson=True):
     try:
       fp = open(fileName, encoding='utf-8')
@@ -249,7 +235,13 @@ def util_create_statList():
 def util_check_mail(name, xmail):
     global statList
 
-    mail = xmail.lower()
+    match = re.search(r'[\w\.-]+@[\w\.-]+', xmail.lower())
+    if match:
+      mail = match.group(0)
+    else:
+      # Return a fake email in order to not break the script
+      mail = 'fake-email at fake-email-script-esc.com'
+      common.sendMail(cfg, 'xiscofauli at libreoffice.org', 'Error parsing email', 'ERROR parsing' + str(xmail))
     if mail in statList['aliases']:
       mail = statList['aliases'][mail]
     if not mail in statList['people']:
@@ -942,42 +934,42 @@ def runAnalyze():
     try:
       runLoadCSV()
     except Exception as e:
-      util_errorMail('ERROR: runLoadCSV failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: runLoadCSV failed with ' + str(e))
       pass
     try:
       analyze_mentoring()
     except Exception as e:
-      util_errorMail('ERROR: analyze_mentoring failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_mentoring failed with ' + str(e))
       pass
     try:
       analyze_ui()
     except Exception as e:
-      util_errorMail('ERROR: analyze_ui failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_ui failed with ' + str(e))
       pass
     try:
       analyze_qa()
     except Exception as e:
-      util_errorMail('ERROR: analyze_qa failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_qa failed with ' + str(e))
       pass
     try:
       analyze_esc()
     except Exception as e:
-      util_errorMail('ERROR: analyze_esc failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_esc failed with ' + str(e))
       pass
     try:
       analyze_myfunc()
     except Exception as e:
-      util_errorMail('ERROR: analyze_myfunc failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_myfunc failed with ' + str(e))
       pass
     try:
       analyze_reports()
     except Exception as e:
-      util_errorMail('ERROR: analyze_reports failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_reports failed with ' + str(e))
       pass
     try:
       analyze_final()
     except Exception as e:
-      util_errorMail('ERROR: analyze_final failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: analyze_final failed with ' + str(e))
       pass
 
 
diff --git a/esc-reporting/esc-automate.py b/esc-reporting/esc-automate.py
index 15c39e5..d008e69 100755
--- a/esc-reporting/esc-automate.py
+++ b/esc-reporting/esc-automate.py
@@ -20,7 +20,7 @@
 #
 
 
-
+import common
 import sys
 import os
 import datetime
@@ -29,16 +29,6 @@ import requests
 from requests.auth import HTTPDigestAuth
 
 
-
-
-
-def util_errorMail(text):
-    print(text)
-    sendMail = 'mail -r mentoring at documentfoundation.org ' + cfg['mail']['bcc'] + ' -s "ERROR: esc-automate FAILED" mentoring at documentfoundation.org <<EOF\n' + text + '\nPlease have a look at vm174\nEOF\n'
-    os.system(sendMail)
-
-
-
 def util_load_data_file(fileName):
     try:
       fp = open(fileName, encoding='utf-8')
@@ -94,18 +84,10 @@ def doGerrit(id, command):
       raise Exception('error: ' + cmd + ' failed')
 
 
-
-def doMail(mail, subject, content, attach=None):
-    if attach:
-      attach = '-a ' + attach + ' '
-    else:
-      attach = ''
-    sendMail = 'mail -r mentoring at documentfoundation.org ' + cfg['mail']['bcc'] + ' -s "' + subject + '" ' + attach + mail + ' <<EOF\n' + content + '\nEOF\n'
-    r = os.system(sendMail)
-    if r != 0:
-      raise Exception('mail failed')
-
-
+def doMail(mail, subject, content, attachFile=None):
+    error = common.sendMail(cfg, mail, subject, content, attachFile)
+    if error:
+        raise Exception('mail failed')
 
 def handle_gerrit_abandon(id, patchset):
     pid = str(id) + ',' + str(patchset)
@@ -186,7 +168,8 @@ def handle_mail_pdf(email, name):
       raise Exception('pdf generation failed ')
 
     text = cfg['automate']['1st award']['content'].format(name)
-    doMail(email, cfg['automate']['1st award']['subject'], text, attach=filePdf)
+
+    doMail(email, cfg['automate']['1st award']['subject'], text, attachFile=filePdf)
 
 
 
@@ -205,7 +188,7 @@ def executeLoop(func, xType, xName):
       for id in autoList[xType][xName]:
         func(id, autoList[xType][xName][id])
     except Exception as e:
-      util_errorMail('ERROR: ' + str(func) + ' failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: ' + str(func) + ' failed with ' + str(e))
       return
 
     del autoList[xType][xName]
diff --git a/esc-reporting/esc-collect.py b/esc-reporting/esc-collect.py
index 425175a..8b812d3 100755
--- a/esc-reporting/esc-collect.py
+++ b/esc-reporting/esc-collect.py
@@ -28,6 +28,7 @@
 # For analysis and reporting see the 2 other programs available.
 #
 
+import common
 import sys
 import csv
 import io
@@ -41,12 +42,6 @@ from requests.auth import HTTPDigestAuth
 
 
 
-def util_errorMail(text):
-    print(text)
-    sendMail = 'mail -r mentoring at documentfoundation.org ' + cfg['mail']['bcc'] + ' -s "ERROR: esc-collect FAILED" mentoring at documentfoundation.org <<EOF\n' + text + '\nPlease have a look at vm174\nEOF\n'
-    os.system(sendMail)
-
-
 def util_load_file(fileName):
     try:
       fp = open(fileName, encoding='utf-8')
@@ -726,32 +721,32 @@ def runBuild(cfg):
     try:
       gerritData = get_gerrit(cfg)
     except Exception as e:
-      util_errorMail('ERROR: get_gerrit failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: get_gerrit failed with ' + str(e))
       pass
     try:
       crashData = get_crash(cfg)
     except Exception as e:
-      util_errorMail('ERROR: get_crash failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: get_crash failed with ' + str(e))
       pass
     try:
       openhubData = get_openhub(cfg)
     except Exception as e:
-      util_errorMail('ERROR: get_openhub failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: get_openhub failed with ' + str(e))
       pass
     try:
       bugzillaData = get_bugzilla(cfg)
     except Exception as e:
-      util_errorMail('ERROR: get_bugzilla failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: get_bugzilla failed with ' + str(e))
       pass
     try:
       ESCData = get_esc_bugzilla(cfg)
     except Exception as e:
-      util_errorMail('ERROR: get_esc_bugzilla failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: get_esc_bugzilla failed with ' + str(e))
       pass
     try:
       gitData = get_git(cfg)
     except Exception as e:
-      util_errorMail('ERROR: get_git failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: get_git failed with ' + str(e))
       pass
 
 
diff --git a/esc-reporting/esc-report.py b/esc-reporting/esc-report.py
index 4cbeeca..ebe0b5f 100755
--- a/esc-reporting/esc-report.py
+++ b/esc-reporting/esc-report.py
@@ -30,6 +30,7 @@
 
 
 
+import common
 import sys
 import csv
 import io
@@ -42,13 +43,6 @@ import xmltodict
 
 
 
-def util_errorMail(text):
-    print(text)
-    sendMail = 'mail -r mentoring at documentfoundation.org ' + cfg['mail']['bcc'] + ' -s "ERROR: esc-report FAILED" mentoring at documentfoundation.org <<EOF\n' + text + '\nPlease have a look at vm174\nEOF\n'
-    os.system(sendMail)
-
-
-
 def util_load_data_file(fileName):
     try:
       fp = open(fileName, encoding='utf-8')
@@ -783,49 +777,49 @@ def runReport():
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_bug_metrics failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_bug_metrics failed with ' + str(e))
       pass
     try:
       x = report_day_mentoring()
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_day_mentoring failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_day_mentoring failed with ' + str(e))
       pass
     try:
       x = report_mentoring()
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_mentoring failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_mentoring failed with ' + str(e))
       pass
     try:
       x = report_ui()
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_ui failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_ui failed with ' + str(e))
       pass
     try:
       x = report_qa()
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_qa failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_qa failed with ' + str(e))
       pass
     try:
       x = report_myfunc()
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_myfunc failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_myfunc failed with ' + str(e))
       pass
     try:
       x = report_esc_prototype()
       if not x is None:
         xMail.append(x)
     except Exception as e:
-      util_errorMail('ERROR: report_esc_prototype failed with ' + str(e))
+      common.util_errorMail(cfg, 'ERROR: report_esc_prototype failed with ' + str(e))
       pass
 
     for i in xMail:
@@ -835,7 +829,7 @@ def runReport():
         attach = ''
       r = os.system("mail -r mentoring at documentfoundation.org " + cfg['mail']['bcc'] + " -s '" + i['title'] + "' " + attach + i['mail'] + " <  " + i['file'])
       if r != 0:
-        util_errorMail('ERROR: mailing failed with ' + str(e))
+        common.util_errorMail(cfg, 'ERROR: mailing failed with ' + str(e))
 
 
 if __name__ == '__main__':


More information about the Libreoffice-commits mailing list