-
Notifications
You must be signed in to change notification settings - Fork 3
/
suse-qa-sle-etherpad-status
executable file
·81 lines (68 loc) · 3.24 KB
/
suse-qa-sle-etherpad-status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
"""
Gather status per QA domain from an etherpad document to serve as a summary status report
"""
# Python 2 and 3: easiest option
# see http://python-future.org/compatible_idioms.html
from __future__ import absolute_import
from future.standard_library import install_aliases # isort:skip to keep 'install_aliases()'
install_aliases()
import argparse
import datetime
import logging
import os.path
import re
import subprocess
import sys
import urllib.parse
logging.basicConfig()
log = logging.getLogger(sys.argv[0] if __name__ == "__main__" else __name__)
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
"""Preserve multi-line __doc__ and provide default arguments in help strings."""
pass
def parse_args():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=CustomFormatter)
parser.add_argument('-v', '--verbose',
help="Increase verbosity level, specify multiple times to increase verbosity", action='count', default=1)
parser.add_argument('--etherpad-url', default="https://etherpad.nue.suse.com/p/QA_SLE_status/",
help="URL to etherpad document")
parser.add_argument('--report-md', default="~/Export/qa_sle_etherpad_status.md",
help="Path to report output document in markdown format (intermediate step)")
parser.add_argument('--dry-run', action='store_true',
help="Do not do any real action, just simulate")
args = parser.parse_args()
verbose_to_log = {
0: logging.CRITICAL,
1: logging.ERROR,
2: logging.WARN,
3: logging.INFO,
4: logging.DEBUG
}
logging_level = logging.DEBUG if args.verbose > 4 else verbose_to_log[args.verbose]
log.setLevel(logging_level)
return args
def call(cmds, dry_run=False):
log.debug("call: %s" % cmds)
return subprocess.call(('echo Simulating: ' if dry_run else '') + cmds, shell=True)
def main():
args = parse_args()
url = urllib.parse.urljoin(args.etherpad_url, 'export/markdown')
cmd = "curl -s " + url + " | grep -B 3 -P 'Status.*(RED|AMBER|GREEN)' | sed -n -e 's/\s*Status:\s*//p' -e '/^#/p'"
log.debug("cmd: %s" % cmd)
call(cmd + ' > %s' % args.report_md, args.dry_run)
report_path = os.path.expanduser(args.report_md)
report_str = open(report_path).read()
status_replace = {
r'RED': '<span style="color: red;">Red</span>',
r'AMBER': '<span style="color: #FFBF00;">Amber</span>',
r'GREEN': '<span style="color: green;">Green</span>',
}
rx = re.compile('|'.join(map(re.escape, status_replace)))
def one_match(m): return '**Status: ' + status_replace[m.group(0)] + '**'
report_str = rx.sub(one_match, report_str)
report_str += "\n\n<small>This report was automatically generated by the script \`%s\` at %s and a bit of python code :)\nThis script lives in [gh#okurz/scripts](https://github.com/okurz/scripts/blob/master/suse-qa-sle-etherpad-status)</small>" % (cmd, datetime.datetime.now())
open(report_path, 'w').write(report_str)
report_html = args.report_md.replace('.md', '.html')
call('markdown %s > %s' % (args.report_md, report_html), args.dry_run)
if __name__ == "__main__":
main()