mbligh | 54fe698 | 2007-09-19 22:20:12 +0000 | [diff] [blame] | 1 | import os, re, parse, sys, frontend |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 2 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 3 | color_map = { |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 4 | 'GOOD' : '#88ff88', # green |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 5 | 'WARN' : '#fffc00', # yellow |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 6 | 'ALERT' : '#fffc00', # yellow |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 7 | 'FAIL' : '#ff8888', # red |
| 8 | 'ABORT' : '#ff8888', # red |
| 9 | 'ERROR' : '#ff8888', # red |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 10 | 'NOSTATUS' : '#ffffff', # white |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 11 | 'header' : '#e5e5c0', # greyish yellow |
| 12 | 'blank' : '#ffffff', # white |
| 13 | 'plain_text' : '#e5e5c0', # greyish yellow |
| 14 | 'borders' : '#bbbbbb', # grey |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 15 | 'white' : '#ffffff', # white |
| 16 | 'green' : '#66ff66', # green |
| 17 | 'yellow' : '#fffc00', # yellow |
| 18 | 'red' : '#ff6666', # red |
| 19 | } |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 20 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 21 | |
| 22 | class box: |
mbligh | f91b3f5 | 2007-10-07 00:47:04 +0000 | [diff] [blame] | 23 | 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 |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 28 | if color_map.has_key(color_key): |
| 29 | self.color = color_map[color_key] |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 30 | elif header: |
| 31 | self.color = color_map['header'] |
| 32 | elif data: |
| 33 | self.color = color_map['plain_text'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 34 | else: |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 35 | self.color = color_map['blank'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 36 | self.header = header |
| 37 | |
| 38 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 39 | def html(self): |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 40 | if self.data: |
| 41 | data = self.data |
| 42 | else: |
| 43 | data = ' ' |
| 44 | |
| 45 | if self.header: |
| 46 | box_html = 'th' |
| 47 | else: |
| 48 | box_html = 'td' |
| 49 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 50 | return "<%s bgcolor=%s>%s</%s>" % \ |
| 51 | (box_html, self.color, data, box_html) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 52 | |
| 53 | |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 54 | def 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 (%d%%)" % (status_count[status], status_pct[status]) |
| 67 | string = "%d %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 | |
| 72 | def status_count_box(db, tests, link = None): |
| 73 | """ |
| 74 | Display a table within a box, representing the status count of |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 75 | the group of tests (e.g. 10 GOOD, 2 WARN, 3 FAIL). |
| 76 | |
| 77 | Starts from a list of test objects |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 78 | """ |
| 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 |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 86 | return status_precounted_box(db, status_count, link) |
| 87 | |
| 88 | |
| 89 | def 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 | |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 97 | 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]) |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 102 | |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 103 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 104 | def 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 | |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 112 | print '<table bgcolor="%s" cellspacing="1" cellpadding="5">' % ( |
| 113 | color_map['borders']) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 114 | for row in matrix: |
| 115 | print '<tr>' |
| 116 | for element in row: |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 117 | print element.html() |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 118 | print '</tr>' |
| 119 | print '</table>' |
| 120 | |
| 121 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 122 | def 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) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 131 | if tests.count('boot'): |
| 132 | results.append('boot') |
| 133 | tests.remove('boot') |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 134 | return results + sorted(tests) |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 135 | |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 136 | |
| 137 | def print_main_header(): |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 138 | print '<head><style type="text/css">' |
| 139 | print 'a { text-decoration: none }' |
| 140 | print '</style></head>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 141 | print '<h2>' |
| 142 | print '<a href="machine_kernel.cgi">Functional</a>' |
| 143 | print '   ' |
| 144 | print '<a href="machine_benchmark.cgi">Performance</a>' |
| 145 | print '</h2><p>' |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 146 | |
| 147 | |
| 148 | def group_name(group): |
| 149 | name = re.sub('_', '<br>', group.name) |
| 150 | if re.search('/', name): |
| 151 | (owner, machine) = name.split('/', 1) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 152 | name = owner + '<br>' + machine |
| 153 | return name |