blob: 0839599a72a9ab5d529bdd0a26cb1359f516d343 [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
apw569f4782007-12-13 19:32:53 +00006 'ALERT' : '#fffc00', # yellow
mbligh1405f4e2007-11-05 19:26:23 +00007 'FAIL' : '#ff8888', # red
8 'ABORT' : '#ff8888', # red
9 'ERROR' : '#ff8888', # red
mblighcfd2d012007-09-19 21:07:34 +000010 'NOSTATUS' : '#ffffff', # white
mbligh1405f4e2007-11-05 19:26:23 +000011 'header' : '#e5e5c0', # greyish yellow
12 'blank' : '#ffffff', # white
13 'plain_text' : '#e5e5c0', # greyish yellow
14 'borders' : '#bbbbbb', # grey
mblighcfd2d012007-09-19 21:07:34 +000015 'white' : '#ffffff', # white
16 'green' : '#66ff66', # green
17 'yellow' : '#fffc00', # yellow
18 'red' : '#ff6666', # red
19}
mblighbfec5222007-09-14 16:58:57 +000020
mblighcfd2d012007-09-19 21:07:34 +000021
22class box:
mblighf91b3f52007-10-07 00:47:04 +000023 def __init__(self, data, color_key = None, header = False, link = None):
24 if link:
25 self.data = '<a href="%s">%s</a>' % (link, data)
26 else:
27 self.data = data
mblighcfd2d012007-09-19 21:07:34 +000028 if color_map.has_key(color_key):
29 self.color = color_map[color_key]
mbligh1405f4e2007-11-05 19:26:23 +000030 elif header:
31 self.color = color_map['header']
32 elif data:
33 self.color = color_map['plain_text']
mblighcfd2d012007-09-19 21:07:34 +000034 else:
mbligh1405f4e2007-11-05 19:26:23 +000035 self.color = color_map['blank']
mblighcfd2d012007-09-19 21:07:34 +000036 self.header = header
37
38
mbligh38757e72007-09-30 22:32:13 +000039 def html(self):
mblighcfd2d012007-09-19 21:07:34 +000040 if self.data:
41 data = self.data
42 else:
43 data = '&nbsp'
44
45 if self.header:
46 box_html = 'th'
47 else:
48 box_html = 'td'
49
mbligh38757e72007-09-30 22:32:13 +000050 return "<%s bgcolor=%s>%s</%s>" % \
51 (box_html, self.color, data, box_html)
mblighcfd2d012007-09-19 21:07:34 +000052
53
mbligha997a342007-10-06 22:35:04 +000054def status_html(db, status_count):
55 """
56 status_count: dict mapping from status (integer key) to count
57 eg. { 'GOOD' : 4, 'FAIL' : 1 }
58 """
59# total = sum(status_count.values())
60# status_pct = {}
61# for status in status_count.keys():
62# status_pct[status] = (100 * status_count[status]) / total
63 rows = []
64 for status in sorted(status_count.keys(), reverse = True):
65 status_word = db.status_word[status]
66 # string = "%d&nbsp(%d%%)" % (status_count[status], status_pct[status])
67 string = "%d&nbsp;%s" % (status_count[status], status_word)
68 rows.append("<tr>%s</tr>" % box(string, status_word).html())
69 return '<table>%s</table>' % '\n'.join(rows)
70
71
72def status_count_box(db, tests, link = None):
73 """
74 Display a table within a box, representing the status count of
mbligh83f63a02007-12-12 19:13:04 +000075 the group of tests (e.g. 10 GOOD, 2 WARN, 3 FAIL).
76
77 Starts from a list of test objects
mbligha997a342007-10-06 22:35:04 +000078 """
79 if not tests:
80 return box(None, None)
81
82 status_count = {}
83 for test in tests:
84 count = status_count.get(test.status_num, 0)
85 status_count[test.status_num] = count + 1
mbligh83f63a02007-12-12 19:13:04 +000086 return status_precounted_box(db, status_count, link)
87
88
89def status_precounted_box(db, status_count, link = None):
90 """
91 Display a table within a box, representing the status count of
92 the group of tests (e.g. 10 GOOD, 2 WARN, 3 FAIL)
93 """
94 if not status_count:
95 return box(None, None)
96
mbligha997a342007-10-06 22:35:04 +000097 worst = sorted(status_count.keys())[0]
98 html = status_html(db, status_count)
99 if link:
100 html = '<a href="%s">%s</a>' % (link, html)
101 return box(html, db.status_word[worst])
mbligh1405f4e2007-11-05 19:26:23 +0000102
mbligha997a342007-10-06 22:35:04 +0000103
mblighcfd2d012007-09-19 21:07:34 +0000104def print_table(matrix):
105 """
106 matrix: list of lists of boxes, giving a matrix of data
107 Each of the inner lists is a row, not a column.
108
109 Display the given matrix of data as a table.
110 """
111
mbligh1405f4e2007-11-05 19:26:23 +0000112 print '<table bgcolor="%s" cellspacing="1" cellpadding="5">' % (
113 color_map['borders'])
mblighcfd2d012007-09-19 21:07:34 +0000114 for row in matrix:
115 print '<tr>'
116 for element in row:
mbligh38757e72007-09-30 22:32:13 +0000117 print element.html()
mblighcfd2d012007-09-19 21:07:34 +0000118 print '</tr>'
119 print '</table>'
120
121
mblighcfd2d012007-09-19 21:07:34 +0000122def sort_tests(tests):
123 kernel_order = ['patch', 'config', 'build', 'mkinitrd', 'install']
124
125 results = []
126 for kernel_op in kernel_order:
127 test = 'kernel.' + kernel_op
128 if tests.count(test):
129 results.append(test)
130 tests.remove(test)
mbligh7a41a862007-11-30 17:44:24 +0000131 if tests.count('boot'):
132 results.append('boot')
133 tests.remove('boot')
mblighcfd2d012007-09-19 21:07:34 +0000134 return results + sorted(tests)
mblighbfec5222007-09-14 16:58:57 +0000135
mbligh04598752007-10-01 15:49:58 +0000136
137def print_main_header():
mbligh1405f4e2007-11-05 19:26:23 +0000138 print '<head><style type="text/css">'
139 print 'a { text-decoration: none }'
140 print '</style></head>'
mbligh04598752007-10-01 15:49:58 +0000141 print '<h2>'
142 print '<a href="machine_kernel.cgi">Functional</a>'
143 print '&nbsp&nbsp&nbsp'
144 print '<a href="machine_benchmark.cgi">Performance</a>'
145 print '</h2><p>'
mbligh7a41a862007-11-30 17:44:24 +0000146
147
148def group_name(group):
149 name = re.sub('_', '<br>', group.name)
150 if re.search('/', name):
151 (owner, machine) = name.split('/', 1)
mbligh7a41a862007-11-30 17:44:24 +0000152 name = owner + '<br>' + machine
153 return name