Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (C) 2013 Google Inc. All rights reserved. | 3 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 import optparse | 35 import optparse |
| 36 import sys | 36 import sys |
| 37 import urllib2 | 37 import urllib2 |
| 38 | 38 |
| 39 from webkitpy.common.host import Host | 39 from webkitpy.common.host import Host |
| 40 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser | 40 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser |
| 41 | 41 |
| 42 # FIXME: Make this a direct request to Monorail. | 42 # FIXME: Make this a direct request to Monorail. |
| 43 GOOGLE_CODE_URL = 'https://www.googleapis.com/projecthosting/v2/projects/chromiu m/issues/%s?key=AIzaSyDgCqT1Dt5AZWLHo4QJjyMHaCjhnFacGF0' | 43 GOOGLE_CODE_URL = 'https://www.googleapis.com/projecthosting/v2/projects/chromiu m/issues/%s?key=AIzaSyDgCqT1Dt5AZWLHo4QJjyMHaCjhnFacGF0' |
| 44 CRBUG_PREFIX = 'crbug.com/' | 44 CRBUG_PREFIX = 'crbug.com/' |
| 45 | 45 CSV_ROW_HEADERS = 'crbug link, test file, days since last updated, status\n' |
|
qyearsley
2016/08/19 00:37:18
This would also make sense as a list of strings:
nainar
2016/08/19 03:36:48
Done.
| |
| 46 | 46 |
| 47 class StaleTestPrinter(object): | 47 class StaleTestPrinter(object): |
| 48 | 48 |
| 49 def __init__(self, options): | 49 def __init__(self, options): |
| 50 self.days = options.days | 50 self.days = options.days |
| 51 self.csv_filename = options.create_csv | 51 self.csv_filename = options.create_csv |
| 52 self.host = Host() | 52 self.host = Host() |
| 53 self.is_stale_results = {} | 53 self.is_stale_results = {} |
| 54 self.last_updated = {} | |
| 55 self.state = {} | |
| 54 | 56 |
| 55 def print_stale_tests(self): | 57 def print_stale_tests(self): |
| 56 port = self.host.port_factory.get() | 58 port = self.host.port_factory.get() |
| 57 expectations = port.expectations_dict() | 59 expectations = port.expectations_dict() |
| 58 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) | 60 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) |
| 59 expectations_file, expectations_contents = expectations.items()[0] | 61 expectations_file, expectations_contents = expectations.items()[0] |
| 60 expectation_lines = parser.parse(expectations_file, expectations_content s) | 62 expectation_lines = parser.parse(expectations_file, expectations_content s) |
| 61 csv_rows = [] | 63 csv_rows = [] |
| 62 for line in expectation_lines: | 64 for line in expectation_lines: |
| 63 row = self.check_expectations_line(line) | 65 row = self.check_expectations_line(line) |
| 64 if row: | 66 if row: |
| 65 csv_rows.append(row) | 67 csv_rows.append(row) |
| 66 if self.csv_filename: | 68 if self.csv_filename: |
| 67 self.write_csv(csv_rows) | 69 self.write_csv(csv_rows) |
| 68 | 70 |
| 69 def write_csv(self, rows): | 71 def write_csv(self, rows): |
| 72 # TODO(nainar): Add following to CSV | |
| 73 # - Add days since last comment | |
| 74 # - Add whether or not the bug is closed | |
| 70 row_strings = [', '.join(r) for r in rows] | 75 row_strings = [', '.join(r) for r in rows] |
| 71 contents = '\n'.join(row_strings) + '\n' | 76 contents = CSV_ROW_HEADERS + '\n'.join(row_strings) + '\n' |
| 72 self.host.filesystem.write_text_file(self.csv_filename, contents) | 77 self.host.filesystem.write_text_file(self.csv_filename, contents) |
|
qyearsley
2016/08/19 00:37:18
Note: this function could also be implemented with
nainar
2016/08/19 03:36:48
Done.
| |
| 73 | 78 |
| 74 def check_expectations_line(self, line): | 79 def check_expectations_line(self, line): |
| 75 """Checks the bugs in one test expectations line to see if they're stale . | 80 """Checks the bugs in one test expectations line to see if they're stale . |
| 76 | 81 |
| 77 Args: | 82 Args: |
| 78 line: A TestExpectationsLine instance. | 83 line: A TestExpectationsLine instance. |
| 79 | 84 |
| 80 Returns: | 85 Returns: |
| 81 A CSV row (a list of strings), or None if there are no stale bugs. | 86 A CSV row (a list of strings), or None if there are no stale bugs. |
| 82 """ | 87 """ |
| 83 bug_links, test_name = line.bugs, line.name | 88 bug_links, test_name = line.bugs, line.name |
| 84 try: | 89 try: |
| 85 if bug_links and all(self.is_stale(bug_link) for bug_link in bug_lin ks): | 90 if bug_links and all(self.is_stale(bug_link) for bug_link in bug_lin ks): |
| 86 print line.original_string.strip() | 91 print line.original_string.strip() |
| 87 return [bug_links[0], test_name] | 92 return [bug_links[0], test_name, str(self.last_updated[bug_links [0]]), self.state[bug_links[0]]] |
| 88 except urllib2.HTTPError as error: | 93 except urllib2.HTTPError as error: |
| 89 if error.code == 404: | 94 if error.code == 404: |
| 90 message = 'got 404, bug does not exist.' | 95 message = 'got 404, bug does not exist.' |
| 91 elif error.code == 403: | 96 elif error.code == 403: |
| 92 message = 'got 403, not accessible. Not able to tell if it\'s st ale.' | 97 message = 'got 403, not accessible. Not able to tell if it\'s st ale.' |
| 93 else: | 98 else: |
| 94 message = str(error) | 99 message = str(error) |
| 95 print >> sys.stderr, 'Error when checking %s: %s' % (','.join(bug_li nks), message) | 100 print >> sys.stderr, 'Error when checking %s: %s' % (','.join(bug_li nks), message) |
| 96 return None | 101 return None |
| 97 | 102 |
| 98 def is_stale(self, bug_link): | 103 def is_stale(self, bug_link): |
| 99 if bug_link in self.is_stale_results: | 104 if bug_link in self.is_stale_results: |
| 100 return self.is_stale_results[bug_link] | 105 return self.is_stale_results[bug_link] |
| 101 # In case there's an error in the request, don't make the same request a gain. | 106 # In case there's an error in the request, don't make the same request a gain. |
| 102 self.is_stale_results[bug_link] = False | 107 self.is_stale_results[bug_link] = False |
| 103 bug_number = bug_link.strip(CRBUG_PREFIX) | 108 bug_number = bug_link.strip(CRBUG_PREFIX) |
| 104 url = GOOGLE_CODE_URL % bug_number | 109 url = GOOGLE_CODE_URL % bug_number |
| 105 response = urllib2.urlopen(url) | 110 response = urllib2.urlopen(url) |
| 106 parsed = json.loads(response.read()) | 111 parsed = json.loads(response.read()) |
| 107 last_updated = parsed['updated'] | 112 last_updated = parsed['updated'] |
| 108 parsed_time = datetime.datetime.strptime(last_updated.split(".")[0] + "U TC", "%Y-%m-%dT%H:%M:%S%Z") | 113 parsed_time = datetime.datetime.strptime(last_updated.split(".")[0] + "U TC", "%Y-%m-%dT%H:%M:%S%Z") |
| 109 time_delta = datetime.datetime.now() - parsed_time | 114 time_delta = datetime.datetime.now() - parsed_time |
| 110 self.is_stale_results[bug_link] = time_delta.days > self.days | 115 self.is_stale_results[bug_link] = time_delta.days > self.days |
| 116 self.last_updated[bug_link] = time_delta.days | |
| 117 self.state[bug_link] = parsed['state'] | |
|
qyearsley
2016/08/19 00:37:18
It seems like storing the state of the bug isn't c
nainar
2016/08/19 03:36:48
Have done the refactors you have asked for.
| |
| 111 return self.is_stale_results[bug_link] | 118 return self.is_stale_results[bug_link] |
| 112 | 119 |
| 113 | 120 |
| 114 def main(argv): | 121 def main(argv): |
| 115 option_parser = optparse.OptionParser() | 122 option_parser = optparse.OptionParser() |
| 116 option_parser.add_option( | 123 option_parser.add_option( |
| 117 '--days', type='int', default=90, | 124 '--days', type='int', default=90, |
| 118 help='Number of days to consider a bug stale.') | 125 help='Number of days to consider a bug stale.') |
| 119 option_parser.add_option( | 126 option_parser.add_option( |
| 120 '--create-csv', type='string', default='', | 127 '--create-csv', type='string', default='', |
| 121 help='Filename of CSV file to write stale entries to. No file will be wr itten if no name specified.') | 128 help='Filename of CSV file to write stale entries to. No file will be wr itten if no name specified.') |
| 122 options, _ = option_parser.parse_args(argv) | 129 options, _ = option_parser.parse_args(argv) |
| 123 printer = StaleTestPrinter(options) | 130 printer = StaleTestPrinter(options) |
| 124 printer.print_stale_tests() | 131 printer.print_stale_tests() |
| 125 return 0 | 132 return 0 |
| 126 | 133 |
| 127 | 134 |
| 128 if __name__ == '__main__': | 135 if __name__ == '__main__': |
| 129 sys.exit(main(sys.argv[1:])) | 136 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |