| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 __version__ = '1.7.0' | 9 __version__ = '1.8.0' |
| 10 | 10 |
| 11 # TODO(joi) Add caching where appropriate/needed. The API is designed to allow | 11 # TODO(joi) Add caching where appropriate/needed. The API is designed to allow |
| 12 # caching (between all different invocations of presubmit scripts for a given | 12 # caching (between all different invocations of presubmit scripts for a given |
| 13 # change). We should add it as our presubmit scripts start feeling slow. | 13 # change). We should add it as our presubmit scripts start feeling slow. |
| 14 | 14 |
| 15 import cpplint | 15 import cpplint |
| 16 import cPickle # Exposed through the API. | 16 import cPickle # Exposed through the API. |
| 17 import cStringIO # Exposed through the API. | 17 import cStringIO # Exposed through the API. |
| 18 import contextlib | 18 import contextlib |
| 19 import fnmatch | 19 import fnmatch |
| (...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 parser.add_option("--may_prompt", action='store_true', default=False) | 1423 parser.add_option("--may_prompt", action='store_true', default=False) |
| 1424 parser.add_option("--skip_canned", action='append', default=[], | 1424 parser.add_option("--skip_canned", action='append', default=[], |
| 1425 help="A list of checks to skip which appear in " | 1425 help="A list of checks to skip which appear in " |
| 1426 "presubmit_canned_checks. Can be provided multiple times " | 1426 "presubmit_canned_checks. Can be provided multiple times " |
| 1427 "to skip multiple canned checks.") | 1427 "to skip multiple canned checks.") |
| 1428 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) | 1428 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) |
| 1429 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) | 1429 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) |
| 1430 parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP) | 1430 parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP) |
| 1431 parser.add_option("--rietveld_fetch", action='store_true', default=False, | 1431 parser.add_option("--rietveld_fetch", action='store_true', default=False, |
| 1432 help=optparse.SUPPRESS_HELP) | 1432 help=optparse.SUPPRESS_HELP) |
| 1433 parser.add_option("--trybot-json", |
| 1434 help="Output trybot information to the file specified.") |
| 1433 options, args = parser.parse_args(argv) | 1435 options, args = parser.parse_args(argv) |
| 1434 if options.verbose >= 2: | 1436 if options.verbose >= 2: |
| 1435 logging.basicConfig(level=logging.DEBUG) | 1437 logging.basicConfig(level=logging.DEBUG) |
| 1436 elif options.verbose: | 1438 elif options.verbose: |
| 1437 logging.basicConfig(level=logging.INFO) | 1439 logging.basicConfig(level=logging.INFO) |
| 1438 else: | 1440 else: |
| 1439 logging.basicConfig(level=logging.ERROR) | 1441 logging.basicConfig(level=logging.ERROR) |
| 1440 change_class, files = load_files(options, args) | 1442 change_class, files = load_files(options, args) |
| 1441 if not change_class: | 1443 if not change_class: |
| 1442 parser.error('For unversioned directory, <files> is not optional.') | 1444 parser.error('For unversioned directory, <files> is not optional.') |
| 1443 logging.info('Found %d file(s).' % len(files)) | 1445 logging.info('Found %d file(s).' % len(files)) |
| 1444 rietveld_obj = None | 1446 rietveld_obj = None |
| 1445 if options.rietveld_url: | 1447 if options.rietveld_url: |
| 1446 rietveld_obj = rietveld.CachingRietveld( | 1448 rietveld_obj = rietveld.CachingRietveld( |
| 1447 options.rietveld_url, | 1449 options.rietveld_url, |
| 1448 options.rietveld_email, | 1450 options.rietveld_email, |
| 1449 options.rietveld_password) | 1451 options.rietveld_password) |
| 1450 if options.rietveld_fetch: | 1452 if options.rietveld_fetch: |
| 1451 assert options.issue | 1453 assert options.issue |
| 1452 props = rietveld_obj.get_issue_properties(options.issue, False) | 1454 props = rietveld_obj.get_issue_properties(options.issue, False) |
| 1453 options.author = props['owner_email'] | 1455 options.author = props['owner_email'] |
| 1454 options.description = props['description'] | 1456 options.description = props['description'] |
| 1455 logging.info('Got author: "%s"', options.author) | 1457 logging.info('Got author: "%s"', options.author) |
| 1456 logging.info('Got description: """\n%s\n"""', options.description) | 1458 logging.info('Got description: """\n%s\n"""', options.description) |
| 1459 if options.trybot_json: |
| 1460 with open(options.trybot_json, 'w') as f: |
| 1461 # Python's sets aren't JSON-encodable, so we convert them to lists here. |
| 1462 class SetEncoder(json.JSONEncoder): |
| 1463 # pylint: disable=E0202 |
| 1464 def default(self, obj): |
| 1465 if isinstance(obj, set): |
| 1466 return sorted(obj) |
| 1467 return json.JSONEncoder.default(self, obj) |
| 1468 change = change_class(options.name, |
| 1469 options.description, |
| 1470 options.root, |
| 1471 files, |
| 1472 options.issue, |
| 1473 options.patchset, |
| 1474 options.author) |
| 1475 trybots = DoGetTrySlaves( |
| 1476 change, |
| 1477 change.LocalPaths(), |
| 1478 change.RepositoryRoot(), |
| 1479 None, |
| 1480 None, |
| 1481 options.verbose, |
| 1482 sys.stdout) |
| 1483 json.dump(trybots, f, cls=SetEncoder) |
| 1457 try: | 1484 try: |
| 1458 with canned_check_filter(options.skip_canned): | 1485 with canned_check_filter(options.skip_canned): |
| 1459 results = DoPresubmitChecks( | 1486 results = DoPresubmitChecks( |
| 1460 change_class(options.name, | 1487 change_class(options.name, |
| 1461 options.description, | 1488 options.description, |
| 1462 options.root, | 1489 options.root, |
| 1463 files, | 1490 files, |
| 1464 options.issue, | 1491 options.issue, |
| 1465 options.patchset, | 1492 options.patchset, |
| 1466 options.author), | 1493 options.author), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1479 except PresubmitFailure, e: | 1506 except PresubmitFailure, e: |
| 1480 print >> sys.stderr, e | 1507 print >> sys.stderr, e |
| 1481 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1508 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
| 1482 print >> sys.stderr, 'If all fails, contact maruel@' | 1509 print >> sys.stderr, 'If all fails, contact maruel@' |
| 1483 return 2 | 1510 return 2 |
| 1484 | 1511 |
| 1485 | 1512 |
| 1486 if __name__ == '__main__': | 1513 if __name__ == '__main__': |
| 1487 fix_encoding.fix_encoding() | 1514 fix_encoding.fix_encoding() |
| 1488 sys.exit(Main(None)) | 1515 sys.exit(Main(None)) |
| OLD | NEW |