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 branch = version['true_branch'] |
| 396 mstone = version['version'].split('.') |
| 397 if not branch[0].isdigit() or mstone[0] != str(milestone): |
| 398 continue |
| 399 branches[branch] += [os_version['os']] |
397 | 400 |
398 # Version is the third parameter and consists of a quad of numbers separated | 401 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 | 402 return None |
412 | 403 |
413 # The following returns a sorted list of the keys of |branch_dict|. | 404 if len(branches) == 1: |
414 sorted_branches = sorted(branch_dict) | 405 return branches.keys()[0] |
415 branch = sorted_branches[-1] | |
416 | 406 |
417 # If all keys match, the branch is the same for all platforms given | 407 choices = ('-(%s): %s' % (b, ', '.join(o)) for b, o in branches.iteritems()) |
418 # |milestone|. This is the safe case, so return the branch. | 408 print >> sys.stderr, ("\nNot all platforms have same branch number for M%d.\n" |
419 if len(sorted_branches) == 1: | 409 "\nHere's a list of platforms on each branch:\n" |
420 return branch | 410 "%s") % (milestone, '\n'.join(choices)) |
421 | 411 |
422 # Not all of the platforms have the same branch. Prompt the user and return | 412 errors = 0 |
423 # the greatest (by value) branch on success. | 413 while errors < 3: |
424 if prompt("Not all platforms have the same branch number, " | 414 user_input = raw_input("Which branch? ('q' to cancel) ").strip().lower() |
425 "continue with branch %s?" % branch): | 415 if user_input in branches: |
426 return branch | 416 return user_input |
| 417 if user_input.startswith('q'): |
| 418 break |
| 419 errors += 1 |
427 | 420 |
428 # User cancelled. | |
429 return None | 421 return None |
430 | 422 |
431 | |
432 def getSVNAuthInfo(folder=None): | 423 def getSVNAuthInfo(folder=None): |
433 """Fetches SVN authorization information in the subversion auth folder and | 424 """Fetches SVN authorization information in the subversion auth folder and |
434 returns it as a dictionary of dictionaries.""" | 425 returns it as a dictionary of dictionaries.""" |
435 if not folder: | 426 if not folder: |
436 if sys.platform == 'win32': | 427 if sys.platform == 'win32': |
437 folder = '%%APPDATA%\\Subversion\\auth' | 428 folder = '%%APPDATA%\\Subversion\\auth' |
438 else: | 429 else: |
439 folder = '~/.subversion/auth' | 430 folder = '~/.subversion/auth' |
440 folder = os.path.expandvars(os.path.expanduser(folder)) | 431 folder = os.path.expandvars(os.path.expanduser(folder)) |
441 svn_simple_folder = os.path.join(folder, 'svn.simple') | 432 svn_simple_folder = os.path.join(folder, 'svn.simple') |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 | 706 |
716 if options.branch and options.milestone: | 707 if options.branch and options.milestone: |
717 option_parser.error("--branch cannot be used with --milestone") | 708 option_parser.error("--branch cannot be used with --milestone") |
718 return 1 | 709 return 1 |
719 | 710 |
720 return drover(options, args) | 711 return drover(options, args) |
721 | 712 |
722 | 713 |
723 if __name__ == "__main__": | 714 if __name__ == "__main__": |
724 sys.exit(main()) | 715 sys.exit(main()) |
OLD | NEW |