blob: a21516fd918f30bf981244e53626bb2039d50066 [file] [log] [blame]
mbligh2e4e5df2007-11-05 17:22:46 +00001#!/usr/bin/python
2
3"""
4Selects all rows and columns that satisfy the condition specified
5and draws the matrix. There is a seperate SQL query made for every (x,y)
6in the matrix.
7"""
8
9
10print "Content-type: text/html\n"
11import cgi, cgitb, re
mbligha4266932007-11-05 18:12:16 +000012import sys, os
mblighb180f6c2008-01-04 20:24:41 +000013import urllib
mbligh2e4e5df2007-11-05 17:22:46 +000014
15tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
16sys.path.insert(0, tko)
17
mbligh2b672532007-11-05 19:24:51 +000018import display, frontend, db, query_lib
mbligh12eebfa2008-01-03 02:01:53 +000019client_bin = os.path.abspath(os.path.join(tko, '../client/bin'))
20sys.path.insert(0, client_bin)
21import kernel_versions
22
mbligh2e4e5df2007-11-05 17:22:46 +000023
mbligh190a81d2007-11-05 20:40:38 +000024html_header = """\
25<form action="compose_query.cgi" method="get">
26<table border="0">
27<tr>
28 <td>Column: </td>
29 <td>Row: </td>
30 <td>Condition: </td>
31 <td align="center"><a href="index.html">Help</a></td>
32</tr>
33<tr>
34 <td>
35 <SELECT NAME="columns">
36 %s
37 </SELECT>
38 </td>
39 <td>
40 <SELECT NAME="rows">
41 %s
42 </SELECT>
43 </td>
44 <td>
mbligh12eebfa2008-01-03 02:01:53 +000045 <input type="text" name="condition" size="30" maxlength="200" value="%s">
mbligh190a81d2007-11-05 20:40:38 +000046 <input type="hidden" name="title" value="Report">
47 </td>
48 <td align="center"><input type="submit" value="Submit">
49 </td>
50</tr>
51</table>
52</form>
53"""
54
mbligh12eebfa2008-01-03 02:01:53 +000055
mbligh5dd503b2008-01-03 16:35:27 +000056next_field = {
57 'machine_group': 'hostname',
58 'hostname': 'tag',
59 'tag': 'tag',
60
61 'kernel': 'test',
mbligh439661b2008-02-19 15:57:53 +000062 'test': 'test',
mbligh5dd503b2008-01-03 16:35:27 +000063 'label': 'label',
64
65 'reason': 'reason',
66 'user': 'user',
67 'status': 'status',
68}
69
70
mbligh12eebfa2008-01-03 02:01:53 +000071
72def parse_field(form, form_field, field_default):
73 if not form_field in form:
74 return field_default
75 field_input = form[form_field].value.lower()
mbligh2ba3e732008-01-16 01:30:19 +000076 if field_input and field_input in frontend.test_view_field_dict:
mbligh12eebfa2008-01-03 02:01:53 +000077 return field_input
78 return field_default
79
80
81def parse_condition(form, form_field, field_default):
82 if not form_field in form:
83 return field_default
84 return form[form_field].value
85
86
87form = cgi.FieldStorage()
mbligh2ba3e732008-01-16 01:30:19 +000088row = parse_field(form, 'rows', 'kernel')
89column = parse_field(form, 'columns', 'machine_group')
mbligh12eebfa2008-01-03 02:01:53 +000090condition_field = parse_condition(form, 'condition', '')
mbligh439661b2008-02-19 15:57:53 +000091## caller can specify rows and columns that shall be included into the report
92## regardless of whether actual test data is available yet
93force_row_field = parse_condition(form,'force_row','')
94force_column_field = parse_condition(form,'force_column','')
mbligh190a81d2007-11-05 20:40:38 +000095
mbligh439661b2008-02-19 15:57:53 +000096def split_forced_fields(force_field):
97 if force_field:
98 return force_field.split()
99 else:
100 return []
101
102force_row = split_forced_fields(force_row_field)
103force_column = split_forced_fields(force_column_field)
104
mbligh2e4e5df2007-11-05 17:22:46 +0000105cgitb.enable()
106db = db.db()
107
mbligh12eebfa2008-01-03 02:01:53 +0000108
mbligh2ba3e732008-01-16 01:30:19 +0000109def construct_link(x, y):
110 next_row = row
111 next_column = column
mbligh5dd503b2008-01-03 16:35:27 +0000112 condition_list = []
113 if condition_field != '':
114 condition_list.append(condition_field)
mbligh2ba3e732008-01-16 01:30:19 +0000115 if y:
116 next_row = next_field[row]
117 condition_list.append("%s='%s'" % (row, y))
118 if x:
119 next_column = next_field[column]
120 condition_list.append("%s='%s'" % (column, x))
mblighb180f6c2008-01-04 20:24:41 +0000121 next_condition = '&'.join(condition_list)
122 return 'compose_query.cgi?' + urllib.urlencode({'columns': next_column,
123 'rows': next_row, 'condition': next_condition})
mbligh5dd503b2008-01-03 16:35:27 +0000124
125
mbligh12eebfa2008-01-03 02:01:53 +0000126def create_select_options(selected_val):
mbligh190a81d2007-11-05 20:40:38 +0000127 ret = ""
mbligh190a81d2007-11-05 20:40:38 +0000128
mbligh2ba3e732008-01-16 01:30:19 +0000129 for option in sorted(frontend.test_view_field_dict.keys()):
mbligh190a81d2007-11-05 20:40:38 +0000130 if selected_val == option:
131 selected = " SELECTED"
132 else:
133 selected = ""
134
mbligh2ba3e732008-01-16 01:30:19 +0000135 ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \
136 (option, selected, option)
mbligh190a81d2007-11-05 20:40:38 +0000137
138 return ret
139
140
mbligh439661b2008-02-19 15:57:53 +0000141def insert_break_into_kernel_name(kernel_name):
142 ## insert <br> after each / in kernel name
143 ## but spare consequtive //
144
145 ## temporary stubed
146 #kernel_name = kernel_name.replace('//',';;')
147 #kernel_name = kernel_name.replace('/','/<br>')
148 #kernel_name = kernel_name.replace(';;','//')
149 return kernel_name
150
151
mbligh12eebfa2008-01-03 02:01:53 +0000152def gen_matrix():
mbligh12eebfa2008-01-03 02:01:53 +0000153 where = None
154 if condition_field.strip() != '':
155 where = query_lib.parse_scrub_and_gen_condition(
mbligh2ba3e732008-01-16 01:30:19 +0000156 condition_field, frontend.test_view_field_dict)
mbligh12eebfa2008-01-03 02:01:53 +0000157 print "<!-- where clause: %s -->" % (where,)
mbligh2e4e5df2007-11-05 17:22:46 +0000158
mbligh2ba3e732008-01-16 01:30:19 +0000159 test_data = frontend.get_matrix_data(db, column, row, where)
mbligh439661b2008-02-19 15:57:53 +0000160
161 for f_row in force_row:
162 if not f_row in test_data.y_values:
163 test_data.y_values.append(f_row)
164 for f_column in force_column:
165 if not f_column in test_data.x_values:
166 test_data.x_values.append(f_column)
mbligh2e4e5df2007-11-05 17:22:46 +0000167
mbligh2ba3e732008-01-16 01:30:19 +0000168 if not test_data.y_values:
mbligh12eebfa2008-01-03 02:01:53 +0000169 msg = "There are no results for this query (yet?)."
170 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000171
mbligh5dd503b2008-01-03 16:35:27 +0000172 link = 'compose_query.cgi?columns=%s&rows=%s&condition=%s' % (
mbligh2ba3e732008-01-16 01:30:19 +0000173 row, column, condition_field)
mbligh5dd503b2008-01-03 16:35:27 +0000174 header_row = [display.box("<center>(Flip Axis)</center>", link=link)]
175
mbligh2ba3e732008-01-16 01:30:19 +0000176 for x in test_data.x_values:
mbligh439661b2008-02-19 15:57:53 +0000177 if column == 'kernel':
178 x_br = insert_break_into_kernel_name(x)
179 else:
180 x_br = x
mbligh2ba3e732008-01-16 01:30:19 +0000181 link = construct_link(x, None)
mbligh439661b2008-02-19 15:57:53 +0000182 header_row.append(display.box(x_br, header=True, link=link))
mbligh2e4e5df2007-11-05 17:22:46 +0000183
184 matrix = [header_row]
mbligh2ba3e732008-01-16 01:30:19 +0000185 for y in test_data.y_values:
mbligh439661b2008-02-19 15:57:53 +0000186 if row == 'kernel':
187 y_br = insert_break_into_kernel_name(y)
188 else:
189 y_br = y
mbligh2ba3e732008-01-16 01:30:19 +0000190 link = construct_link(None, y)
mbligh439661b2008-02-19 15:57:53 +0000191 cur_row = [display.box(y_br, header=True, link=link)]
mbligh2ba3e732008-01-16 01:30:19 +0000192 for x in test_data.x_values:
mbligh12eebfa2008-01-03 02:01:53 +0000193 try:
mbligh2ba3e732008-01-16 01:30:19 +0000194 box_data = test_data.data[x][y].status_count
mbligh12eebfa2008-01-03 02:01:53 +0000195 except:
196 cur_row.append(display.box(None, None))
197 continue
mbligh2ba3e732008-01-16 01:30:19 +0000198 job_tag = test_data.data[x][y].job_tag
mbligh5dd503b2008-01-03 16:35:27 +0000199 if job_tag:
200 link = '/results/%s/' % job_tag
mbligh439661b2008-02-19 15:57:53 +0000201 if (row == 'test' and
202 not 'boot' in y and
203 not 'build' in y and
204 not 'install' in y ):
205 link += y + '/'
206 if (column == 'test' and
207 not 'boot' in x and
208 not 'build' in x and
209 not 'install' in x):
210 link += x + '/'
mbligh5dd503b2008-01-03 16:35:27 +0000211 else:
mbligh2ba3e732008-01-16 01:30:19 +0000212 link = construct_link(x, y)
mbligh12eebfa2008-01-03 02:01:53 +0000213 cur_row.append(display.status_precounted_box(db,
mbligh5dd503b2008-01-03 16:35:27 +0000214 box_data,
215 link))
mbligh12eebfa2008-01-03 02:01:53 +0000216 matrix.append(cur_row)
mbligh2e4e5df2007-11-05 17:22:46 +0000217
mbligh12eebfa2008-01-03 02:01:53 +0000218 return matrix
mbligh2b672532007-11-05 19:24:51 +0000219
mbligh2b672532007-11-05 19:24:51 +0000220
mbligh12eebfa2008-01-03 02:01:53 +0000221def main():
mbligh190a81d2007-11-05 20:40:38 +0000222 # create the actual page
mbligh190a81d2007-11-05 20:40:38 +0000223 print '<html><head><title>'
224 print 'Filtered Autotest Results'
225 print '</title></head><body>'
mbligh14671622008-01-11 16:49:54 +0000226 display.print_main_header()
mbligh2ba3e732008-01-16 01:30:19 +0000227 print html_header % (create_select_options(column),
228 create_select_options(row),
mbligh12eebfa2008-01-03 02:01:53 +0000229 condition_field)
mbligh439661b2008-02-19 15:57:53 +0000230 print display.color_keys_row()
mbligh12eebfa2008-01-03 02:01:53 +0000231 display.print_table(gen_matrix())
mbligh439661b2008-02-19 15:57:53 +0000232 print display.color_keys_row()
mbligh190a81d2007-11-05 20:40:38 +0000233 print '</body></html>'
mbligh2e4e5df2007-11-05 17:22:46 +0000234
235
236main()