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.8.0' | 9 __version__ = '1.8.0' |
10 | 10 |
(...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 "presubmit_canned_checks. Can be provided multiple times " | 1643 "presubmit_canned_checks. Can be provided multiple times " |
1644 "to skip multiple canned checks.") | 1644 "to skip multiple canned checks.") |
1645 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) | 1645 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) |
1646 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) | 1646 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) |
1647 parser.add_option("--rietveld_fetch", action='store_true', default=False, | 1647 parser.add_option("--rietveld_fetch", action='store_true', default=False, |
1648 help=optparse.SUPPRESS_HELP) | 1648 help=optparse.SUPPRESS_HELP) |
1649 # These are for OAuth2 authentication for bots. See also apply_issue.py | 1649 # These are for OAuth2 authentication for bots. See also apply_issue.py |
1650 parser.add_option("--rietveld_email_file", help=optparse.SUPPRESS_HELP) | 1650 parser.add_option("--rietveld_email_file", help=optparse.SUPPRESS_HELP) |
1651 parser.add_option("--rietveld_private_key_file", help=optparse.SUPPRESS_HELP) | 1651 parser.add_option("--rietveld_private_key_file", help=optparse.SUPPRESS_HELP) |
1652 | 1652 |
| 1653 # TODO(phajdan.jr): Update callers and remove obsolete --trybot-json . |
1653 parser.add_option("--trybot-json", | 1654 parser.add_option("--trybot-json", |
1654 help="Output trybot information to the file specified.") | 1655 help="Output trybot information to the file specified.") |
1655 auth.add_auth_options(parser) | 1656 auth.add_auth_options(parser) |
1656 options, args = parser.parse_args(argv) | 1657 options, args = parser.parse_args(argv) |
1657 auth_config = auth.extract_auth_config_from_options(options) | 1658 auth_config = auth.extract_auth_config_from_options(options) |
1658 | 1659 |
1659 if options.verbose >= 2: | 1660 if options.verbose >= 2: |
1660 logging.basicConfig(level=logging.DEBUG) | 1661 logging.basicConfig(level=logging.DEBUG) |
1661 elif options.verbose: | 1662 elif options.verbose: |
1662 logging.basicConfig(level=logging.INFO) | 1663 logging.basicConfig(level=logging.INFO) |
(...skipping 26 matching lines...) Expand all Loading... |
1689 options.rietveld_url, | 1690 options.rietveld_url, |
1690 auth_config, | 1691 auth_config, |
1691 options.rietveld_email) | 1692 options.rietveld_email) |
1692 if options.rietveld_fetch: | 1693 if options.rietveld_fetch: |
1693 assert options.issue | 1694 assert options.issue |
1694 props = rietveld_obj.get_issue_properties(options.issue, False) | 1695 props = rietveld_obj.get_issue_properties(options.issue, False) |
1695 options.author = props['owner_email'] | 1696 options.author = props['owner_email'] |
1696 options.description = props['description'] | 1697 options.description = props['description'] |
1697 logging.info('Got author: "%s"', options.author) | 1698 logging.info('Got author: "%s"', options.author) |
1698 logging.info('Got description: """\n%s\n"""', options.description) | 1699 logging.info('Got description: """\n%s\n"""', options.description) |
1699 if options.trybot_json: | |
1700 with open(options.trybot_json, 'w') as f: | |
1701 # Python's sets aren't JSON-encodable, so we convert them to lists here. | |
1702 class SetEncoder(json.JSONEncoder): | |
1703 # pylint: disable=E0202 | |
1704 def default(self, obj): | |
1705 if isinstance(obj, set): | |
1706 return sorted(obj) | |
1707 return json.JSONEncoder.default(self, obj) | |
1708 change = change_class(options.name, | |
1709 options.description, | |
1710 options.root, | |
1711 files, | |
1712 options.issue, | |
1713 options.patchset, | |
1714 options.author, | |
1715 upstream=options.upstream) | |
1716 trybots = DoGetTrySlaves( | |
1717 change, | |
1718 change.LocalPaths(), | |
1719 change.RepositoryRoot(), | |
1720 None, | |
1721 None, | |
1722 options.verbose, | |
1723 sys.stdout) | |
1724 json.dump(trybots, f, cls=SetEncoder) | |
1725 try: | 1700 try: |
1726 with canned_check_filter(options.skip_canned): | 1701 with canned_check_filter(options.skip_canned): |
1727 results = DoPresubmitChecks( | 1702 results = DoPresubmitChecks( |
1728 change_class(options.name, | 1703 change_class(options.name, |
1729 options.description, | 1704 options.description, |
1730 options.root, | 1705 options.root, |
1731 files, | 1706 files, |
1732 options.issue, | 1707 options.issue, |
1733 options.patchset, | 1708 options.patchset, |
1734 options.author, | 1709 options.author, |
(...skipping 17 matching lines...) Expand all Loading... |
1752 return 2 | 1727 return 2 |
1753 | 1728 |
1754 | 1729 |
1755 if __name__ == '__main__': | 1730 if __name__ == '__main__': |
1756 fix_encoding.fix_encoding() | 1731 fix_encoding.fix_encoding() |
1757 try: | 1732 try: |
1758 sys.exit(main()) | 1733 sys.exit(main()) |
1759 except KeyboardInterrupt: | 1734 except KeyboardInterrupt: |
1760 sys.stderr.write('interrupted\n') | 1735 sys.stderr.write('interrupted\n') |
1761 sys.exit(1) | 1736 sys.exit(1) |
OLD | NEW |