Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 | 6 |
| 7 OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json' | 7 OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json' |
| 8 | 8 |
| 9 def SplitChannelNameFromPath(path, default='stable'): | 9 def SplitChannelNameFromPath(path, default='stable'): |
| 10 try: | 10 try: |
| 11 first, second = path.split('/', 1) | 11 first, second = path.split('/', 1) |
| 12 except ValueError: | 12 except ValueError: |
| 13 first = path | 13 first = path |
| 14 second ='' | 14 second = '' |
| 15 if first in ['trunk', 'dev', 'beta', 'stable']: | 15 if first in ['trunk', 'dev', 'beta', 'stable']: |
| 16 return (first, second) | 16 return (first, second) |
| 17 else: | 17 else: |
| 18 return (default, path) | 18 return (default, path) |
| 19 | 19 |
| 20 def GetBranchNumberForChannelName(channel_name, | 20 def GetBranchNumberForChannelName(channel_name, |
| 21 urlfetch, | 21 urlfetch, |
| 22 base_path=OMAHA_PROXY_URL): | 22 base_path=OMAHA_PROXY_URL): |
| 23 """Returns an empty string if the branch number cannot be found. | 23 """Returns an empty string if the branch number cannot be found. |
| 24 Throws exception on network errors. | 24 Throws exception on network errors. |
| 25 """ | 25 """ |
| 26 if channel_name == 'trunk' or channel_name == 'local': | 26 if channel_name == 'trunk' or channel_name == 'local': |
| 27 return channel_name | 27 return channel_name |
|
not at google - send to devlin
2012/07/18 10:39:15
I posit that this isn't a number
(just sayin)
cduvall
2012/07/18 21:26:10
It could be something like "1180_38" which isn't r
| |
| 28 | 28 |
| 29 fetch_data = urlfetch.fetch(base_path) | 29 fetch_data = urlfetch.fetch(base_path) |
|
not at google - send to devlin
2012/07/18 10:39:15
The result of this fetch should be cached. Just me
cduvall
2012/07/18 21:26:10
Done.
| |
| 30 if fetch_data.content == '': | 30 if fetch_data.content == '': |
| 31 raise Exception('Fetch returned zero results.') | 31 raise Exception('Fetch returned zero results.') |
|
not at google - send to devlin
2012/07/18 10:39:15
It'd crash anyway with an invalid JSON thing, so c
cduvall
2012/07/18 21:26:10
Done.
| |
| 32 | 32 |
| 33 version_json = json.loads(fetch_data.content) | 33 version_json = json.loads(fetch_data.content) |
| 34 branch_numbers = {} | 34 branch_numbers = {} |
| 35 for entry in version_json: | 35 for entry in version_json: |
| 36 if entry['os'] not in ['win', 'linux', 'mac', 'cros']: | 36 if entry['os'] not in ['win', 'linux', 'mac', 'cros']: |
| 37 continue | 37 continue |
| 38 for version in entry['versions']: | 38 for version in entry['versions']: |
| 39 if version['channel'] != channel_name: | 39 if version['channel'] != channel_name: |
| 40 continue | 40 continue |
| 41 if version['true_branch'] not in branch_numbers: | 41 if version['true_branch'] not in branch_numbers: |
| 42 branch_numbers[version['true_branch']] = 0 | 42 branch_numbers[version['true_branch']] = 0 |
| 43 else: | 43 else: |
| 44 branch_numbers[version['true_branch']] += 1 | 44 branch_numbers[version['true_branch']] += 1 |
| 45 | 45 |
| 46 sorted_list = [x for x in branch_numbers.iteritems()] | 46 sorted_list = [x for x in branch_numbers.iteritems()] |
|
not at google - send to devlin
2012/07/18 10:39:15
x for x in blah... isn't that just blah?
If you'r
cduvall
2012/07/18 21:26:10
Wow this was ugly. I haven't looked at it since I
| |
| 47 sorted_list.sort(key = lambda x: x[1]) | 47 sorted_list.sort(key = lambda x: x[1]) |
|
not at google - send to devlin
2012/07/18 10:39:15
key=itemgetter(1)
cduvall
2012/07/18 21:26:10
Done.
| |
| 48 sorted_list.reverse() | 48 sorted_list.reverse() |
| 49 | 49 |
| 50 branch_number, _ = sorted_list[0] | 50 branch_number, _ = sorted_list[0] |
| 51 | 51 |
| 52 return branch_number | 52 return branch_number |
| OLD | NEW |