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 |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 6 | 'FAIL' : '#ff8888', # red |
| 7 | 'ABORT' : '#ff8888', # red |
| 8 | 'ERROR' : '#ff8888', # red |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 9 | 'NOSTATUS' : '#ffffff', # white |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 10 | 'header' : '#e5e5c0', # greyish yellow |
| 11 | 'blank' : '#ffffff', # white |
| 12 | 'plain_text' : '#e5e5c0', # greyish yellow |
| 13 | 'borders' : '#bbbbbb', # grey |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 14 | 'white' : '#ffffff', # white |
| 15 | 'green' : '#66ff66', # green |
| 16 | 'yellow' : '#fffc00', # yellow |
| 17 | 'red' : '#ff6666', # red |
| 18 | } |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 19 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 20 | |
| 21 | class box: |
mbligh | f91b3f5 | 2007-10-07 00:47:04 +0000 | [diff] [blame] | 22 | 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 |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 27 | if color_map.has_key(color_key): |
| 28 | self.color = color_map[color_key] |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 29 | elif header: |
| 30 | self.color = color_map['header'] |
| 31 | elif data: |
| 32 | self.color = color_map['plain_text'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 33 | else: |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 34 | self.color = color_map['blank'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 35 | self.header = header |
| 36 | |
| 37 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 38 | def html(self): |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 39 | if self.data: |
| 40 | data = self.data |
| 41 | else: |
| 42 | data = ' ' |
| 43 | |
| 44 | if self.header: |
| 45 | box_html = 'th' |
| 46 | else: |
| 47 | box_html = 'td' |
| 48 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 49 | return "<%s bgcolor=%s>%s</%s>" % \ |
| 50 | (box_html, self.color, data, box_html) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 51 | |
| 52 | |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 53 | def 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 (%d%%)" % (status_count[status], status_pct[status]) |
| 66 | string = "%d %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 | |
| 71 | def 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]) |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 88 | |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 89 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 90 | def 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 | |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 98 | print '<table bgcolor="%s" cellspacing="1" cellpadding="5">' % ( |
| 99 | color_map['borders']) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 100 | for row in matrix: |
| 101 | print '<tr>' |
| 102 | for element in row: |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 103 | print element.html() |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 104 | print '</tr>' |
| 105 | print '</table>' |
| 106 | |
| 107 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 108 | def 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) |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 118 | |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 119 | |
| 120 | def print_main_header(): |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame^] | 121 | print '<head><style type="text/css">' |
| 122 | print 'a { text-decoration: none }' |
| 123 | print '</style></head>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 124 | print '<h2>' |
| 125 | print '<a href="machine_kernel.cgi">Functional</a>' |
| 126 | print '   ' |
| 127 | print '<a href="machine_benchmark.cgi">Performance</a>' |
| 128 | print '</h2><p>' |