blob: 976dafef3edf6206c8ee7a548bcf4c667a5fd487 [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',
62 'test': 'label',
63 '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', '')
mbligh190a81d2007-11-05 20:40:38 +000091
mbligh2e4e5df2007-11-05 17:22:46 +000092cgitb.enable()
93db = db.db()
94
mbligh12eebfa2008-01-03 02:01:53 +000095
mbligh2ba3e732008-01-16 01:30:19 +000096def construct_link(x, y):
97 next_row = row
98 next_column = column
mbligh5dd503b2008-01-03 16:35:27 +000099 condition_list = []
100 if condition_field != '':
101 condition_list.append(condition_field)
mbligh2ba3e732008-01-16 01:30:19 +0000102 if y:
103 next_row = next_field[row]
104 condition_list.append("%s='%s'" % (row, y))
105 if x:
106 next_column = next_field[column]
107 condition_list.append("%s='%s'" % (column, x))
mblighb180f6c2008-01-04 20:24:41 +0000108 next_condition = '&'.join(condition_list)
109 return 'compose_query.cgi?' + urllib.urlencode({'columns': next_column,
110 'rows': next_row, 'condition': next_condition})
mbligh5dd503b2008-01-03 16:35:27 +0000111
112
mbligh12eebfa2008-01-03 02:01:53 +0000113def create_select_options(selected_val):
mbligh190a81d2007-11-05 20:40:38 +0000114 ret = ""
mbligh190a81d2007-11-05 20:40:38 +0000115
mbligh2ba3e732008-01-16 01:30:19 +0000116 for option in sorted(frontend.test_view_field_dict.keys()):
mbligh190a81d2007-11-05 20:40:38 +0000117 if selected_val == option:
118 selected = " SELECTED"
119 else:
120 selected = ""
121
mbligh2ba3e732008-01-16 01:30:19 +0000122 ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \
123 (option, selected, option)
mbligh190a81d2007-11-05 20:40:38 +0000124
125 return ret
126
127
mbligh12eebfa2008-01-03 02:01:53 +0000128def gen_matrix():
mbligh12eebfa2008-01-03 02:01:53 +0000129 where = None
130 if condition_field.strip() != '':
131 where = query_lib.parse_scrub_and_gen_condition(
mbligh2ba3e732008-01-16 01:30:19 +0000132 condition_field, frontend.test_view_field_dict)
mbligh12eebfa2008-01-03 02:01:53 +0000133 print "<!-- where clause: %s -->" % (where,)
mbligh2e4e5df2007-11-05 17:22:46 +0000134
mbligh2ba3e732008-01-16 01:30:19 +0000135 test_data = frontend.get_matrix_data(db, column, row, where)
mbligh2e4e5df2007-11-05 17:22:46 +0000136
mbligh2ba3e732008-01-16 01:30:19 +0000137 if not test_data.y_values:
mbligh12eebfa2008-01-03 02:01:53 +0000138 msg = "There are no results for this query (yet?)."
139 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000140
mbligh5dd503b2008-01-03 16:35:27 +0000141 link = 'compose_query.cgi?columns=%s&rows=%s&condition=%s' % (
mbligh2ba3e732008-01-16 01:30:19 +0000142 row, column, condition_field)
mbligh5dd503b2008-01-03 16:35:27 +0000143 header_row = [display.box("<center>(Flip Axis)</center>", link=link)]
144
mbligh2ba3e732008-01-16 01:30:19 +0000145 for x in test_data.x_values:
146 link = construct_link(x, None)
147 header_row.append(display.box(x, header=True, link=link))
mbligh2e4e5df2007-11-05 17:22:46 +0000148
149 matrix = [header_row]
mbligh2ba3e732008-01-16 01:30:19 +0000150 for y in test_data.y_values:
151 link = construct_link(None, y)
152 cur_row = [display.box(y, header=True, link=link)]
153 for x in test_data.x_values:
mbligh12eebfa2008-01-03 02:01:53 +0000154 try:
mbligh2ba3e732008-01-16 01:30:19 +0000155 box_data = test_data.data[x][y].status_count
mbligh12eebfa2008-01-03 02:01:53 +0000156 except:
157 cur_row.append(display.box(None, None))
158 continue
mbligh2ba3e732008-01-16 01:30:19 +0000159 job_tag = test_data.data[x][y].job_tag
mbligh5dd503b2008-01-03 16:35:27 +0000160 if job_tag:
161 link = '/results/%s/' % job_tag
162 else:
mbligh2ba3e732008-01-16 01:30:19 +0000163 link = construct_link(x, y)
mbligh12eebfa2008-01-03 02:01:53 +0000164 cur_row.append(display.status_precounted_box(db,
mbligh5dd503b2008-01-03 16:35:27 +0000165 box_data,
166 link))
mbligh12eebfa2008-01-03 02:01:53 +0000167 matrix.append(cur_row)
mbligh2e4e5df2007-11-05 17:22:46 +0000168
mbligh12eebfa2008-01-03 02:01:53 +0000169 return matrix
mbligh2b672532007-11-05 19:24:51 +0000170
mbligh2b672532007-11-05 19:24:51 +0000171
mbligh12eebfa2008-01-03 02:01:53 +0000172def main():
mbligh190a81d2007-11-05 20:40:38 +0000173 # create the actual page
mbligh190a81d2007-11-05 20:40:38 +0000174 print '<html><head><title>'
175 print 'Filtered Autotest Results'
176 print '</title></head><body>'
mbligh14671622008-01-11 16:49:54 +0000177 display.print_main_header()
mbligh2ba3e732008-01-16 01:30:19 +0000178 print html_header % (create_select_options(column),
179 create_select_options(row),
mbligh12eebfa2008-01-03 02:01:53 +0000180 condition_field)
181 display.print_table(gen_matrix())
mbligh190a81d2007-11-05 20:40:38 +0000182 print '</body></html>'
mbligh2e4e5df2007-11-05 17:22:46 +0000183
184
185main()