| 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 import logging | 6 import logging |
| 7 import operator | 7 import operator |
| 8 | 8 |
| 9 from appengine_url_fetcher import AppEngineUrlFetcher | 9 from appengine_url_fetcher import AppEngineUrlFetcher |
| 10 import url_constants | 10 import url_constants |
| 11 | 11 |
| 12 class BranchUtility(object): | 12 class BranchUtility(object): |
| 13 def __init__(self, fetch_url, fetcher, object_store_creator): | 13 def __init__(self, fetch_url, fetcher, object_store_creator): |
| 14 self._fetch_url = fetch_url | 14 self._fetch_url = fetch_url |
| 15 self._fetcher = fetcher | 15 self._fetcher = fetcher |
| 16 # BranchUtility is obviously cross-channel, so set the channel to None. | 16 self._object_store = object_store_creator.Create(BranchUtility) |
| 17 self._object_store = object_store_creator.Create(BranchUtility, | |
| 18 channel=None) | |
| 19 | 17 |
| 20 @staticmethod | 18 @staticmethod |
| 21 def Create(object_store_creator): | 19 def Create(object_store_creator): |
| 22 return BranchUtility(url_constants.OMAHA_PROXY_URL, | 20 return BranchUtility(url_constants.OMAHA_PROXY_URL, |
| 23 AppEngineUrlFetcher(), | 21 AppEngineUrlFetcher(), |
| 24 object_store_creator) | 22 object_store_creator) |
| 25 | 23 |
| 26 @staticmethod | 24 @staticmethod |
| 27 def GetAllChannelNames(): | 25 def GetAllChannelNames(): |
| 28 return ['stable', 'beta', 'dev', 'trunk'] | 26 return ['stable', 'beta', 'dev', 'trunk'] |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 else: | 71 else: |
| 74 branch_numbers[branch] += 1 | 72 branch_numbers[branch] += 1 |
| 75 | 73 |
| 76 sorted_branches = sorted(branch_numbers.iteritems(), | 74 sorted_branches = sorted(branch_numbers.iteritems(), |
| 77 None, | 75 None, |
| 78 operator.itemgetter(1), | 76 operator.itemgetter(1), |
| 79 True) | 77 True) |
| 80 self._object_store.Set(channel_name, sorted_branches[0][0]) | 78 self._object_store.Set(channel_name, sorted_branches[0][0]) |
| 81 | 79 |
| 82 return sorted_branches[0][0] | 80 return sorted_branches[0][0] |
| OLD | NEW |