OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Main functions for the Layout Test Analyzer module.""" | 6 """Main functions for the Layout Test Analyzer module.""" |
7 | 7 |
8 import csv | 8 import csv |
9 from datetime import datetime | 9 from datetime import datetime |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 import time | 13 import time |
14 | 14 |
15 import layouttests | 15 import layouttests |
16 import layouttest_analyzer_helpers | 16 import layouttest_analyzer_helpers |
17 from test_expectations import TestExpectations | 17 from test_expectations import TestExpectations |
18 from trend_graph import TrendGraph | 18 from trend_graph import TrendGraph |
19 | 19 |
20 # Predefined result directory. | 20 # Predefined result directory. |
21 DEFAULT_RESULT_DIR = 'result' | 21 DEFAULT_RESULT_DIR = 'result' |
22 DEFAULT_ANNO_FILE = os.path.join('anno', 'anno.csv') | 22 DEFAULT_ANNO_FILE = os.path.join('anno', 'anno.csv') |
23 DEFAULT_GRAPH_FILE = os.path.join('graph', 'graph.html') | 23 DEFAULT_GRAPH_FILE = os.path.join('graph', 'graph.html') |
| 24 DEFAULT_STATS_CSV_FILENAME = 'stats.csv' |
| 25 DEFAULT_ISSUES_CSV_FILENAME = 'issues.csv' |
24 # Predefined result files for debug. | 26 # Predefined result files for debug. |
25 CUR_TIME_FOR_DEBUG = '2011-09-11-19' | 27 CUR_TIME_FOR_DEBUG = '2011-09-11-19' |
26 CURRENT_RESULT_FILE_FOR_DEBUG = os.path.join(DEFAULT_RESULT_DIR, | 28 CURRENT_RESULT_FILE_FOR_DEBUG = os.path.join(DEFAULT_RESULT_DIR, |
27 CUR_TIME_FOR_DEBUG) | 29 CUR_TIME_FOR_DEBUG) |
28 PREV_TIME_FOR_DEBUG = '2011-09-11-18' | 30 PREV_TIME_FOR_DEBUG = '2011-09-11-18' |
29 | 31 |
30 | 32 |
31 def ParseOption(): | 33 def ParseOption(): |
32 """Parse command-line options using OptionParser. | 34 """Parse command-line options using OptionParser. |
33 | 35 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 """ | 191 """ |
190 anno_map = {} | 192 anno_map = {} |
191 try: | 193 try: |
192 file_object = open(bug_annotation_file_location) | 194 file_object = open(bug_annotation_file_location) |
193 except IOError: | 195 except IOError: |
194 print 'cannot open annotation file %s. Skipping.' % ( | 196 print 'cannot open annotation file %s. Skipping.' % ( |
195 bug_annotation_file_location) | 197 bug_annotation_file_location) |
196 else: | 198 else: |
197 data = csv.reader(file_object) | 199 data = csv.reader(file_object) |
198 for row in data: | 200 for row in data: |
199 anno_map[row[0]] = row[1] | 201 if len(row) > 1: |
| 202 anno_map[row[0]] = row[1] |
200 file_object.close() | 203 file_object.close() |
201 | 204 |
202 appended_text_to_email = '' | 205 appended_text_to_email = '' |
203 if email_appended_text_file_location: | 206 if email_appended_text_file_location: |
204 try: | 207 try: |
205 file_object = open(email_appended_text_file_location) | 208 file_object = open(email_appended_text_file_location) |
206 except IOError: | 209 except IOError: |
207 print 'cannot open email appended text file %s. Skipping.' % ( | 210 print 'cannot open email appended text file %s. Skipping.' % ( |
208 email_appended_text_file_location) | 211 email_appended_text_file_location) |
209 else: | 212 else: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 (rev_str, simple_rev_str, rev, rev_date) = ( | 269 (rev_str, simple_rev_str, rev, rev_date) = ( |
267 layouttest_analyzer_helpers.GetRevisionString(prev_time_in_float, | 270 layouttest_analyzer_helpers.GetRevisionString(prev_time_in_float, |
268 cur_time_in_float, | 271 cur_time_in_float, |
269 diff_map)) | 272 diff_map)) |
270 email_content = analyzer_result_map.ConvertToString(prev_time, diff_map, | 273 email_content = analyzer_result_map.ConvertToString(prev_time, diff_map, |
271 anno_map) | 274 anno_map) |
272 if receiver_email_address: | 275 if receiver_email_address: |
273 layouttest_analyzer_helpers.SendStatusEmail( | 276 layouttest_analyzer_helpers.SendStatusEmail( |
274 prev_time, analyzer_result_map, diff_map, anno_map, | 277 prev_time, analyzer_result_map, diff_map, anno_map, |
275 receiver_email_address, test_group_name, | 278 receiver_email_address, test_group_name, |
276 appended_text_to_email, email_content, rev_str) | 279 appended_text_to_email, email_content, rev_str, |
| 280 email_only_change_mode) |
277 if simple_rev_str: | 281 if simple_rev_str: |
278 simple_rev_str = '\'' + simple_rev_str + '\'' | 282 simple_rev_str = '\'' + simple_rev_str + '\'' |
279 else: | 283 else: |
280 simple_rev_str = 'undefined' # GViz uses undefined for NONE. | 284 simple_rev_str = 'undefined' # GViz uses undefined for NONE. |
281 else: | 285 else: |
282 # Initial result should be written to tread-graph if there are no previous | 286 # Initial result should be written to tread-graph if there are no previous |
283 # results. | 287 # results. |
284 result_change = True | 288 result_change = True |
285 diff_map = None | 289 diff_map = None |
286 simple_rev_str = 'undefined' | 290 simple_rev_str = 'undefined' |
| 291 email_content = analyzer_result_map.ConvertToString(None, diff_map, |
| 292 anno_map) |
287 return (result_change, diff_map, simple_rev_str, rev, rev_date, | 293 return (result_change, diff_map, simple_rev_str, rev, rev_date, |
288 email_content) | 294 email_content) |
289 | 295 |
290 | 296 |
291 def UpdateTrendGraph(start_time, analyzer_result_map, diff_map, simple_rev_str, | 297 def UpdateTrendGraph(start_time, analyzer_result_map, diff_map, simple_rev_str, |
292 trend_graph_location): | 298 trend_graph_location): |
293 """Update trend graph in GViz. | 299 """Update trend graph in GViz. |
294 | 300 |
295 Annotate the graph with revision information. | 301 Annotate the graph with revision information. |
296 | 302 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 options.test_group_name, | 453 options.test_group_name, |
448 options.result_directory_location)) | 454 options.result_directory_location)) |
449 (anno_map, appended_text_to_email) = ReadEmailInformation( | 455 (anno_map, appended_text_to_email) = ReadEmailInformation( |
450 options.bug_annotation_file_location, | 456 options.bug_annotation_file_location, |
451 options.email_appended_text_file_location) | 457 options.email_appended_text_file_location) |
452 (result_change, diff_map, simple_rev_str, rev, rev_date, email_content) = ( | 458 (result_change, diff_map, simple_rev_str, rev, rev_date, email_content) = ( |
453 SendEmail(prev_time, prev_analyzer_result_map, analyzer_result_map, | 459 SendEmail(prev_time, prev_analyzer_result_map, analyzer_result_map, |
454 anno_map, appended_text_to_email, | 460 anno_map, appended_text_to_email, |
455 options.email_only_change_mode, options.debug, | 461 options.email_only_change_mode, options.debug, |
456 options.receiver_email_address, options.test_group_name)) | 462 options.receiver_email_address, options.test_group_name)) |
| 463 |
| 464 # Create CSV texts and save them for bug spreadsheet. |
| 465 (stats, issues_txt) = analyzer_result_map.ConvertToCSVText( |
| 466 start_time.strftime('%Y-%m-%d-%H')) |
| 467 file_object = open(os.path.join(options.result_directory_location, |
| 468 DEFAULT_STATS_CSV_FILENAME), 'wb') |
| 469 file_object.write(stats) |
| 470 file_object.close() |
| 471 file_object = open(os.path.join(options.result_directory_location, |
| 472 DEFAULT_ISSUES_CSV_FILENAME), 'wb') |
| 473 file_object.write(issues_txt) |
| 474 file_object.close() |
| 475 |
457 if not options.debug and (result_change or not prev_analyzer_result_map): | 476 if not options.debug and (result_change or not prev_analyzer_result_map): |
458 # Save the current result when result is changed or the script is | 477 # Save the current result when result is changed or the script is |
459 # executed for the first time. | 478 # executed for the first time. |
460 date = start_time.strftime('%Y-%m-%d-%H') | 479 date = start_time.strftime('%Y-%m-%d-%H') |
461 file_path = os.path.join(options.result_directory_location, date) | 480 file_path = os.path.join(options.result_directory_location, date) |
462 analyzer_result_map.Save(file_path) | 481 analyzer_result_map.Save(file_path) |
463 if result_change or not prev_analyzer_result_map: | 482 if result_change or not prev_analyzer_result_map: |
464 data_map = UpdateTrendGraph(start_time, analyzer_result_map, diff_map, | 483 data_map = UpdateTrendGraph(start_time, analyzer_result_map, diff_map, |
465 simple_rev_str, options.trend_graph_location) | 484 simple_rev_str, options.trend_graph_location) |
466 # Report the result to dashboard. | 485 # Report the result to dashboard. |
467 if options.dashboard_file_location: | 486 if options.dashboard_file_location: |
468 UpdateDashboard(options.dashboard_file_location, options.test_group_name, | 487 UpdateDashboard(options.dashboard_file_location, options.test_group_name, |
469 data_map, layouttests.DEFAULT_LAYOUTTEST_LOCATION, rev, | 488 data_map, layouttests.DEFAULT_LAYOUTTEST_LOCATION, rev, |
470 rev_date, options.receiver_email_address, | 489 rev_date, options.receiver_email_address, |
471 email_content) | 490 email_content) |
472 | 491 |
473 | 492 |
474 if '__main__' == __name__: | 493 if '__main__' == __name__: |
475 main() | 494 main() |
OLD | NEW |