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

Side by Side Diff: apply_issue.py

Issue 11019015: Works around rate limiting by trying to apply CL unauthenticated first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Removed stray print statement Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 """Applies an issue from Rietveld. 6 """Applies an issue from Rietveld.
7 """ 7 """
8 8
9 import getpass 9 import getpass
10 import logging 10 import logging
(...skipping 13 matching lines...) Expand all
24 24
25 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 25 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
26 26
27 27
28 def main(): 28 def main():
29 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) 29 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__)
30 parser.add_option( 30 parser.add_option(
31 '-v', '--verbose', action='count', default=0, 31 '-v', '--verbose', action='count', default=0,
32 help='Prints debugging infos') 32 help='Prints debugging infos')
33 parser.add_option( 33 parser.add_option(
34 '-e', '--email', default='', 34 '-e', '--email',
35 help='Email address to access rietveld. If not specified, anonymous ' 35 help='Email address to access rietveld. If not specified, anonymous '
36 'access will be used.') 36 'access will be used.')
37 parser.add_option( 37 parser.add_option(
38 '-w', '--password', default=None, 38 '-w', '--password', default=None,
39 help='Password for email addressed. Use - to read password from stdin.') 39 help='Password for email addressed. Use - to read password from stdin.')
40 parser.add_option( 40 parser.add_option(
41 '-i', '--issue', type='int', help='Rietveld issue number') 41 '-i', '--issue', type='int', help='Rietveld issue number')
42 parser.add_option( 42 parser.add_option(
43 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') 43 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number')
44 parser.add_option( 44 parser.add_option(
(...skipping 15 matching lines...) Expand all
60 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) 60 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args))
61 if not options.issue: 61 if not options.issue:
62 parser.error('Require --issue') 62 parser.error('Require --issue')
63 options.server = options.server.rstrip('/') 63 options.server = options.server.rstrip('/')
64 if not options.server: 64 if not options.server:
65 parser.error('Require a valid server') 65 parser.error('Require a valid server')
66 66
67 if options.password == '-': 67 if options.password == '-':
68 options.password = sys.stdin.readline().strip() 68 options.password = sys.stdin.readline().strip()
69 69
70 obj = rietveld.Rietveld(options.server, options.email, options.password) 70 # Always try un-authenticated first.
71 # TODO(maruel): Use OAuth2 properly so we don't hit rate-limiting on login
72 # attempts.
73 # Bad except clauses order (HTTPError is an ancestor class of
74 # ClientLoginError)
75 # pylint: disable=E0701
76 obj = rietveld.Rietveld(options.server, '', None)
77 properties = None
71 try: 78 try:
72 properties = obj.get_issue_properties(options.issue, False) 79 properties = obj.get_issue_properties(options.issue, False)
80 except urllib2.HTTPError, e:
81 if e.getcode() != 302:
82 raise
83 # TODO(maruel): A few 'Invalid username or password.' are printed first, we
84 # should get rid of those.
73 except rietveld.upload.ClientLoginError, e: 85 except rietveld.upload.ClientLoginError, e:
74 if sys.stdout.closed: 86 # Fine, we'll do proper authentication.
75 print >> sys.stderr, 'Accessing the issue requires login.' 87 pass
76 return 1 88 if properties is None:
89 if options.email is not None:
90 try:
91 obj = rietveld.Rietveld(options.server, options.email, options.password)
92 except rietveld.upload.ClientLoginError, e:
93 if sys.stdout.closed:
94 print >> sys.stderr, 'Accessing the issue requires login.'
95 return 1
77 print('Accessing the issue requires login.') 96 print('Accessing the issue requires login.')
78 obj = rietveld.Rietveld(options.server, None, None) 97 obj = rietveld.Rietveld(options.server, None, None)
79 properties = obj.get_issue_properties(options.issue, False) 98 properties = obj.get_issue_properties(options.issue, False)
80 99
81 if not options.patchset: 100 if not options.patchset:
82 options.patchset = properties['patchsets'][-1] 101 options.patchset = properties['patchsets'][-1]
83 print('No patchset specified. Using patchset %d' % options.patchset) 102 print('No patchset specified. Using patchset %d' % options.patchset)
84 103
85 print('Downloading the patch.') 104 print('Downloading the patch.')
86 try: 105 try:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if sys.platform == 'win32': 150 if sys.platform == 'win32':
132 gclient_path += '.bat' 151 gclient_path += '.bat'
133 return subprocess.call( 152 return subprocess.call(
134 [gclient_path, 'sync', '--revision', base_rev], cwd=gclient_root) 153 [gclient_path, 'sync', '--revision', base_rev], cwd=gclient_root)
135 return 0 154 return 0
136 155
137 156
138 if __name__ == "__main__": 157 if __name__ == "__main__":
139 fix_encoding.fix_encoding() 158 fix_encoding.fix_encoding()
140 sys.exit(main()) 159 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698