| 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 28 matching lines...) Expand all Loading... |
| 39 import urllib2 | 39 import urllib2 |
| 40 | 40 |
| 41 from webkitpy.common.host import Host | 41 from webkitpy.common.host import Host |
| 42 from webkitpy.common.system.filesystem import FileSystem | 42 from webkitpy.common.system.filesystem import FileSystem |
| 43 from webkitpy.common.webkit_finder import WebKitFinder | 43 from webkitpy.common.webkit_finder import WebKitFinder |
| 44 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser | 44 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser |
| 45 | 45 |
| 46 google_code_url = 'https://www.googleapis.com/projecthosting/v2/projects/chromiu
m/issues/%s?key=AIzaSyDgCqT1Dt5AZWLHo4QJjyMHaCjhnFacGF0' | 46 google_code_url = 'https://www.googleapis.com/projecthosting/v2/projects/chromiu
m/issues/%s?key=AIzaSyDgCqT1Dt5AZWLHo4QJjyMHaCjhnFacGF0' |
| 47 crbug_prefix = 'crbug.com/' | 47 crbug_prefix = 'crbug.com/' |
| 48 | 48 |
| 49 |
| 49 class StaleTestPrinter(object): | 50 class StaleTestPrinter(object): |
| 51 |
| 50 def __init__(self, options): | 52 def __init__(self, options): |
| 51 self.days = options.days | 53 self.days = options.days |
| 52 self.create_csv = options.create_csv | 54 self.create_csv = options.create_csv |
| 53 | 55 |
| 54 def is_stale(self, bug_link): | 56 def is_stale(self, bug_link): |
| 55 bug_number = bug_link.strip(crbug_prefix) | 57 bug_number = bug_link.strip(crbug_prefix) |
| 56 url = google_code_url % bug_number | 58 url = google_code_url % bug_number |
| 57 response = urllib2.urlopen(url) | 59 response = urllib2.urlopen(url) |
| 58 parsed = json.loads(response.read()) | 60 parsed = json.loads(response.read()) |
| 59 last_updated = parsed['updated'] | 61 last_updated = parsed['updated'] |
| 60 parsed_time = datetime.datetime.strptime(last_updated.split(".")[0]+"UTC
", "%Y-%m-%dT%H:%M:%S%Z") | 62 parsed_time = datetime.datetime.strptime(last_updated.split(".")[0] + "U
TC", "%Y-%m-%dT%H:%M:%S%Z") |
| 61 time_delta = datetime.datetime.now() - parsed_time | 63 time_delta = datetime.datetime.now() - parsed_time |
| 62 return time_delta.days > self.days | 64 return time_delta.days > self.days |
| 63 | 65 |
| 64 def print_stale_tests(self): | 66 def print_stale_tests(self): |
| 65 host = Host() | 67 host = Host() |
| 66 port = host.port_factory.get() | 68 port = host.port_factory.get() |
| 67 exps = port.expectations_dict() | 69 exps = port.expectations_dict() |
| 68 csv_contents = '' | 70 csv_contents = '' |
| 69 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) | 71 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) |
| 70 for line in parser.parse(*exps.items()[0]): | 72 for line in parser.parse(*exps.items()[0]): |
| 71 bugs, name = line.bugs, line.name | 73 bugs, name = line.bugs, line.name |
| 72 try: | 74 try: |
| 73 if bugs and all(self.is_stale(bug) for bug in bugs): | 75 if bugs and all(self.is_stale(bug) for bug in bugs): |
| 74 print line.original_string.strip() | 76 print line.original_string.strip() |
| 75 csv_contents += "%s, %s\n" % (bugs[0], name) | 77 csv_contents += "%s, %s\n" % (bugs[0], name) |
| 76 except urllib2.HTTPError as error: | 78 except urllib2.HTTPError as error: |
| 77 if error.code == 404: | 79 if error.code == 404: |
| 78 print 'Does not exist.' | 80 print 'Does not exist.' |
| 79 elif error.code == 403: | 81 elif error.code == 403: |
| 80 print 'Is not accessible. Not able to tell if it\'s stale.' | 82 print 'Is not accessible. Not able to tell if it\'s stale.' |
| 81 is_bug_stale = False | 83 is_bug_stale = False |
| 82 else: | 84 else: |
| 83 print error | 85 print error |
| 84 if self.create_csv: | 86 if self.create_csv: |
| 85 host.filesystem.write_text_file(self.create_csv, csv_contents) | 87 host.filesystem.write_text_file(self.create_csv, csv_contents) |
| 86 | 88 |
| 89 |
| 87 def main(argv): | 90 def main(argv): |
| 88 option_parser = optparse.OptionParser() | 91 option_parser = optparse.OptionParser() |
| 89 option_parser.add_option('--days', type='int', default=90, help='Number of d
ays to consider a bug stale.'), | 92 option_parser.add_option('--days', type='int', default=90, help='Number of d
ays to consider a bug stale.'), |
| 90 option_parser.add_option('--create-csv', type='string', default=0, help='Gen
erate a CSV of the stale entries as well. Followed by the filename.'), | 93 option_parser.add_option( |
| 94 '--create-csv', |
| 95 type='string', |
| 96 default=0, |
| 97 help='Generate a CSV of the stale entries as well. Followed by the filen
ame.'), |
| 91 options, args = option_parser.parse_args(argv) | 98 options, args = option_parser.parse_args(argv) |
| 92 | 99 |
| 93 printer = StaleTestPrinter(options) | 100 printer = StaleTestPrinter(options) |
| 94 printer.print_stale_tests() | 101 printer.print_stale_tests() |
| 95 return 0 | 102 return 0 |
| 96 | 103 |
| 97 if __name__ == '__main__': | 104 if __name__ == '__main__': |
| 98 sys.exit(main(sys.argv[1:])) | 105 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |