blob: 9d85a9d25569367cd62831302a3e34fc8c197ce4 [file] [log] [blame]
mbligh54fe6982007-09-19 22:20:12 +00001import os, re, parse, sys, frontend
mblighbfec5222007-09-14 16:58:57 +00002
mblighcfd2d012007-09-19 21:07:34 +00003color_map = {
mbligh1405f4e2007-11-05 19:26:23 +00004 'GOOD' : '#88ff88', # green
mblighcfd2d012007-09-19 21:07:34 +00005 'WARN' : '#fffc00', # yellow
mbligh1405f4e2007-11-05 19:26:23 +00006 'FAIL' : '#ff8888', # red
7 'ABORT' : '#ff8888', # red
8 'ERROR' : '#ff8888', # red
mblighcfd2d012007-09-19 21:07:34 +00009 'NOSTATUS' : '#ffffff', # white
mbligh1405f4e2007-11-05 19:26:23 +000010 'header' : '#e5e5c0', # greyish yellow
11 'blank' : '#ffffff', # white
12 'plain_text' : '#e5e5c0', # greyish yellow
13 'borders' : '#bbbbbb', # grey
mblighcfd2d012007-09-19 21:07:34 +000014 'white' : '#ffffff', # white
15 'green' : '#66ff66', # green
16 'yellow' : '#fffc00', # yellow
17 'red' : '#ff6666', # red
18}
mblighbfec5222007-09-14 16:58:57 +000019
mblighcfd2d012007-09-19 21:07:34 +000020
21class box:
mblighf91b3f52007-10-07 00:47:04 +000022 def __init__(self, data, color_key = None, header = False, link = None):
23 if link:
24 self.data = '<a href="%s">%s</a>' % (link, data)
25 else:
26 self.data = data
mblighcfd2d012007-09-19 21:07:34 +000027 if color_map.has_key(color_key):
28 self.color = color_map[color_key]
mbligh1405f4e2007-11-05 19:26:23 +000029 elif header:
30 self.color = color_map['header']
31 elif data:
32 self.color = color_map['plain_text']
mblighcfd2d012007-09-19 21:07:34 +000033 else:
mbligh1405f4e2007-11-05 19:26:23 +000034 self.color = color_map['blank']
mblighcfd2d012007-09-19 21:07:34 +000035 self.header = header
36
37
mbligh38757e72007-09-30 22:32:13 +000038 def html(self):
mblighcfd2d012007-09-19 21:07:34 +000039 if self.data:
40 data = self.data
41 else:
42 data = '&nbsp'
43
44 if self.header:
45 box_html = 'th'
46 else:
47 box_html = 'td'
48
mbligh38757e72007-09-30 22:32:13 +000049 return "<%s bgcolor=%s>%s</%s>" % \
50 (box_html, self.color, data, box_html)
mblighcfd2d012007-09-19 21:07:34 +000051
52
mbligha997a342007-10-06 22:35:04 +000053def status_html(db, status_count):
54 """
55 status_count: dict mapping from status (integer key) to count
56 eg. { 'GOOD' : 4, 'FAIL' : 1 }
57 """
58# total = sum(status_count.values())
59# status_pct = {}
60# for status in status_count.keys():
61# status_pct[status] = (100 * status_count[status]) / total
62 rows = []
63 for status in sorted(status_count.keys(), reverse = True):
64 status_word = db.status_word[status]
65 # string = "%d&nbsp(%d%%)" % (status_count[status], status_pct[status])
66 string = "%d&nbsp;%s" % (status_count[status], status_word)
67 rows.append("<tr>%s</tr>" % box(string, status_word).html())
68 return '<table>%s</table>' % '\n'.join(rows)
69
70
71def status_count_box(db, tests, link = None):
72 """
73 Display a table within a box, representing the status count of
74 the group of tests (e.g. 10 GOOD, 2 WARN, 3 FAIL)
75 """
76 if not tests:
77 return box(None, None)
78
79 status_count = {}
80 for test in tests:
81 count = status_count.get(test.status_num, 0)
82 status_count[test.status_num] = count + 1
83 worst = sorted(status_count.keys())[0]
84 html = status_html(db, status_count)
85 if link:
86 html = '<a href="%s">%s</a>' % (link, html)
87 return box(html, db.status_word[worst])
mbligh1405f4e2007-11-05 19:26:23 +000088
mbligha997a342007-10-06 22:35:04 +000089
mblighcfd2d012007-09-19 21:07:34 +000090def print_table(matrix):
91 """
92 matrix: list of lists of boxes, giving a matrix of data
93 Each of the inner lists is a row, not a column.
94
95 Display the given matrix of data as a table.
96 """
97
mbligh1405f4e2007-11-05 19:26:23 +000098 print '<table bgcolor="%s" cellspacing="1" cellpadding="5">' % (
99 color_map['borders'])
mblighcfd2d012007-09-19 21:07:34 +0000100 for row in matrix:
101 print '<tr>'
102 for element in row:
mbligh38757e72007-09-30 22:32:13 +0000103 print element.html()
mblighcfd2d012007-09-19 21:07:34 +0000104 print '</tr>'
105 print '</table>'
106
107
mblighcfd2d012007-09-19 21:07:34 +0000108def sort_tests(tests):
109 kernel_order = ['patch', 'config', 'build', 'mkinitrd', 'install']
110
111 results = []
112 for kernel_op in kernel_order:
113 test = 'kernel.' + kernel_op
114 if tests.count(test):
115 results.append(test)
116 tests.remove(test)
117 return results + sorted(tests)
mblighbfec5222007-09-14 16:58:57 +0000118
mbligh04598752007-10-01 15:49:58 +0000119
120def print_main_header():
mbligh1405f4e2007-11-05 19:26:23 +0000121 print '<head><style type="text/css">'
122 print 'a { text-decoration: none }'
123 print '</style></head>'
mbligh04598752007-10-01 15:49:58 +0000124 print '<h2>'
125 print '<a href="machine_kernel.cgi">Functional</a>'
126 print '&nbsp&nbsp&nbsp'
127 print '<a href="machine_benchmark.cgi">Performance</a>'
128 print '</h2><p>'