blob: f2e9749ea07f74b13863cea97b25df41af37224d [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
mbligh2e4e5df2007-11-05 17:22:46 +000013
14tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
15sys.path.insert(0, tko)
16
mbligh2b672532007-11-05 19:24:51 +000017import display, frontend, db, query_lib
mbligh2e4e5df2007-11-05 17:22:46 +000018
mbligh190a81d2007-11-05 20:40:38 +000019html_header = """\
20<form action="compose_query.cgi" method="get">
21<table border="0">
22<tr>
23 <td>Column: </td>
24 <td>Row: </td>
25 <td>Condition: </td>
26 <td align="center"><a href="index.html">Help</a></td>
27</tr>
28<tr>
29 <td>
30 <SELECT NAME="columns">
31 %s
32 </SELECT>
33 </td>
34 <td>
35 <SELECT NAME="rows">
36 %s
37 </SELECT>
38 </td>
39 <td>
40 <input type="text" name="condition" size="80" maxlength="80" value="%s">
41 <input type="hidden" name="title" value="Report">
42 </td>
43 <td align="center"><input type="submit" value="Submit">
44 </td>
45</tr>
46</table>
47</form>
48"""
49
50columns_default = 'kernel'
51rows_default = 'test'
52
mbligh2e4e5df2007-11-05 17:22:46 +000053cgitb.enable()
54db = db.db()
55
mbligh190a81d2007-11-05 20:40:38 +000056def create_select_options(selected_val, default_val):
57 ret = ""
58 option_list = ['kernel', 'hostname', 'test', 'label',
59 'machine_group', 'reason']
60
61 if option_list.count(selected_val) == 0:
62 selected_val = default_val
63 assert(option_list.count(selected_val) > 0)
64
65 for option in option_list:
66 if selected_val == option:
67 selected = " SELECTED"
68 else:
69 selected = ""
70
71 ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % (option,
72 selected,
73 option)
74
75 return ret
76
77
mbligh2e4e5df2007-11-05 17:22:46 +000078def main():
mbligh1405f4e2007-11-05 19:26:23 +000079 display.print_main_header()
mbligh2e4e5df2007-11-05 17:22:46 +000080
81 # parse the fields from the form.
82 form = cgi.FieldStorage()
mbligh190a81d2007-11-05 20:40:38 +000083 columns = columns_default
84 rows = rows_default
mbligh2e4e5df2007-11-05 17:22:46 +000085 condition = None
86 for field in form:
87 value = form[field].value
88 if field == 'columns':
89 columns = value
90 elif field == 'rows':
91 rows = value
92 elif field == 'condition':
93 condition = value
94
95 # parse the conditions into sql query and value list.
96 condition_sql = ""
97 condition_value = []
98 if condition:
mbligh2b672532007-11-05 19:24:51 +000099 condition_list = query_lib.parse_condition(condition)
100 condition_sql, condition_value = \
101 query_lib.generate_sql_condition(condition_list)
mbligh2e4e5df2007-11-05 17:22:46 +0000102
103 # get all possible column values.
104 column_groups = frontend.anygroup.selectunique(db, columns)
105
106 # get all possible row values.
107 row_groups = frontend.anygroup.selectunique(db,rows)
108 # keep only those values in rows/columns that have a test
109 # corresponding to it.
mbligh2b672532007-11-05 19:24:51 +0000110 row_groups = query_lib.prune_list(row_groups, condition_sql, \
111 condition_value)
112 column_groups = query_lib.prune_list(column_groups, condition_sql, \
113 condition_value)
mbligh2e4e5df2007-11-05 17:22:46 +0000114
115 # prepare the header for the table.
116 headers = [g.name for g in column_groups]
117
118 header_row = [display.box(x, header=True) for x in headers]
119 header_row.insert(0, display.box("", header=True))
120
121 matrix = [header_row]
122
mbligh2b672532007-11-05 19:24:51 +0000123 # get all the tests that satify the given condition.
124 tests = query_lib.get_tests(condition_sql, condition_value)
125
mbligh2e4e5df2007-11-05 17:22:46 +0000126 for r_group in row_groups:
127 row = [display.box(r_group.name)]
mbligh2b672532007-11-05 19:24:51 +0000128
129 # build the row sql for this row.
130 row_expr = [ " %s = %%s " % r_group.idx_name for val in r_group.idx_value]
131 row_sql = " (%s) " % " or ".join(row_expr)
132
mbligh2e4e5df2007-11-05 17:22:46 +0000133 # get individual unit values
134 for c_group in column_groups:
mbligh2b672532007-11-05 19:24:51 +0000135 # get the list of tests that belong to this x,y in the matrix.
136 xy_test = [test for test in tests
137 if query_lib.get_value(test, r_group.idx_name) \
138 in r_group.idx_value \
139 and query_lib.get_value(test,c_group.idx_name) \
140 in c_group.idx_value]
141
142 # build the column sql
143 column_expr = [ " %s = %%s " % c_group.idx_name for val in c_group.idx_value]
144 column_sql = " (%s) " % " or ".join(column_expr)
145
146 sql = "t where %s and %s " % (row_sql, column_sql)
147
148 # add the corresponding values of the fields to
149 # the value list.
150
151 value = []
152 value.extend(r_group.idx_value)
153 value.extend(c_group.idx_value)
154
155 # append the condition sql and the values to the
156 # sql/list respectively.
157 if condition_sql:
158 sql += " and "
159 sql += condition_sql
160 value.extend(condition_value)
161
mbligh2e4e5df2007-11-05 17:22:46 +0000162 value_str = [str(val) for val in value]
163 link = 'test.cgi?sql=%s&values=%s' % \
164 (sql, ','.join(value_str))
mbligh2b672532007-11-05 19:24:51 +0000165 row.append(display.status_count_box(db, xy_test, link))
mbligh2e4e5df2007-11-05 17:22:46 +0000166 matrix.append(row)
mbligh190a81d2007-11-05 20:40:38 +0000167
168 # create the actual page
169 condition_str = condition
170 if condition_str == None:
171 condition_str = ""
172 print '<html><head><title>'
173 print 'Filtered Autotest Results'
174 print '</title></head><body>'
175 print html_header % (create_select_options(columns, columns_default),
176 create_select_options(rows, rows_default),
177 condition_str)
mbligh2e4e5df2007-11-05 17:22:46 +0000178 display.print_table(matrix)
mbligh190a81d2007-11-05 20:40:38 +0000179 print '</body></html>'
mbligh2e4e5df2007-11-05 17:22:46 +0000180
181
182main()