mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | Selects all rows and columns that satisfy the condition specified |
| 5 | and draws the matrix. There is a seperate SQL query made for every (x,y) |
| 6 | in the matrix. |
| 7 | """ |
| 8 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 9 | print "Content-type: text/html\n" |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 10 | import cgi, cgitb, re, datetime, query_lib |
mbligh | a426693 | 2007-11-05 18:12:16 +0000 | [diff] [blame] | 11 | import sys, os |
mbligh | b180f6c | 2008-01-04 20:24:41 +0000 | [diff] [blame] | 12 | import urllib |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 13 | |
| 14 | tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) |
| 15 | sys.path.insert(0, tko) |
| 16 | |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 17 | import display, frontend, db, query_lib |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 18 | client_bin = os.path.abspath(os.path.join(tko, '../client/bin')) |
| 19 | sys.path.insert(0, client_bin) |
| 20 | import kernel_versions |
| 21 | |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 22 | html_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> |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 29 | <td align="center"> |
| 30 | <a href="http://test.kernel.org/autotest/AutotestTKOCondition">Help</a> |
| 31 | </td> |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 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> |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 45 | <input type="text" name="condition" size="30" value="%s"> |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 46 | <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 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 55 | |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 56 | next_field = { |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 57 | 'machine_group': 'hostname', |
| 58 | 'hostname': 'tag', |
| 59 | 'tag': 'tag', |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 60 | |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 61 | 'kernel': 'test', |
| 62 | 'test': 'label', |
| 63 | 'label': 'tag', |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 64 | |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 65 | 'reason': 'tag', |
| 66 | 'user': 'tag', |
| 67 | 'status': 'tag', |
| 68 | |
| 69 | 'time_daily': 'tag', |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 73 | def parse_field(form, form_field, field_default): |
| 74 | if not form_field in form: |
| 75 | return field_default |
| 76 | field_input = form[form_field].value.lower() |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 77 | if field_input and field_input in frontend.test_view_field_dict: |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 78 | return field_input |
| 79 | return field_default |
| 80 | |
| 81 | |
| 82 | def parse_condition(form, form_field, field_default): |
| 83 | if not form_field in form: |
| 84 | return field_default |
| 85 | return form[form_field].value |
| 86 | |
| 87 | |
| 88 | form = cgi.FieldStorage() |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 89 | row = parse_field(form, 'rows', 'kernel') |
| 90 | column = parse_field(form, 'columns', 'machine_group') |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 91 | condition_field = parse_condition(form, 'condition', '') |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 92 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 93 | ## caller can specify rows and columns that shall be included into the report |
| 94 | ## regardless of whether actual test data is available yet |
| 95 | force_row_field = parse_condition(form,'force_row','') |
| 96 | force_column_field = parse_condition(form,'force_column','') |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 97 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 98 | def split_forced_fields(force_field): |
| 99 | if force_field: |
| 100 | return force_field.split() |
| 101 | else: |
| 102 | return [] |
| 103 | |
| 104 | force_row = split_forced_fields(force_row_field) |
| 105 | force_column = split_forced_fields(force_column_field) |
| 106 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 107 | cgitb.enable() |
mbligh | aea0960 | 2008-04-16 22:59:37 +0000 | [diff] [blame^] | 108 | db_obj = db.db() |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 109 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 110 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 111 | def construct_link(x, y): |
| 112 | next_row = row |
| 113 | next_column = column |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 114 | condition_list = [] |
| 115 | if condition_field != '': |
| 116 | condition_list.append(condition_field) |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 117 | if y: |
| 118 | next_row = next_field[row] |
| 119 | condition_list.append("%s='%s'" % (row, y)) |
| 120 | if x: |
| 121 | next_column = next_field[column] |
| 122 | condition_list.append("%s='%s'" % (column, x)) |
mbligh | b180f6c | 2008-01-04 20:24:41 +0000 | [diff] [blame] | 123 | next_condition = '&'.join(condition_list) |
| 124 | return 'compose_query.cgi?' + urllib.urlencode({'columns': next_column, |
| 125 | 'rows': next_row, 'condition': next_condition}) |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 126 | |
| 127 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 128 | def create_select_options(selected_val): |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 129 | ret = "" |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 130 | for option in sorted(frontend.test_view_field_dict.keys()): |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 131 | ## exceptional handling of id and time :( |
| 132 | ## To do: when we have more then two such prohibitions, |
| 133 | ## something better should be implemented |
| 134 | ## e.g. let frontend.test_view_field_dict |
| 135 | ## have tuples as a values: (next_field,bAllowGrouping) |
| 136 | if option == "id": |
| 137 | ## do not allow to group by id |
| 138 | ## because it may result in jumbo data transacted |
| 139 | continue |
| 140 | if option == "time": |
| 141 | ## we have time_daily and time_weekly |
| 142 | ## in both drop down menus |
| 143 | ## They are two different clones of "time" |
| 144 | ## just 'time' should be avoided due to big |
| 145 | ## data transfer |
| 146 | continue |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 147 | if selected_val == option: |
| 148 | selected = " SELECTED" |
| 149 | else: |
| 150 | selected = "" |
| 151 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 152 | ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \ |
| 153 | (option, selected, option) |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 154 | return ret |
| 155 | |
| 156 | |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 157 | def map_kernel_base(kernel_name): |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 158 | ## insert <br> after each / in kernel name |
| 159 | ## but spare consequtive // |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 160 | kernel_name = kernel_name.replace('/','/<br>') |
| 161 | kernel_name = kernel_name.replace('/<br>/<br>','//') |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 162 | return kernel_name |
| 163 | |
| 164 | |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 165 | def header_tuneup(field_name, header): |
| 166 | ## header tune up depends on particular field name and may include: |
| 167 | ## - breaking header into several strings if it is long url |
| 168 | ## - creating date from datetime stamp |
| 169 | ## - possibly, expect more various refinements for different fields |
| 170 | if field_name == 'kernel': |
| 171 | return map_kernel_base(header) |
| 172 | elif field_name.startswith('time') and header != None: |
| 173 | return datetime.date(header.year, header.month, header.day) |
| 174 | else: |
| 175 | return header |
| 176 | |
| 177 | |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 178 | # Kernel name mappings -- the kernels table 'printable' field is |
| 179 | # effectively a sortable identifier for the kernel It encodes the base |
| 180 | # release which is used for overall sorting, plus where patches are |
| 181 | # applied it adds an increasing pNNN patch combination identifier |
| 182 | # (actually the kernel_idx for the entry). This allows sorting |
| 183 | # as normal by the base kernel version and then sub-sorting by the |
| 184 | # "first time we saw" a patch combination which should keep them in |
| 185 | # approximatly date order. This patch identifier is not suitable |
| 186 | # for display, so we have to map it to a suitable html fragment for |
| 187 | # display. This contains the kernel base version plus the truncated |
| 188 | # names of all the patches, |
| 189 | # |
| 190 | # 2.6.24-mm1 p112 |
| 191 | # +add-new-string-functions- |
| 192 | # +x86-amd-thermal-interrupt |
| 193 | # |
| 194 | # This mapping is produced when the first mapping is request, with |
| 195 | # a single query over the patches table; the result is then cached. |
| 196 | # |
| 197 | # Note: that we only count a base version as patched if it contains |
| 198 | # patches which are not already "expressed" in the base version. |
| 199 | # This includes both -gitN and -mmN kernels. |
| 200 | map_kernel_map = None |
| 201 | |
| 202 | |
| 203 | def map_kernel_init(): |
| 204 | fields = ['base', 'k.kernel_idx', 'name', 'url'] |
| 205 | map = {} |
mbligh | aea0960 | 2008-04-16 22:59:37 +0000 | [diff] [blame^] | 206 | for (base, idx, name, url) in db_obj.select(','.join(fields), |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 207 | 'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'): |
| 208 | match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url) |
| 209 | if match: |
| 210 | continue |
| 211 | |
| 212 | key = base + ' p%d' % (idx) |
| 213 | if not map.has_key(key): |
| 214 | map[key] = map_kernel_base(base) + ' p%d' % (idx) |
| 215 | map[key] += '<br>+<span title="' + name + '">' + name[0:25] + '</span>' |
| 216 | |
| 217 | return map |
| 218 | |
| 219 | |
| 220 | def map_kernel(name): |
| 221 | global map_kernel_map |
| 222 | if map_kernel_map == None: |
| 223 | map_kernel_map = map_kernel_init() |
| 224 | |
| 225 | if map_kernel_map.has_key(name): |
| 226 | return map_kernel_map[name] |
| 227 | |
| 228 | return map_kernel_base(name.split(' ')[0]) |
| 229 | |
| 230 | |
| 231 | field_map = { |
| 232 | 'kernel':map_kernel |
| 233 | } |
| 234 | |
| 235 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 236 | def gen_matrix(): |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 237 | where = None |
| 238 | if condition_field.strip() != '': |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 239 | try: |
| 240 | where = query_lib.parse_scrub_and_gen_condition( |
| 241 | condition_field, frontend.test_view_field_dict) |
| 242 | print "<!-- where clause: %s -->" % (where,) |
| 243 | except: |
| 244 | msg = "Unspecified error when parsing condition" |
| 245 | return [[display.box(msg)]] |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 246 | |
mbligh | aea0960 | 2008-04-16 22:59:37 +0000 | [diff] [blame^] | 247 | try: |
| 248 | test_data = frontend.get_matrix_data(db_obj, column, row, where) |
| 249 | except db.MySQLTooManyRows, error: |
| 250 | return [[display.box(str(error))]] |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 251 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 252 | for f_row in force_row: |
| 253 | if not f_row in test_data.y_values: |
| 254 | test_data.y_values.append(f_row) |
| 255 | for f_column in force_column: |
| 256 | if not f_column in test_data.x_values: |
| 257 | test_data.x_values.append(f_column) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 258 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 259 | if not test_data.y_values: |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 260 | msg = "There are no results for this query (yet?)." |
| 261 | return [[display.box(msg)]] |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 262 | |
mbligh | 456b477 | 2008-03-25 23:54:45 +0000 | [diff] [blame] | 263 | dict_url = {'columns': row, |
| 264 | 'rows': column, 'condition': condition_field} |
| 265 | link = 'compose_query.cgi?' + urllib.urlencode(dict_url) |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 266 | header_row = [display.box("<center>(Flip Axis)</center>", link=link)] |
| 267 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 268 | for x in test_data.x_values: |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 269 | dx = x |
| 270 | if field_map.has_key(column): |
| 271 | dx = field_map[column](x) |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 272 | x_header = header_tuneup(column, dx) |
| 273 | link = construct_link(x, None) |
| 274 | header_row.append(display.box(x_header,header=True,link=link)) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 275 | |
| 276 | matrix = [header_row] |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 277 | for y in test_data.y_values: |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 278 | dy = y |
| 279 | if field_map.has_key(row): |
| 280 | dy = field_map[row](y) |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 281 | y_header = header_tuneup(row, dy) |
| 282 | link = construct_link(None, y) |
| 283 | cur_row = [display.box(y_header, header=True, link=link)] |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 284 | for x in test_data.x_values: |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 285 | ## next 2 lines: temporary, until non timestamped |
| 286 | ## records are in the database |
| 287 | if x==datetime.datetime(1970,1,1): x = None |
| 288 | if y==datetime.datetime(1970,1,1): y = None |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 289 | try: |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 290 | box_data = test_data.data[x][y].status_count |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 291 | except: |
| 292 | cur_row.append(display.box(None, None)) |
| 293 | continue |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 294 | job_tag = test_data.data[x][y].job_tag |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 295 | if job_tag: |
mbligh | e47ff2a | 2008-02-28 00:44:11 +0000 | [diff] [blame] | 296 | link = frontend.html_root + job_tag + '/' |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 297 | if (row == 'test' and |
| 298 | not 'boot' in y and |
| 299 | not 'build' in y and |
| 300 | not 'install' in y ): |
| 301 | link += y + '/' |
| 302 | if (column == 'test' and |
| 303 | not 'boot' in x and |
| 304 | not 'build' in x and |
| 305 | not 'install' in x): |
| 306 | link += x + '/' |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 307 | else: |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 308 | link = construct_link(x, y) |
mbligh | 44710b6 | 2008-03-07 00:25:43 +0000 | [diff] [blame] | 309 | |
mbligh | aea0960 | 2008-04-16 22:59:37 +0000 | [diff] [blame^] | 310 | cur_row.append(display.status_precounted_box(db_obj, |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 311 | box_data, |
| 312 | link)) |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 313 | matrix.append(cur_row) |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 314 | return matrix |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 315 | |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 316 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 317 | def main(): |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 318 | # create the actual page |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 319 | print '<html><head><title>' |
| 320 | print 'Filtered Autotest Results' |
| 321 | print '</title></head><body>' |
mbligh | 1467162 | 2008-01-11 16:49:54 +0000 | [diff] [blame] | 322 | display.print_main_header() |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 323 | print html_header % (create_select_options(column), |
| 324 | create_select_options(row), |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 325 | condition_field) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 326 | print display.color_keys_row() |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 327 | display.print_table(gen_matrix()) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 328 | print display.color_keys_row() |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 329 | print '</body></html>' |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 330 | |
| 331 | |
| 332 | main() |