blob: 40dda0b83f906e6f0bb1383ad9f542d4ba569461 [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 = {
4 'GOOD' : '#66ff66', # green
5 'WARN' : '#fffc00', # yellow
6 'FAIL' : '#ff6666', # red
7 'ABORT' : '#ff6666', # red
8 'ERROR' : '#ff6666', # red
9 'NOSTATUS' : '#ffffff', # white
10 'white' : '#ffffff', # white
11 'green' : '#66ff66', # green
12 'yellow' : '#fffc00', # yellow
13 'red' : '#ff6666', # red
14}
mblighbfec5222007-09-14 16:58:57 +000015
mblighcfd2d012007-09-19 21:07:34 +000016
17class box:
mblighf91b3f52007-10-07 00:47:04 +000018 def __init__(self, data, color_key = None, header = False, link = None):
19 if link:
20 self.data = '<a href="%s">%s</a>' % (link, data)
21 else:
22 self.data = data
mblighcfd2d012007-09-19 21:07:34 +000023 if color_map.has_key(color_key):
24 self.color = color_map[color_key]
25 else:
26 self.color = color_map['white']
27 self.header = header
28
29
mbligh38757e72007-09-30 22:32:13 +000030 def html(self):
mblighcfd2d012007-09-19 21:07:34 +000031 if self.data:
32 data = self.data
33 else:
34 data = '&nbsp'
35
36 if self.header:
37 box_html = 'th'
38 else:
39 box_html = 'td'
40
mbligh38757e72007-09-30 22:32:13 +000041 return "<%s bgcolor=%s>%s</%s>" % \
42 (box_html, self.color, data, box_html)
mblighcfd2d012007-09-19 21:07:34 +000043
44
mbligha997a342007-10-06 22:35:04 +000045def status_html(db, status_count):
46 """
47 status_count: dict mapping from status (integer key) to count
48 eg. { 'GOOD' : 4, 'FAIL' : 1 }
49 """
50# total = sum(status_count.values())
51# status_pct = {}
52# for status in status_count.keys():
53# status_pct[status] = (100 * status_count[status]) / total
54 rows = []
55 for status in sorted(status_count.keys(), reverse = True):
56 status_word = db.status_word[status]
57 # string = "%d&nbsp(%d%%)" % (status_count[status], status_pct[status])
58 string = "%d&nbsp;%s" % (status_count[status], status_word)
59 rows.append("<tr>%s</tr>" % box(string, status_word).html())
60 return '<table>%s</table>' % '\n'.join(rows)
61
62
63def status_count_box(db, tests, link = None):
64 """
65 Display a table within a box, representing the status count of
66 the group of tests (e.g. 10 GOOD, 2 WARN, 3 FAIL)
67 """
68 if not tests:
69 return box(None, None)
70
71 status_count = {}
72 for test in tests:
73 count = status_count.get(test.status_num, 0)
74 status_count[test.status_num] = count + 1
75 worst = sorted(status_count.keys())[0]
76 html = status_html(db, status_count)
77 if link:
78 html = '<a href="%s">%s</a>' % (link, html)
79 return box(html, db.status_word[worst])
80
81
mblighcfd2d012007-09-19 21:07:34 +000082def print_table(matrix):
83 """
84 matrix: list of lists of boxes, giving a matrix of data
85 Each of the inner lists is a row, not a column.
86
87 Display the given matrix of data as a table.
88 """
89
90 print '<table cellpadding=5 border=1 class="boldtable">'
91 for row in matrix:
92 print '<tr>'
93 for element in row:
94 print element
mbligh38757e72007-09-30 22:32:13 +000095 print element.html()
mblighcfd2d012007-09-19 21:07:34 +000096 print '</tr>'
97 print '</table>'
98
99
mblighcfd2d012007-09-19 21:07:34 +0000100def sort_tests(tests):
101 kernel_order = ['patch', 'config', 'build', 'mkinitrd', 'install']
102
103 results = []
104 for kernel_op in kernel_order:
105 test = 'kernel.' + kernel_op
106 if tests.count(test):
107 results.append(test)
108 tests.remove(test)
109 return results + sorted(tests)
mblighbfec5222007-09-14 16:58:57 +0000110
mbligh04598752007-10-01 15:49:58 +0000111
112def print_main_header():
113 print '<h2>'
114 print '<a href="machine_kernel.cgi">Functional</a>'
115 print '&nbsp&nbsp&nbsp'
116 print '<a href="machine_benchmark.cgi">Performance</a>'
117 print '</h2><p>'