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