diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-02-25 22:55:05 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-03-15 14:22:49 +0000 |
commit | d7bf8c17eca8f8c89898a7794462c773c449e983 (patch) | |
tree | d18618fca85ca5f0c077032cc7b009344b60f663 /import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py | |
parent | e2b5abdc9f28cdf8578e5b9be803c8e697443c20 (diff) | |
download | blackbird-openbmc-d7bf8c17eca8f8c89898a7794462c773c449e983.tar.gz blackbird-openbmc-d7bf8c17eca8f8c89898a7794462c773c449e983.zip |
Yocto 2.4
Move OpenBMC to Yocto 2.4(rocko)
Tested: Built and verified Witherspoon and Palmetto images
Change-Id: I12057b18610d6fb0e6903c60213690301e9b0c67
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py')
-rwxr-xr-x | import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py b/import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py index 261ca514e..913847bbe 100755 --- a/import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py +++ b/import-layers/yocto-poky/scripts/contrib/oe-build-perf-report-email.py @@ -25,6 +25,7 @@ import socket import subprocess import sys import tempfile +from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -71,6 +72,10 @@ def parse_args(argv): help="Only print errors") parser.add_argument('--to', action='append', help="Recipients of the email") + parser.add_argument('--cc', action='append', + help="Carbon copy recipients of the email") + parser.add_argument('--bcc', action='append', + help="Blind carbon copy recipients of the email") parser.add_argument('--subject', default="Yocto build perf test report", help="Email subject") parser.add_argument('--outdir', '-o', @@ -107,15 +112,6 @@ def decode_png(infile, outfile): subprocess.check_output(['optipng', outfile], stderr=subprocess.STDOUT) -def encode_png(pngfile): - """Encode png into a <img> html element""" - with open(pngfile, 'rb') as f: - data = f.read() - - b64_data = base64.b64encode(data) - return '<img src="data:image/png;base64,' + b64_data.decode('utf-8') + '">\n' - - def mangle_html_report(infile, outfile, pngs): """Mangle html file into a email compatible format""" paste = True @@ -140,9 +136,7 @@ def mangle_html_report(infile, outfile, pngs): # Replace charts with <img> elements match = re.match('<div id="(?P<id>\w+)"', stripped) if match and match.group('id') in pngs: - #f_out.write('<img src="{}">\n'.format(match.group('id') + '.png')) - png_file = os.path.join(png_dir, match.group('id') + '.png') - f_out.write(encode_png(png_file)) + f_out.write('<img src="cid:{}"\n'.format(match.group('id'))) else: f_out.write(line) @@ -166,7 +160,7 @@ def scrape_html_report(report, outdir, phantomjs_extra_args=None): stderr=subprocess.STDOUT) pngs = [] - attachments = [] + images = [] for fname in os.listdir(tmpdir): base, ext = os.path.splitext(fname) if ext == '.png': @@ -174,7 +168,7 @@ def scrape_html_report(report, outdir, phantomjs_extra_args=None): decode_png(os.path.join(tmpdir, fname), os.path.join(outdir, fname)) pngs.append(base) - attachments.append(fname) + images.append(fname) elif ext in ('.html', '.htm'): report_file = fname else: @@ -184,11 +178,13 @@ def scrape_html_report(report, outdir, phantomjs_extra_args=None): log.debug("Mangling html report file %s", report_file) mangle_html_report(os.path.join(tmpdir, report_file), os.path.join(outdir, report_file), pngs) - return report_file, attachments + return (os.path.join(outdir, report_file), + [os.path.join(outdir, i) for i in images]) finally: shutil.rmtree(tmpdir) -def send_email(text_fn, html_fn, subject, recipients): +def send_email(text_fn, html_fn, image_fns, subject, recipients, copy=[], + blind_copy=[]): """Send email""" # Generate email message text_msg = html_msg = None @@ -197,8 +193,16 @@ def send_email(text_fn, html_fn, subject, recipients): text_msg = MIMEText("Yocto build performance test report.\n" + f.read(), 'plain') if html_fn: + html_msg = msg = MIMEMultipart('related') with open(html_fn) as f: - html_msg = MIMEText(f.read(), 'html') + html_msg.attach(MIMEText(f.read(), 'html')) + for img_fn in image_fns: + # Expect that content id is same as the filename + cid = os.path.splitext(os.path.basename(img_fn))[0] + with open(img_fn, 'rb') as f: + image_msg = MIMEImage(f.read()) + image_msg['Content-ID'] = '<{}>'.format(cid) + html_msg.attach(image_msg) if text_msg and html_msg: msg = MIMEMultipart('alternative') @@ -217,6 +221,10 @@ def send_email(text_fn, html_fn, subject, recipients): '{}@{}'.format(pw_data.pw_name, socket.getfqdn())) msg['From'] = "{} <{}>".format(full_name, email) msg['To'] = ', '.join(recipients) + if copy: + msg['Cc'] = ', '.join(copy) + if blind_copy: + msg['Bcc'] = ', '.join(blind_copy) msg['Subject'] = subject # Send email @@ -243,14 +251,19 @@ def main(argv=None): try: log.debug("Storing email parts in %s", outdir) - html_report = None + html_report = images = None if args.html: - scrape_html_report(args.html, outdir, args.phantomjs_args) - html_report = os.path.join(outdir, os.path.basename(args.html)) + html_report, images = scrape_html_report(args.html, outdir, + args.phantomjs_args) if args.to: log.info("Sending email to %s", ', '.join(args.to)) - send_email(args.text, html_report, args.subject, args.to) + if args.cc: + log.info("Copying to %s", ', '.join(args.cc)) + if args.bcc: + log.info("Blind copying to %s", ', '.join(args.bcc)) + send_email(args.text, html_report, images, args.subject, + args.to, args.cc, args.bcc) except subprocess.CalledProcessError as err: log.error("%s, with output:\n%s", str(err), err.output.decode()) return 1 |