#!/usr/bin/env python # # error/warn formatting, css, colors etc. stolen from Olof Johansson # import os import sys import subprocess import json import re headers = """ Boot log: %s """ log = sys.argv[1] if not os.path.exists(log): print "ERROR: logfile %s doesn't exist." %log sys.exit(1) base,ext = os.path.splitext(log) html = base + ".html" jsn = base + ".json" base = os.path.basename(base) board = base if base.startswith("boot-"): board = base[5:] log_f = open(log, "r") html_f = open(html, "w") json_f = open(jsn, "r+") boot_json = json.load(json_f) json_f.seek(0) boot_result = None if boot_json.has_key("boot_result"): boot_result = boot_json["boot_result"] html_f.write(headers %board) html_f.write("

Boot log: %s

\n" %(board)) errors = subprocess.check_output('grep "^\[ERR\]" %s | cat' %log, shell=True).splitlines() num_errors = len(errors) warnings = subprocess.check_output('grep "^\[WARN\]" %s | cat' %log, shell=True).splitlines() num_warnings = len(warnings) html_f.write("
\n")

html_f.write("

Boot result: ") if boot_result == "PASS": html_f.write("PASS

") elif boot_result == "FAIL": html_f.write("FAIL") else: html_f.write("%s" %boot_result) html_f.write("

Errors: %d

" %num_errors) if num_errors: for e in errors: html_f.write("%s\n" %e.rstrip()) html_f.write("\n") html_f.write("

Warnings: %d

" %num_warnings) if num_warnings: for e in warnings: html_f.write("%s\n" %e.rstrip()) html_f.write("\n") html_f.write("

Full boot log:

\n") for line in log_f: warn = err = pyboot = False if line.startswith("[WARN]"): warn = True html_f.write("") elif line.startswith("[ERR]"): err = True html_f.write("") m = re.search("^# PYBOOT:", line) if m: line = "%s" %line html_f.write(line) if warn: html_f.write("") elif err: html_f.write("") html_f.write("
") log_f.close() html_f.close()