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

Guilhem Moulin (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 19 16:09:57 UTC 2020


 esc-reporting/esc-automate.py |   21 +++++++++------------
 esc-reporting/esc-collect.py  |   18 ++++++++----------
 esc-reporting/esc-report.py   |    9 +++++----
 3 files changed, 22 insertions(+), 26 deletions(-)

New commits:
commit 49b88333c8b541a391d11c1b0341e25445e2ef71
Author:     Guilhem Moulin <guilhem at libreoffice.org>
AuthorDate: Mon Feb 17 06:15:03 2020 +0100
Commit:     Xisco Faulí <xiscofauli at libreoffice.org>
CommitDate: Wed Feb 19 17:09:36 2020 +0100

    esc-reporting: replace os.system with subprocess.*
    
    Change-Id: Ief15aae7bb7a66ba59c57f3bd1b6d489a590b0ab
    Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/88908
    Tested-by: Xisco Faulí <xiscofauli at libreoffice.org>
    Reviewed-by: Xisco Faulí <xiscofauli at libreoffice.org>

diff --git a/esc-reporting/esc-automate.py b/esc-reporting/esc-automate.py
index 32f603b..77cf5ee 100755
--- a/esc-reporting/esc-automate.py
+++ b/esc-reporting/esc-automate.py
@@ -27,6 +27,8 @@ import datetime
 import json
 import requests
 from requests.auth import HTTPDigestAuth
+from shlex import quote
+from subprocess import check_call
 import unidecode
 
 def util_load_data_file(fileName):
@@ -78,10 +80,8 @@ def doBugzilla(id, command, isComment=False):
 
 
 def doGerrit(id, command):
-    cmd = 'ssh gerrit.libreoffice.org gerrit ' + command + ' "' + id + '"'
-    r = os.system(cmd)
-    if r != 0:
-      raise Exception('error: ' + cmd + ' failed')
+    gerrit = ['ssh', '-p', '29418', 'gerrit.libreoffice.org', 'gerrit']
+    check_call(gerrit + command + [quote(id)])
 
 
 def doMail(cfg, mail, subject, content, attachFile=None):
@@ -91,13 +91,13 @@ def doMail(cfg, mail, subject, content, attachFile=None):
 
 def handle_gerrit_abandon(id, patchset):
     pid = str(id) + ',' + str(patchset)
-    cmd = 'review --abandon --message \'"' + cfg['automate']['gerrit']['abandon'] + '"\''
+    cmd = ['review', '--abandon', '--message', quote(cfg['automate']['gerrit']['abandon'])]
     doGerrit(pid, cmd)
 
 
 
 def handle_gerrit_review(id, row):
-    cmd = 'set-reviewers -a  \'"' + row['name'] + '"\''
+    cmd = ['set-reviewers', '-a', quote(row['name'])]
     doGerrit(id, cmd)
     handle_gerrit_comment(row['id'], row['patchset'], useText='added reviewer')
 
@@ -109,7 +109,7 @@ def handle_gerrit_comment(id, patchset, useText = None):
       txt = 'A polite ping, ' + cfg['automate']['gerrit']['comment']
     else:
       txt = useText
-    cmd = 'review --message \'"' + txt + '"\''
+    cmd = ['review', '--message', quote(txt)]
     doGerrit(pid, cmd)
 
 
@@ -133,13 +133,10 @@ def handle_mail_pdf(email, name):
     fp.close()
 
     filePdf = '/tmp/award.pdf'
-    pdfGen = 'pdftk ' + cfg['homedir'] + 'AcknowledgmentForm.pdf fill_form ' + fileFdf + ' output ' + filePdf
-    attachFile= {'path': filePdf, 'name': 'award.pdf', 'extension': 'pdf'}
-    r = os.system(pdfGen)
-    if r != 0:
-      raise Exception('pdf generation failed ')
+    check_call(['pdftk', cfg['homedir'] + 'AcknowledgmentForm.pdf', 'fill_form', fileFdf, 'output', filePdf])
 
     text = cfg['automate']['1st award']['content'].format(name)
+    attachFile= {'path': filePdf, 'name': 'award.pdf', 'extension': 'pdf'}
 
     doMail(cfg, email, cfg['automate']['1st award']['subject'], text, attachFile)
 
diff --git a/esc-reporting/esc-collect.py b/esc-reporting/esc-collect.py
index b0adc1f..034e0ca 100755
--- a/esc-reporting/esc-collect.py
+++ b/esc-reporting/esc-collect.py
@@ -38,7 +38,7 @@ import datetime
 import json
 import xmltodict
 import requests
-from subprocess import check_call, Popen, PIPE
+from subprocess import check_call, Popen, PIPE, CalledProcessError
 from requests.auth import HTTPDigestAuth
 
 
@@ -591,19 +591,17 @@ def get_gerrit(cfg):
     print("Updating gerrit dump from " + rawList['newest-entry'])
 
     rawList['committers'] = []
-    r = os.system('ssh gerrit.libreoffice.org "gerrit ls-members Committers" > /tmp/committerList')
-    if r != 0:
-      raise Exception('ssh gerrit... failed')
-
-    fp = open('/tmp/committerList', encoding='utf-8')
-    tmp = fp.read().split('\n')[1:-1]
-    fp.close()
-    for line in tmp:
-      row = line.split('\t')
+    # Could use the REST API instead and receive pre-formatted JSON, but that requires HTTP auth
+    cmd = ["ssh", "-p", "29418", "gerrit.libreoffice.org", "gerrit", "ls-members", "Committers"]
+    p = Popen(cmd, stdout=PIPE)
+    for line in io.TextIOWrapper(p.stdout, encoding="utf-8"):
+      row = line.rstrip().split('\t')
       rawList['committers'].append({"_account_id": int(row[0]),
                                     "email": row[3],
                                     "name": row[2],
                                     "username": row[1]})
+    if p.wait() != 0:
+        raise CalledProcessError(p.returncode, cmd)
 
     url = 'https://gerrit.libreoffice.org/changes/?q=after:' + searchDate.strftime("%Y-%m-%d") + \
          '&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS&o=MESSAGES&limit=200&start='
diff --git a/esc-reporting/esc-report.py b/esc-reporting/esc-report.py
index 9f54321..7e1b630 100755
--- a/esc-reporting/esc-report.py
+++ b/esc-reporting/esc-report.py
@@ -39,6 +39,7 @@ import operator
 import datetime
 import json
 import xmltodict
+from subprocess import check_call
 
 
 
@@ -462,8 +463,8 @@ def report_bug_metrics():
     filePath = cfg['homedir'] + fileName
     fileContent = '/tmp/bugs/content.xml'
 
-    os.system('rm -rf /tmp/bugs')
-    os.system('unzip -d /tmp/bugs ' + filePath)
+    check_call(['rm', '-rf', '/tmp/bugs'])
+    check_call(['unzip', '-d', '/tmp/bugs', filePath])
     fp = open(fileContent, encoding='utf-8')
     text = fp.read()
     fp.close()
@@ -498,8 +499,8 @@ def report_bug_metrics():
     fp = open(fileContent, 'w', encoding='utf-8')
     print(text, file=fp)
     fp.close()
-    os.system('cd /tmp/bugs; zip ' + filePath + ' *')
-    os.system('cd ' + cfg['homedir'] + 'bug-metrics; git add *; git commit -m \'new version ' + statList['addDate'] + '\'')
+    check_call(['zip', filePath, '-r', '.'], cwd='/tmp/bugs')
+    check_call(['git', '-C', cfg['homedir'] + 'bug-metrics', 'commit', '-am', 'new version ' + statList['addDate']])
 
     fileBody='/tmp/esc_odf.txt'
     fp = open(fileBody, 'w', encoding='utf-8')


More information about the Libreoffice-commits mailing list