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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apply_issue.py
diff --git a/apply_issue.py b/apply_issue.py
index 9bc5d2123158cfdb1f92de3ab589f2f91decf459..3eb4d61f321d217b5f970161a2e0a7c0e4821c7b 100755
--- a/apply_issue.py
+++ b/apply_issue.py
@@ -31,7 +31,7 @@ def main():
'-v', '--verbose', action='count', default=0,
help='Prints debugging infos')
parser.add_option(
- '-e', '--email', default='',
+ '-e', '--email',
help='Email address to access rietveld. If not specified, anonymous '
'access will be used.')
parser.add_option(
@@ -67,13 +67,32 @@ def main():
if options.password == '-':
options.password = sys.stdin.readline().strip()
- obj = rietveld.Rietveld(options.server, options.email, options.password)
+ # Always try un-authenticated first.
+ # TODO(maruel): Use OAuth2 properly so we don't hit rate-limiting on login
+ # attempts.
+ # Bad except clauses order (HTTPError is an ancestor class of
+ # ClientLoginError)
+ # pylint: disable=E0701
+ obj = rietveld.Rietveld(options.server, '', None)
+ properties = None
try:
properties = obj.get_issue_properties(options.issue, False)
+ except urllib2.HTTPError, e:
+ if e.getcode() != 302:
+ raise
+ # TODO(maruel): A few 'Invalid username or password.' are printed first, we
+ # should get rid of those.
except rietveld.upload.ClientLoginError, e:
- if sys.stdout.closed:
- print >> sys.stderr, 'Accessing the issue requires login.'
- return 1
+ # Fine, we'll do proper authentication.
+ pass
+ if properties is None:
+ if options.email is not None:
+ try:
+ obj = rietveld.Rietveld(options.server, options.email, options.password)
+ except rietveld.upload.ClientLoginError, e:
+ if sys.stdout.closed:
+ print >> sys.stderr, 'Accessing the issue requires login.'
+ return 1
print('Accessing the issue requires login.')
obj = rietveld.Rietveld(options.server, None, None)
properties = obj.get_issue_properties(options.issue, False)
« 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