Chromium Code Reviews| Index: drover.py |
| =================================================================== |
| --- drover.py (revision 109172) |
| +++ drover.py (working copy) |
| @@ -6,7 +6,9 @@ |
| import optparse |
| import os |
| import re |
| +import string |
| import sys |
| +import urllib2 |
| import breakpad # pylint: disable=W0611 |
| @@ -25,6 +27,10 @@ |
| --merge <revision> --branch <branch_num> |
| Example: %(app)s --merge 12345 --branch 187 |
| +[Merge from trunk to milestone] |
| +--merge <revision> --milestone <milestone_num> |
| +Example: %(app)s -- merge 12345 --milestone 16 |
| + |
| [Merge from trunk to local copy] |
| --merge <revision> --local |
| Example: %(app)s --merge 12345 --local |
| @@ -357,6 +363,37 @@ |
| """ |
| return ['%s/%s' % (f[2], f[3]) for f in files_info] |
| +def getBranchForMilestone(milestone): |
| + """Queries omahaproxy.appspot.com for the branch number given |milestone|. |
| + """ |
| + OMAHA_PROXY_URL = "http://omahaproxy.appspot.com" |
| + request = urllib2.Request(OMAHA_PROXY_URL) |
| + try: |
| + response = urllib2.urlopen(request) |
| + except urllib2.HTTPError, e: |
| + print "Failed to query %s: %d" % (OMAHA_PROXY_URL, e.code) |
| + return None |
| + |
| + # Slice the first line since it's column information text. |
| + for line in response.readlines()[1:]: |
|
laforge
2011/11/09 05:06:12
This approach is a little dangerous, but will prob
James Hawkins
2011/11/10 03:37:36
There are two separate things we can do here:
* De
|
| + # Version data is CSV. |
| + parameters = string.split(line, ',') |
| + |
| + # Milestone is the third parameter. |
| + full_milestone = parameters[2] |
|
laforge
2011/11/09 05:06:12
It would probably be clearer to call this var vers
James Hawkins
2011/11/10 03:37:36
Done.
|
| + |
| + # Full milestone is a quad of numbers separated by periods. |
| + milestone_str = string.split(full_milestone, '.')[0] |
| + if int(milestone_str, 10) != milestone: |
| + continue |
| + |
| + # Correct milestone found. Return the branch parameter, which is last. |
| + return parameters[len(parameters) - 1] |
|
laforge
2011/11/09 05:06:12
It would be better here to return full_mstone.spli
James Hawkins
2011/11/10 03:37:36
Done.
|
| + |
| + # Milestone not found. |
| + print "Milestone provided is invalid" |
| + return None |
| + |
| def prompt(question): |
| while True: |
| print question + " [y|n]:", |
| @@ -386,6 +423,12 @@ |
| SKIP_CHECK_WORKING = True |
| PROMPT_FOR_AUTHOR = False |
| + # Translate a given milestone to the appropriate branch number. |
| + if options.milestone: |
| + options.branch = getBranchForMilestone(options.milestone) |
| + if options.branch is None: |
| + return 1 |
| + |
| DEFAULT_WORKING = "drover_" + str(revision) |
| if options.branch: |
| DEFAULT_WORKING += ("_" + options.branch) |
| @@ -522,6 +565,8 @@ |
| help='Revision to merge from trunk to branch') |
| option_parser.add_option('-b', '--branch', |
| help='Branch to revert or merge from') |
| + option_parser.add_option('-M', '--milestone', type="int", |
| + help='Milestone to revert or merge from') |
| option_parser.add_option('-l', '--local', action='store_true', |
| help='Local working copy to merge to') |
| option_parser.add_option('-s', '--sbranch', |
| @@ -543,14 +588,19 @@ |
| option_parser.error("You need at least --merge or --revert") |
| return 1 |
| - if options.merge and not options.branch and not options.local: |
| + if (options.merge and not options.branch and not options.milestone and |
| + not options.local): |
| option_parser.error("--merge requires either --branch or --local") |
| return 1 |
| - if options.local and (options.revert or options.branch): |
| + if options.local and (options.revert or options.branch or options.milestone): |
| option_parser.error("--local cannot be used with --revert or --branch") |
| return 1 |
| + if options.branch and options.milestone: |
| + option_parser.error("--branch cannot be used with --milestone") |
| + return 1 |
| + |
| return drover(options, args) |