blob: 012c383ed6cca6d40cd9ad2102f31b2646e52a99 [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
mbligh2e4e5df2007-11-05 17:22:46 +00009print "Content-type: text/html\n"
mbligh44710b62008-03-07 00:25:43 +000010import cgi, cgitb, re, datetime, query_lib
mbligha4266932007-11-05 18:12:16 +000011import sys, os
mblighb180f6c2008-01-04 20:24:41 +000012import urllib
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
mbligh12eebfa2008-01-03 02:01:53 +000018client_bin = os.path.abspath(os.path.join(tko, '../client/bin'))
19sys.path.insert(0, client_bin)
20import kernel_versions
21
mbligh190a81d2007-11-05 20:40:38 +000022html_header = """\
23<form action="compose_query.cgi" method="get">
24<table border="0">
25<tr>
26 <td>Column: </td>
27 <td>Row: </td>
28 <td>Condition: </td>
mbligh44710b62008-03-07 00:25:43 +000029 <td align="center">
30 <a href="http://test.kernel.org/autotest/AutotestTKOCondition">Help</a>
31 </td>
mbligh190a81d2007-11-05 20:40:38 +000032</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>
mbligh44710b62008-03-07 00:25:43 +000045 <input type="text" name="condition" size="30" 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 = {
mbligh44710b62008-03-07 00:25:43 +000057 'machine_group': 'hostname',
58 'hostname': 'tag',
59 'tag': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000060
mbligh44710b62008-03-07 00:25:43 +000061 'kernel': 'test',
62 'test': 'label',
63 'label': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000064
mbligh44710b62008-03-07 00:25:43 +000065 'reason': 'tag',
66 'user': 'tag',
67 'status': 'tag',
68
69 'time_daily': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000070}
71
72
mbligh3d7a5f52008-04-16 23:06:36 +000073def parse_field(form, form_field):
mbligh12eebfa2008-01-03 02:01:53 +000074 field_input = form[form_field].value.lower()
mbligh2ba3e732008-01-16 01:30:19 +000075 if field_input and field_input in frontend.test_view_field_dict:
mbligh12eebfa2008-01-03 02:01:53 +000076 return field_input
mbligh3d7a5f52008-04-16 23:06:36 +000077 return ''
mbligh12eebfa2008-01-03 02:01:53 +000078
79
80def parse_condition(form, form_field, field_default):
81 if not form_field in form:
82 return field_default
83 return form[form_field].value
84
85
86form = cgi.FieldStorage()
mbligh3d7a5f52008-04-16 23:06:36 +000087
88try:
89 row = parse_field(form, 'rows')
90 column = parse_field(form, 'columns')
91 condition_field = parse_condition(form, 'condition','')
92except KeyError:
93 ## first time here
94 ## to start faster, begin with records of last week only
95 cut_off = datetime.datetime.now() - datetime.timedelta(7)
96 cut_off = datetime.date(cut_off.year, cut_off.month, cut_off.day)
97 condition_field = parse_condition(form, 'condition',
98 "time > '%s'" % str(cut_off))
99 row = 'kernel'
100 column = 'machine_group'
101
mbligh44710b62008-03-07 00:25:43 +0000102
mbligh439661b2008-02-19 15:57:53 +0000103## caller can specify rows and columns that shall be included into the report
104## regardless of whether actual test data is available yet
105force_row_field = parse_condition(form,'force_row','')
106force_column_field = parse_condition(form,'force_column','')
mbligh190a81d2007-11-05 20:40:38 +0000107
mbligh439661b2008-02-19 15:57:53 +0000108def split_forced_fields(force_field):
109 if force_field:
110 return force_field.split()
111 else:
112 return []
113
114force_row = split_forced_fields(force_row_field)
115force_column = split_forced_fields(force_column_field)
116
mbligh2e4e5df2007-11-05 17:22:46 +0000117cgitb.enable()
mblighaea09602008-04-16 22:59:37 +0000118db_obj = db.db()
mbligh2e4e5df2007-11-05 17:22:46 +0000119
mbligh12eebfa2008-01-03 02:01:53 +0000120
mbligh2ba3e732008-01-16 01:30:19 +0000121def construct_link(x, y):
122 next_row = row
123 next_column = column
mbligh5dd503b2008-01-03 16:35:27 +0000124 condition_list = []
125 if condition_field != '':
126 condition_list.append(condition_field)
mbligh2ba3e732008-01-16 01:30:19 +0000127 if y:
128 next_row = next_field[row]
129 condition_list.append("%s='%s'" % (row, y))
130 if x:
131 next_column = next_field[column]
132 condition_list.append("%s='%s'" % (column, x))
mblighb180f6c2008-01-04 20:24:41 +0000133 next_condition = '&'.join(condition_list)
134 return 'compose_query.cgi?' + urllib.urlencode({'columns': next_column,
135 'rows': next_row, 'condition': next_condition})
mbligh5dd503b2008-01-03 16:35:27 +0000136
137
mbligh12eebfa2008-01-03 02:01:53 +0000138def create_select_options(selected_val):
mbligh190a81d2007-11-05 20:40:38 +0000139 ret = ""
mbligh2ba3e732008-01-16 01:30:19 +0000140 for option in sorted(frontend.test_view_field_dict.keys()):
mbligh44710b62008-03-07 00:25:43 +0000141 ## exceptional handling of id and time :(
142 ## To do: when we have more then two such prohibitions,
143 ## something better should be implemented
144 ## e.g. let frontend.test_view_field_dict
145 ## have tuples as a values: (next_field,bAllowGrouping)
146 if option == "id":
147 ## do not allow to group by id
148 ## because it may result in jumbo data transacted
149 continue
150 if option == "time":
151 ## we have time_daily and time_weekly
152 ## in both drop down menus
153 ## They are two different clones of "time"
154 ## just 'time' should be avoided due to big
155 ## data transfer
156 continue
mbligh190a81d2007-11-05 20:40:38 +0000157 if selected_val == option:
158 selected = " SELECTED"
159 else:
160 selected = ""
161
mbligh2ba3e732008-01-16 01:30:19 +0000162 ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \
163 (option, selected, option)
mbligh190a81d2007-11-05 20:40:38 +0000164 return ret
165
166
apw7a7316b2008-02-21 17:42:05 +0000167def map_kernel_base(kernel_name):
mbligh439661b2008-02-19 15:57:53 +0000168 ## insert <br> after each / in kernel name
169 ## but spare consequtive //
mbligh8e7c78e2008-02-20 21:18:49 +0000170 kernel_name = kernel_name.replace('/','/<br>')
171 kernel_name = kernel_name.replace('/<br>/<br>','//')
mbligh439661b2008-02-19 15:57:53 +0000172 return kernel_name
173
174
mbligh44710b62008-03-07 00:25:43 +0000175def header_tuneup(field_name, header):
176 ## header tune up depends on particular field name and may include:
177 ## - breaking header into several strings if it is long url
178 ## - creating date from datetime stamp
179 ## - possibly, expect more various refinements for different fields
180 if field_name == 'kernel':
181 return map_kernel_base(header)
182 elif field_name.startswith('time') and header != None:
183 return datetime.date(header.year, header.month, header.day)
184 else:
185 return header
186
187
apw7a7316b2008-02-21 17:42:05 +0000188# Kernel name mappings -- the kernels table 'printable' field is
189# effectively a sortable identifier for the kernel It encodes the base
190# release which is used for overall sorting, plus where patches are
191# applied it adds an increasing pNNN patch combination identifier
192# (actually the kernel_idx for the entry). This allows sorting
193# as normal by the base kernel version and then sub-sorting by the
194# "first time we saw" a patch combination which should keep them in
195# approximatly date order. This patch identifier is not suitable
196# for display, so we have to map it to a suitable html fragment for
197# display. This contains the kernel base version plus the truncated
198# names of all the patches,
199#
200# 2.6.24-mm1 p112
201# +add-new-string-functions-
202# +x86-amd-thermal-interrupt
203#
204# This mapping is produced when the first mapping is request, with
205# a single query over the patches table; the result is then cached.
206#
207# Note: that we only count a base version as patched if it contains
208# patches which are not already "expressed" in the base version.
209# This includes both -gitN and -mmN kernels.
210map_kernel_map = None
211
212
213def map_kernel_init():
214 fields = ['base', 'k.kernel_idx', 'name', 'url']
215 map = {}
mblighaea09602008-04-16 22:59:37 +0000216 for (base, idx, name, url) in db_obj.select(','.join(fields),
apw7a7316b2008-02-21 17:42:05 +0000217 'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'):
218 match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url)
219 if match:
220 continue
221
222 key = base + ' p%d' % (idx)
223 if not map.has_key(key):
224 map[key] = map_kernel_base(base) + ' p%d' % (idx)
225 map[key] += '<br>+<span title="' + name + '">' + name[0:25] + '</span>'
226
227 return map
228
229
230def map_kernel(name):
231 global map_kernel_map
232 if map_kernel_map == None:
233 map_kernel_map = map_kernel_init()
234
235 if map_kernel_map.has_key(name):
236 return map_kernel_map[name]
237
238 return map_kernel_base(name.split(' ')[0])
239
240
241field_map = {
242 'kernel':map_kernel
243}
244
245
mbligh12eebfa2008-01-03 02:01:53 +0000246def gen_matrix():
mbligh12eebfa2008-01-03 02:01:53 +0000247 where = None
248 if condition_field.strip() != '':
mbligh44710b62008-03-07 00:25:43 +0000249 try:
250 where = query_lib.parse_scrub_and_gen_condition(
251 condition_field, frontend.test_view_field_dict)
252 print "<!-- where clause: %s -->" % (where,)
253 except:
254 msg = "Unspecified error when parsing condition"
255 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000256
mblighaea09602008-04-16 22:59:37 +0000257 try:
258 test_data = frontend.get_matrix_data(db_obj, column, row, where)
259 except db.MySQLTooManyRows, error:
260 return [[display.box(str(error))]]
mbligh44710b62008-03-07 00:25:43 +0000261
mbligh439661b2008-02-19 15:57:53 +0000262 for f_row in force_row:
263 if not f_row in test_data.y_values:
264 test_data.y_values.append(f_row)
265 for f_column in force_column:
266 if not f_column in test_data.x_values:
267 test_data.x_values.append(f_column)
mbligh2e4e5df2007-11-05 17:22:46 +0000268
mbligh2ba3e732008-01-16 01:30:19 +0000269 if not test_data.y_values:
mbligh12eebfa2008-01-03 02:01:53 +0000270 msg = "There are no results for this query (yet?)."
271 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000272
mbligh456b4772008-03-25 23:54:45 +0000273 dict_url = {'columns': row,
274 'rows': column, 'condition': condition_field}
275 link = 'compose_query.cgi?' + urllib.urlencode(dict_url)
mbligh5dd503b2008-01-03 16:35:27 +0000276 header_row = [display.box("<center>(Flip Axis)</center>", link=link)]
277
mbligh2ba3e732008-01-16 01:30:19 +0000278 for x in test_data.x_values:
apw7a7316b2008-02-21 17:42:05 +0000279 dx = x
280 if field_map.has_key(column):
281 dx = field_map[column](x)
mbligh44710b62008-03-07 00:25:43 +0000282 x_header = header_tuneup(column, dx)
283 link = construct_link(x, None)
284 header_row.append(display.box(x_header,header=True,link=link))
mbligh2e4e5df2007-11-05 17:22:46 +0000285
286 matrix = [header_row]
mbligh2ba3e732008-01-16 01:30:19 +0000287 for y in test_data.y_values:
apw7a7316b2008-02-21 17:42:05 +0000288 dy = y
289 if field_map.has_key(row):
290 dy = field_map[row](y)
mbligh44710b62008-03-07 00:25:43 +0000291 y_header = header_tuneup(row, dy)
292 link = construct_link(None, y)
293 cur_row = [display.box(y_header, header=True, link=link)]
mbligh2ba3e732008-01-16 01:30:19 +0000294 for x in test_data.x_values:
mbligh44710b62008-03-07 00:25:43 +0000295 ## next 2 lines: temporary, until non timestamped
296 ## records are in the database
297 if x==datetime.datetime(1970,1,1): x = None
298 if y==datetime.datetime(1970,1,1): y = None
mbligh12eebfa2008-01-03 02:01:53 +0000299 try:
mbligh2ba3e732008-01-16 01:30:19 +0000300 box_data = test_data.data[x][y].status_count
mbligh12eebfa2008-01-03 02:01:53 +0000301 except:
302 cur_row.append(display.box(None, None))
303 continue
mbligh2ba3e732008-01-16 01:30:19 +0000304 job_tag = test_data.data[x][y].job_tag
mbligh5dd503b2008-01-03 16:35:27 +0000305 if job_tag:
mblighe47ff2a2008-02-28 00:44:11 +0000306 link = frontend.html_root + job_tag + '/'
mbligh439661b2008-02-19 15:57:53 +0000307 if (row == 'test' and
308 not 'boot' in y and
309 not 'build' in y and
310 not 'install' in y ):
311 link += y + '/'
312 if (column == 'test' and
313 not 'boot' in x and
314 not 'build' in x and
315 not 'install' in x):
316 link += x + '/'
mbligh5dd503b2008-01-03 16:35:27 +0000317 else:
mbligh2ba3e732008-01-16 01:30:19 +0000318 link = construct_link(x, y)
mbligh44710b62008-03-07 00:25:43 +0000319
mblighaea09602008-04-16 22:59:37 +0000320 cur_row.append(display.status_precounted_box(db_obj,
mbligh5dd503b2008-01-03 16:35:27 +0000321 box_data,
322 link))
mbligh12eebfa2008-01-03 02:01:53 +0000323 matrix.append(cur_row)
mbligh12eebfa2008-01-03 02:01:53 +0000324 return matrix
mbligh2b672532007-11-05 19:24:51 +0000325
mbligh2b672532007-11-05 19:24:51 +0000326
mbligh12eebfa2008-01-03 02:01:53 +0000327def main():
mbligh190a81d2007-11-05 20:40:38 +0000328 # create the actual page
mbligh190a81d2007-11-05 20:40:38 +0000329 print '<html><head><title>'
330 print 'Filtered Autotest Results'
331 print '</title></head><body>'
mbligh14671622008-01-11 16:49:54 +0000332 display.print_main_header()
mbligh2ba3e732008-01-16 01:30:19 +0000333 print html_header % (create_select_options(column),
334 create_select_options(row),
mbligh12eebfa2008-01-03 02:01:53 +0000335 condition_field)
mbligh439661b2008-02-19 15:57:53 +0000336 print display.color_keys_row()
mbligh12eebfa2008-01-03 02:01:53 +0000337 display.print_table(gen_matrix())
mbligh439661b2008-02-19 15:57:53 +0000338 print display.color_keys_row()
mbligh190a81d2007-11-05 20:40:38 +0000339 print '</body></html>'
mbligh2e4e5df2007-11-05 17:22:46 +0000340
341
342main()