Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: presubmit_support.py

Issue 1075723002: Extract authentication options handling into a separate function. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « my_reviews.py ('k') | rietveld.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
32 import sys # Parts exposed through API. 32 import sys # Parts exposed through API.
33 import tempfile # Exposed through the API. 33 import tempfile # Exposed through the API.
34 import time 34 import time
35 import traceback # Exposed through the API. 35 import traceback # Exposed through the API.
36 import types 36 import types
37 import unittest # Exposed through the API. 37 import unittest # Exposed through the API.
38 import urllib2 # Exposed through the API. 38 import urllib2 # Exposed through the API.
39 from warnings import warn 39 from warnings import warn
40 40
41 # Local imports. 41 # Local imports.
42 import auth
42 import fix_encoding 43 import fix_encoding
43 import gclient_utils 44 import gclient_utils
44 import owners 45 import owners
45 import presubmit_canned_checks 46 import presubmit_canned_checks
46 import rietveld 47 import rietveld
47 import scm 48 import scm
48 import subprocess2 as subprocess # Exposed through the API. 49 import subprocess2 as subprocess # Exposed through the API.
49 50
50 51
51 # Ask for feedback only once in program lifetime. 52 # Ask for feedback only once in program lifetime.
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 help="Git only: the base ref or upstream branch against " 1631 help="Git only: the base ref or upstream branch against "
1631 "which the diff should be computed.") 1632 "which the diff should be computed.")
1632 parser.add_option("--default_presubmit") 1633 parser.add_option("--default_presubmit")
1633 parser.add_option("--may_prompt", action='store_true', default=False) 1634 parser.add_option("--may_prompt", action='store_true', default=False)
1634 parser.add_option("--skip_canned", action='append', default=[], 1635 parser.add_option("--skip_canned", action='append', default=[],
1635 help="A list of checks to skip which appear in " 1636 help="A list of checks to skip which appear in "
1636 "presubmit_canned_checks. Can be provided multiple times " 1637 "presubmit_canned_checks. Can be provided multiple times "
1637 "to skip multiple canned checks.") 1638 "to skip multiple canned checks.")
1638 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) 1639 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP)
1639 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) 1640 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP)
1640 parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP)
1641 parser.add_option("--rietveld_fetch", action='store_true', default=False, 1641 parser.add_option("--rietveld_fetch", action='store_true', default=False,
1642 help=optparse.SUPPRESS_HELP) 1642 help=optparse.SUPPRESS_HELP)
1643 # These are for OAuth2 authentication for bots. See also apply_issue.py 1643 # These are for OAuth2 authentication for bots. See also apply_issue.py
1644 parser.add_option("--rietveld_email_file", help=optparse.SUPPRESS_HELP) 1644 parser.add_option("--rietveld_email_file", help=optparse.SUPPRESS_HELP)
1645 parser.add_option("--rietveld_private_key_file", help=optparse.SUPPRESS_HELP) 1645 parser.add_option("--rietveld_private_key_file", help=optparse.SUPPRESS_HELP)
1646 1646
1647 parser.add_option("--trybot-json", 1647 parser.add_option("--trybot-json",
1648 help="Output trybot information to the file specified.") 1648 help="Output trybot information to the file specified.")
1649 auth.add_auth_options(parser)
1649 options, args = parser.parse_args(argv) 1650 options, args = parser.parse_args(argv)
1651 auth_config = auth.extract_auth_config_from_options(options)
1650 1652
1651 if options.verbose >= 2: 1653 if options.verbose >= 2:
1652 logging.basicConfig(level=logging.DEBUG) 1654 logging.basicConfig(level=logging.DEBUG)
1653 elif options.verbose: 1655 elif options.verbose:
1654 logging.basicConfig(level=logging.INFO) 1656 logging.basicConfig(level=logging.INFO)
1655 else: 1657 else:
1656 logging.basicConfig(level=logging.ERROR) 1658 logging.basicConfig(level=logging.ERROR)
1657 1659
1658 if options.rietveld_email and options.rietveld_email_file: 1660 if options.rietveld_email and options.rietveld_email_file:
1659 parser.error("Only one of --rietveld_email or --rietveld_email_file " 1661 parser.error("Only one of --rietveld_email or --rietveld_email_file "
1660 "can be passed to this program.") 1662 "can be passed to this program.")
1661 if options.rietveld_private_key_file and options.rietveld_password:
1662 parser.error("Only one of --rietveld_private_key_file or "
1663 "--rietveld_password can be passed to this program.")
1664 1663
1665 if options.rietveld_email_file: 1664 if options.rietveld_email_file:
1666 with open(options.rietveld_email_file, "rb") as f: 1665 with open(options.rietveld_email_file, "rb") as f:
1667 options.rietveld_email = f.read().strip() 1666 options.rietveld_email = f.read().strip()
1668 1667
1669 change_class, files = load_files(options, args) 1668 change_class, files = load_files(options, args)
1670 if not change_class: 1669 if not change_class:
1671 parser.error('For unversioned directory, <files> is not optional.') 1670 parser.error('For unversioned directory, <files> is not optional.')
1672 logging.info('Found %d file(s).' % len(files)) 1671 logging.info('Found %d file(s).' % len(files))
1673 1672
1674 rietveld_obj = None 1673 rietveld_obj = None
1675 if options.rietveld_url: 1674 if options.rietveld_url:
1676 # The empty password is permitted: '' is not None. 1675 # The empty password is permitted: '' is not None.
1677 if options.rietveld_private_key_file: 1676 if options.rietveld_private_key_file:
1678 rietveld_obj = rietveld.JwtOAuth2Rietveld( 1677 rietveld_obj = rietveld.JwtOAuth2Rietveld(
1679 options.rietveld_url, 1678 options.rietveld_url,
1680 options.rietveld_email, 1679 options.rietveld_email,
1681 options.rietveld_private_key_file) 1680 options.rietveld_private_key_file)
1682 else: 1681 else:
1683 rietveld_obj = rietveld.CachingRietveld( 1682 rietveld_obj = rietveld.CachingRietveld(
1684 options.rietveld_url, 1683 options.rietveld_url,
1685 options.rietveld_email, 1684 auth_config,
1686 options.rietveld_password) 1685 options.rietveld_email)
1687 if options.rietveld_fetch: 1686 if options.rietveld_fetch:
1688 assert options.issue 1687 assert options.issue
1689 props = rietveld_obj.get_issue_properties(options.issue, False) 1688 props = rietveld_obj.get_issue_properties(options.issue, False)
1690 options.author = props['owner_email'] 1689 options.author = props['owner_email']
1691 options.description = props['description'] 1690 options.description = props['description']
1692 logging.info('Got author: "%s"', options.author) 1691 logging.info('Got author: "%s"', options.author)
1693 logging.info('Got description: """\n%s\n"""', options.description) 1692 logging.info('Got description: """\n%s\n"""', options.description)
1694 if options.trybot_json: 1693 if options.trybot_json:
1695 with open(options.trybot_json, 'w') as f: 1694 with open(options.trybot_json, 'w') as f:
1696 # Python's sets aren't JSON-encodable, so we convert them to lists here. 1695 # Python's sets aren't JSON-encodable, so we convert them to lists here.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 return 2 1746 return 2
1748 1747
1749 1748
1750 if __name__ == '__main__': 1749 if __name__ == '__main__':
1751 fix_encoding.fix_encoding() 1750 fix_encoding.fix_encoding()
1752 try: 1751 try:
1753 sys.exit(main()) 1752 sys.exit(main())
1754 except KeyboardInterrupt: 1753 except KeyboardInterrupt:
1755 sys.stderr.write('interrupted\n') 1754 sys.stderr.write('interrupted\n')
1756 sys.exit(1) 1755 sys.exit(1)
OLDNEW
« no previous file with comments | « my_reviews.py ('k') | rietveld.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698