Chromium Code Reviews| 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 import datetime | 6 import datetime |
| 7 import json | |
| 7 import optparse | 8 import optparse |
| 8 import os | 9 import os |
| 9 import re | 10 import re |
| 10 import string | |
| 11 import sys | 11 import sys |
| 12 import urllib2 | 12 import urllib2 |
| 13 import urlparse | 13 import urlparse |
| 14 | 14 |
| 15 import breakpad # pylint: disable=W0611 | 15 import breakpad # pylint: disable=W0611 |
| 16 | 16 |
| 17 import gclient_utils | 17 import gclient_utils |
| 18 import subprocess2 | 18 import subprocess2 |
| 19 | 19 |
| 20 USAGE = """ | 20 USAGE = """ |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 | 368 |
| 369 Anything that's A will require special treatment (either a merge or an | 369 Anything that's A will require special treatment (either a merge or an |
| 370 export + add) | 370 export + add) |
| 371 """ | 371 """ |
| 372 return ['%s/%s' % (f[2], f[3]) for f in files_info] | 372 return ['%s/%s' % (f[2], f[3]) for f in files_info] |
| 373 | 373 |
| 374 | 374 |
| 375 def getBranchForMilestone(milestone): | 375 def getBranchForMilestone(milestone): |
| 376 """Queries omahaproxy.appspot.com for the branch number given |milestone|. | 376 """Queries omahaproxy.appspot.com for the branch number given |milestone|. |
| 377 """ | 377 """ |
| 378 OMAHA_PROXY_URL = "http://omahaproxy.appspot.com/all?csv=1" | 378 OMAHA_PROXY_URL = "http://omahaproxy.appspot.com/all?json=1" |
|
Isaac (away)
2013/05/03 10:00:50
can we use https?
Dan Beam
2013/05/03 17:05:43
Done.
| |
| 379 request = urllib2.Request(OMAHA_PROXY_URL) | |
| 380 try: | 379 try: |
| 381 response = urllib2.urlopen(request) | 380 request = urllib2.urlopen(OMAHA_PROXY_URL) |
|
Isaac (away)
2013/05/03 10:00:50
I think this variable would be aptly named 'respon
Dan Beam
2013/05/03 17:05:43
I've renamed to response, but this is actually a f
| |
| 382 except urllib2.HTTPError, e: | 381 except urllib2.HTTPError, e: |
| 383 print "Failed to query %s: %d" % (OMAHA_PROXY_URL, e.code) | 382 print "Failed to query %s: %d" % (OMAHA_PROXY_URL, e.code) |
| 384 return None | 383 return None |
| 385 | 384 |
| 386 # Dictionary of [branch: major]. When searching for the appropriate branch | 385 # Response is in the form of: |
| 387 # matching |milestone|, all major versions that match are added to the | 386 # [{ os: "os_name", versions: [{ channel: "canary", true_branch: "1490" }] }] |
| 388 # dictionary. If all of the branches are the same, this branch value is | 387 response = json.load(request) |
|
Isaac (away)
2013/05/03 10:00:50
nit: change 'response' to variable name that descr
Dan Beam
2013/05/03 17:05:43
Done.
| |
| 389 # returned; otherwise, the user is prompted to accept the largest branch | |
| 390 # value. | |
| 391 branch_dict = {} | |
| 392 | 388 |
| 393 # Slice the first line since it's column information text. | 389 branches = {} |
|
Isaac (away)
2013/05/03 10:00:50
import collections
...
branches = collections.de
Dan Beam
2013/05/03 17:05:43
Done.
| |
| 394 for line in response.readlines()[1:]: | 390 for os_version in response: |
| 395 # Version data is CSV. | 391 for version in os_version['versions']: |
| 396 parameters = string.split(line, ',') | 392 if not version['true_branch'] or not version['version']: |
|
Isaac (away)
2013/05/03 10:00:50
I don't think this check is necessary.
not versio
Dan Beam
2013/05/03 17:05:43
I was getting None type, see below as to why this
| |
| 393 continue | |
| 394 mstone = version['version'].split('.') | |
|
Dan Beam
2013/05/03 17:05:43
if version['version'] is None type this dies
| |
| 395 if not mstone or mstone[0] != str(milestone): | |
| 396 continue | |
| 397 branch = version['true_branch'] | |
| 398 if not branch.isdigit(): | |
|
Isaac (away)
2013/05/03 10:00:50
this seems brittle, are they guaranteed to be ints
Dan Beam
2013/05/03 17:05:43
if version['true_branch'] is None type this dies
Dan Beam
2013/05/03 17:05:43
asked laforge@, didn't get back to me, made a litt
| |
| 399 continue | |
| 400 if not branch in branches: | |
| 401 branches[branch] = [] | |
| 402 branches[branch] += [os_version['os']] | |
| 397 | 403 |
|
Isaac (away)
2013/05/03 10:00:50
check if branches is empty?
Dan Beam
2013/05/03 17:05:43
Done.
| |
| 398 # Version is the third parameter and consists of a quad of numbers separated | 404 if len(branches.keys()) == 1: |
|
Isaac (away)
2013/05/03 10:00:50
len(branches)
Dan Beam
2013/05/03 17:05:43
Done.
| |
| 399 # by periods. | 405 return branches.keys()[0] |
| 400 version = string.split(parameters[2], '.') | |
| 401 major = int(version[0], 10) | |
| 402 if major != milestone: | |
| 403 continue | |
| 404 | 406 |
| 405 # Branch number is the third value in the quad. | 407 choices = ('-(%s): %s' % (b, ', '.join(o)) for b, o in branches.iteritems()) |
| 406 branch_dict[version[2]] = major | 408 print >> sys.stderr, """ |
| 409 Not all platforms have same branch number for M%d. | |
| 407 | 410 |
| 408 if not branch_dict: | 411 Here's a list of platforms on each branch: |
| 409 # |milestone| not found. | 412 %s""" % (milestone, '\n'.join(choices)) |
| 410 print "Milestone provided is invalid" | |
| 411 return None | |
| 412 | 413 |
| 413 # The following returns a sorted list of the keys of |branch_dict|. | 414 errors = 0 |
| 414 sorted_branches = sorted(branch_dict) | 415 while errors < 3: |
| 415 branch = sorted_branches[-1] | 416 user_input = raw_input("Which branch? ('q' to cancel) ") |
|
Isaac (away)
2013/05/03 10:00:50
do you need to strip trailing newline?
Dan Beam
2013/05/03 17:05:43
Done. (no, I didn't need to in testing but it does
| |
| 417 if user_input in branches.keys(): | |
| 418 return branch | |
| 419 if user_input.lower().startswith('q'): | |
|
Isaac (away)
2013/05/03 10:00:50
how about also abort on empty input
Dan Beam
2013/05/03 17:05:43
I dislike this behavior as if you've pressed enter
| |
| 420 break | |
| 421 errors += 1 | |
| 416 | 422 |
| 417 # If all keys match, the branch is the same for all platforms given | |
| 418 # |milestone|. This is the safe case, so return the branch. | |
| 419 if len(sorted_branches) == 1: | |
| 420 return branch | |
| 421 | |
| 422 # Not all of the platforms have the same branch. Prompt the user and return | |
| 423 # the greatest (by value) branch on success. | |
| 424 if prompt("Not all platforms have the same branch number, " | |
| 425 "continue with branch %s?" % branch): | |
| 426 return branch | |
| 427 | |
| 428 # User cancelled. | |
| 429 return None | 423 return None |
| 430 | 424 |
| 431 | |
| 432 def getSVNAuthInfo(folder=None): | 425 def getSVNAuthInfo(folder=None): |
| 433 """Fetches SVN authorization information in the subversion auth folder and | 426 """Fetches SVN authorization information in the subversion auth folder and |
| 434 returns it as a dictionary of dictionaries.""" | 427 returns it as a dictionary of dictionaries.""" |
| 435 if not folder: | 428 if not folder: |
| 436 if sys.platform == 'win32': | 429 if sys.platform == 'win32': |
| 437 folder = '%%APPDATA%\\Subversion\\auth' | 430 folder = '%%APPDATA%\\Subversion\\auth' |
| 438 else: | 431 else: |
| 439 folder = '~/.subversion/auth' | 432 folder = '~/.subversion/auth' |
| 440 folder = os.path.expandvars(os.path.expanduser(folder)) | 433 folder = os.path.expandvars(os.path.expanduser(folder)) |
| 441 svn_simple_folder = os.path.join(folder, 'svn.simple') | 434 svn_simple_folder = os.path.join(folder, 'svn.simple') |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 708 |
| 716 if options.branch and options.milestone: | 709 if options.branch and options.milestone: |
| 717 option_parser.error("--branch cannot be used with --milestone") | 710 option_parser.error("--branch cannot be used with --milestone") |
| 718 return 1 | 711 return 1 |
| 719 | 712 |
| 720 return drover(options, args) | 713 return drover(options, args) |
| 721 | 714 |
| 722 | 715 |
| 723 if __name__ == "__main__": | 716 if __name__ == "__main__": |
| 724 sys.exit(main()) | 717 sys.exit(main()) |
| OLD | NEW |