Index: drover.py |
=================================================================== |
--- drover.py (revision 197065) |
+++ drover.py (working copy) |
@@ -7,7 +7,6 @@ |
import optparse |
import os |
import re |
-import string |
Dan Beam
2013/04/29 17:40:18
pylint was complaining that this wasn't used (whic
|
import sys |
import urllib2 |
import urlparse |
@@ -16,6 +15,7 @@ |
import gclient_utils |
import subprocess2 |
+import json |
USAGE = """ |
WARNING: Please use this tool in an empty directory |
@@ -375,60 +375,49 @@ |
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 = "http://omahaproxy.appspot.com/all?json=1" |
try: |
- response = urllib2.urlopen(request) |
+ request = 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" }] }] |
+ response = json.load(request) |
- # 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 = {} |
+ for os_version in response: |
+ 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.isdigit(): |
+ continue |
+ if not branch in branches: |
+ branches[branch] = [] |
+ 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" |
- return None |
- |
- # The following returns a sorted list of the keys of |branch_dict|. |
- sorted_branches = sorted(branch_dict) |
- branch = sorted_branches[-1] |
- |
- # 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: |
+ if len(branches.keys()) == 1: |
return branch |
- # 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 |
+ print ('Not all platforms have same branch number for M%d.\n\n' |
+ 'Here is a list of which platforms are on which branch:' % milestone) |
+ choices = ('-(%s): %s' % (b, ', '.join(o)) for b, o in branches.iteritems()) |
+ print '\n'.join(choices) |
- # User cancelled. |
- return None |
+ errors = 0 |
+ while True: |
+ user_input = raw_input("Type the branch ('q' to cancel): ") |
+ if user_input in branches.keys(): |
+ return branch |
+ errors += 1 |
+ if user_input.lower().startswith('q') or errors > 4: |
+ return None |
- |
def getSVNAuthInfo(folder=None): |
"""Fetches SVN authorization information in the subversion auth folder and |
returns it as a dictionary of dictionaries.""" |