Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import logging | |
| 6 import re | |
| 7 import json | |
| 8 | |
| 9 class BranchUtility(object): | |
| 10 """Utility class for dealing with different doc branches. | |
| 11 """ | |
| 12 def __init__(self, urlfetch): | |
| 13 self.url = 'http://omahaproxy.appspot.com/json' | |
|
Aaron Boodman
2012/05/24 06:10:23
Nit: omaha_proxy_url ?
cduvall
2012/05/25 20:02:23
Done.
| |
| 14 self.urlfetch = urlfetch | |
| 15 | |
| 16 def SetURL(self, url): | |
| 17 self.url = url | |
| 18 | |
| 19 def GetChannelNameFromPath(self, path): | |
| 20 first_part = path.split('/')[0] | |
| 21 if first_part in ['trunk', 'dev', 'beta', 'stable']: | |
| 22 return first_part | |
| 23 else: | |
| 24 return 'stable' | |
| 25 | |
| 26 def GetBranchNumberForChannelName(self, channel_name): | |
| 27 """Returns an empty string if the branch number cannot be found. | |
|
Aaron Boodman
2012/05/24 06:10:23
Add a commment: This can throw in case of network
cduvall
2012/05/25 20:02:23
Done.
| |
| 28 """ | |
| 29 if channel_name == 'trunk': | |
| 30 return 'trunk' | |
| 31 | |
| 32 fetch_data = self.urlfetch.fetch(self.url) | |
| 33 | |
| 34 version_json = json.loads(fetch_data.content) | |
| 35 branch_numbers = {} | |
| 36 for entry in version_json: | |
| 37 if entry['os'] not in ['win', 'linux', 'mac', 'cros']: | |
| 38 continue | |
| 39 for version in entry['versions']: | |
| 40 if version['channel'] != channel_name: | |
| 41 continue | |
| 42 if version['true_branch'] not in branch_numbers: | |
| 43 branch_numbers[version['true_branch']] = 0 | |
| 44 else: | |
| 45 branch_numbers[version['true_branch']] += 1 | |
| 46 | |
| 47 sorted_list = [x for x in branch_numbers.iteritems()] | |
|
Aaron Boodman
2012/05/24 06:10:23
cute
| |
| 48 sorted_list.sort(key = lambda x: x[1]) | |
| 49 sorted_list.reverse() | |
| 50 | |
| 51 branch_number = '' | |
| 52 if len(sorted_list) > 0: | |
|
Aaron Boodman
2012/05/24 06:10:23
I think you should throw earlier if you get zero r
cduvall
2012/05/25 20:02:23
Done.
| |
| 53 branch_number, _ = sorted_list[0] | |
| 54 | |
| 55 return branch_number | |
| OLD | NEW |