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 optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import string | |
|
Dan Beam
2013/04/29 17:40:18
pylint was complaining that this wasn't used (whic
| |
| 11 import sys | 10 import sys |
| 12 import urllib2 | 11 import urllib2 |
| 13 import urlparse | 12 import urlparse |
| 14 | 13 |
| 15 import breakpad # pylint: disable=W0611 | 14 import breakpad # pylint: disable=W0611 |
| 16 | 15 |
| 17 import gclient_utils | 16 import gclient_utils |
| 18 import subprocess2 | 17 import subprocess2 |
| 18 import json | |
| 19 | 19 |
| 20 USAGE = """ | 20 USAGE = """ |
| 21 WARNING: Please use this tool in an empty directory | 21 WARNING: Please use this tool in an empty directory |
| 22 (or at least one that you don't mind clobbering.) | 22 (or at least one that you don't mind clobbering.) |
| 23 | 23 |
| 24 REQUIRES: SVN 1.5+ | 24 REQUIRES: SVN 1.5+ |
| 25 NOTE: NO NEED TO CHECKOUT ANYTHING IN ADVANCE OF USING THIS TOOL. | 25 NOTE: NO NEED TO CHECKOUT ANYTHING IN ADVANCE OF USING THIS TOOL. |
| 26 Valid parameters: | 26 Valid parameters: |
| 27 | 27 |
| 28 [Merge from trunk to branch] | 28 [Merge from trunk to branch] |
| (...skipping 339 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" |
| 379 request = urllib2.Request(OMAHA_PROXY_URL) | |
| 380 try: | 379 try: |
| 381 response = urllib2.urlopen(request) | 380 request = urllib2.urlopen(OMAHA_PROXY_URL) |
| 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) |
| 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 = {} |
| 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']: |
| 393 continue | |
| 394 mstone = version['version'].split('.') | |
| 395 if not mstone or mstone[0] != str(milestone): | |
| 396 continue | |
| 397 branch = version['true_branch'] | |
| 398 if not branch.isdigit(): | |
| 399 continue | |
| 400 if not branch in branches: | |
| 401 branches[branch] = [] | |
| 402 branches[branch] += [os_version['os']] | |
| 397 | 403 |
| 398 # Version is the third parameter and consists of a quad of numbers separated | 404 if len(branches.keys()) == 1: |
| 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 | |
| 412 | |
| 413 # The following returns a sorted list of the keys of |branch_dict|. | |
| 414 sorted_branches = sorted(branch_dict) | |
| 415 branch = sorted_branches[-1] | |
| 416 | |
| 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 | 405 return branch |
| 421 | 406 |
| 422 # Not all of the platforms have the same branch. Prompt the user and return | 407 print ('Not all platforms have same branch number for M%d.\n\n' |
| 423 # the greatest (by value) branch on success. | 408 'Here is a list of which platforms are on which branch:' % milestone) |
| 424 if prompt("Not all platforms have the same branch number, " | 409 choices = ('-(%s): %s' % (b, ', '.join(o)) for b, o in branches.iteritems()) |
| 425 "continue with branch %s?" % branch): | 410 print '\n'.join(choices) |
| 426 return branch | |
| 427 | 411 |
| 428 # User cancelled. | 412 errors = 0 |
| 429 return None | 413 while True: |
| 430 | 414 user_input = raw_input("Type the branch ('q' to cancel): ") |
| 415 if user_input in branches.keys(): | |
| 416 return branch | |
| 417 errors += 1 | |
| 418 if user_input.lower().startswith('q') or errors > 4: | |
| 419 return None | |
| 431 | 420 |
| 432 def getSVNAuthInfo(folder=None): | 421 def getSVNAuthInfo(folder=None): |
| 433 """Fetches SVN authorization information in the subversion auth folder and | 422 """Fetches SVN authorization information in the subversion auth folder and |
| 434 returns it as a dictionary of dictionaries.""" | 423 returns it as a dictionary of dictionaries.""" |
| 435 if not folder: | 424 if not folder: |
| 436 if sys.platform == 'win32': | 425 if sys.platform == 'win32': |
| 437 folder = '%%APPDATA%\\Subversion\\auth' | 426 folder = '%%APPDATA%\\Subversion\\auth' |
| 438 else: | 427 else: |
| 439 folder = '~/.subversion/auth' | 428 folder = '~/.subversion/auth' |
| 440 folder = os.path.expandvars(os.path.expanduser(folder)) | 429 folder = os.path.expandvars(os.path.expanduser(folder)) |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 704 |
| 716 if options.branch and options.milestone: | 705 if options.branch and options.milestone: |
| 717 option_parser.error("--branch cannot be used with --milestone") | 706 option_parser.error("--branch cannot be used with --milestone") |
| 718 return 1 | 707 return 1 |
| 719 | 708 |
| 720 return drover(options, args) | 709 return drover(options, args) |
| 721 | 710 |
| 722 | 711 |
| 723 if __name__ == "__main__": | 712 if __name__ == "__main__": |
| 724 sys.exit(main()) | 713 sys.exit(main()) |
| OLD | NEW |