Chromium Code Reviews| Index: drover.py |
| =================================================================== |
| --- drover.py (revision 198133) |
| +++ drover.py (working copy) |
| @@ -3,11 +3,12 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import collections |
| import datetime |
| +import json |
| import optparse |
| import os |
| import re |
| -import string |
| import sys |
| import urllib2 |
| import urlparse |
| @@ -375,60 +376,54 @@ |
| def getBranchForMilestone(milestone): |
| """Queries omahaproxy.appspot.com for the branch number given |milestone|. |
| """ |
| - OMAHA_PROXY_URL = "http://omahaproxy.appspot.com/all?csv=1" |
| - request = urllib2.Request(OMAHA_PROXY_URL) |
| + OMAHA_PROXY_URL = "https://omahaproxy.appspot.com/all?json=1" |
| try: |
| - response = urllib2.urlopen(request) |
| + response = urllib2.urlopen(OMAHA_PROXY_URL) |
| except urllib2.HTTPError, e: |
| print "Failed to query %s: %d" % (OMAHA_PROXY_URL, e.code) |
| return None |
| - # Dictionary of [branch: major]. When searching for the appropriate branch |
| - # matching |milestone|, all major versions that match are added to the |
| - # dictionary. If all of the branches are the same, this branch value is |
| - # returned; otherwise, the user is prompted to accept the largest branch |
| - # value. |
| - branch_dict = {} |
| + # Response is in the form of: |
| + # [{ os: "os_name", versions: [{ channel: "canary", true_branch: "1490" }] }] |
| + os_versions = json.load(response) |
| - # Slice the first line since it's column information text. |
| - for line in response.readlines()[1:]: |
| - # Version data is CSV. |
| - parameters = string.split(line, ',') |
| + branches = collections.defaultdict(list) |
| + for os_version in os_versions: |
| + for version in os_version['versions']: |
| + if not version['true_branch'] or not version['version']: |
| + continue |
| + mstone = version['version'].split('.') |
| + if not mstone or mstone[0] != str(milestone): |
| + continue |
| + branch = version['true_branch'] |
| + if not branch[0].isdigit(): |
| + continue |
| + branches[branch] += [os_version['os']] |
| - # Version is the third parameter and consists of a quad of numbers separated |
| - # by periods. |
| - version = string.split(parameters[2], '.') |
| - major = int(version[0], 10) |
| - if major != milestone: |
| - continue |
| - |
| - # Branch number is the third value in the quad. |
| - branch_dict[version[2]] = major |
| - |
| - if not branch_dict: |
| - # |milestone| not found. |
| - print "Milestone provided is invalid" |
| + if not branches: |
| return None |
| - # The following returns a sorted list of the keys of |branch_dict|. |
| - sorted_branches = sorted(branch_dict) |
| - branch = sorted_branches[-1] |
| + if len(branches) == 1: |
| + return branches.keys()[0] |
| - # If all keys match, the branch is the same for all platforms given |
| - # |milestone|. This is the safe case, so return the branch. |
| - if len(sorted_branches) == 1: |
| - return branch |
| + choices = ('-(%s): %s' % (b, ', '.join(o)) for b, o in branches.iteritems()) |
| + 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.
|
| +Not all platforms have same branch number for M%d. |
| - # Not all of the platforms have the same branch. Prompt the user and return |
| - # the greatest (by value) branch on success. |
| - if prompt("Not all platforms have the same branch number, " |
| - "continue with branch %s?" % branch): |
| - return branch |
| +Here's a list of platforms on each branch: |
| +%s""" % (milestone, '\n'.join(choices)) |
| - # User cancelled. |
| + errors = 0 |
| + while errors < 3: |
| + user_input = raw_input("Which branch? ('q' to cancel) ").strip().lower() |
| + 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.
|
| + return branch |
| + if user_input.startswith('q'): |
| + break |
| + errors += 1 |
| + |
| return None |
| - |
| def getSVNAuthInfo(folder=None): |
| """Fetches SVN authorization information in the subversion auth folder and |
| returns it as a dictionary of dictionaries.""" |