forked from kernelci/lava-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log2html.py
107 lines (92 loc) · 2.6 KB
/
log2html.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
#
# error/warn formatting, css, colors etc. stolen from Olof Johansson <[email protected]>
#
import os
import sys
import subprocess
import json
import re
headers = """
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Boot log: %s</title>
<style type="text/css">
body { background-color: black; color: white; }
pre warn { color: #F88017; }
pre err { color: red; }
pre pass { color: green; }
pre pyboot { color: yellow; }
pre offline { color: darkgray; }
A:link {text-decoration: none }
A:visited {text-decoration: none }
A:active {text-decoration: none }
A:hover {text-decoration: bold; color: red; }
</style>
</head>
<body>
"""
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("<h1>Boot log: %s</h1>\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("<font size=-2><pre>\n")
html_f.write("<h2>Boot result: ")
if boot_result == "PASS":
html_f.write("<pass>PASS</pass></h2>")
elif boot_result == "FAIL":
html_f.write("<err>FAIL</err></h2>")
else:
html_f.write("<warn>%s</warn></h2>" %boot_result)
html_f.write("<h2>Errors: %d</h2>" %num_errors)
if num_errors:
for e in errors:
html_f.write("<err>%s</err>\n" %e.rstrip())
html_f.write("\n")
html_f.write("<h2>Warnings: %d</h2>" %num_warnings)
if num_warnings:
for e in warnings:
html_f.write("<warn>%s</warn>\n" %e.rstrip())
html_f.write("\n")
html_f.write("<h2>Full boot log:</h2>\n")
for line in log_f:
warn = err = pyboot = False
if line.startswith("[WARN]"):
warn = True
html_f.write("<warn>")
elif line.startswith("[ERR]"):
err = True
html_f.write("<err>")
m = re.search("^# PYBOOT:", line)
if m:
line = "<pyboot>%s</pyboot>" %line
html_f.write(line)
if warn:
html_f.write("</warn>")
elif err:
html_f.write("</err>")
html_f.write("</pre></font></body></html>")
log_f.close()
html_f.close()