Index: chrome/common/extensions/docs/server2/branch_utility.py |
diff --git a/chrome/common/extensions/docs/server2/branch_utility.py b/chrome/common/extensions/docs/server2/branch_utility.py |
index adfb38eae66d456dc4f062e83355aec49de9b72d..b120b92b904951d570907e034bf599a43c9dee50 100644 |
--- a/chrome/common/extensions/docs/server2/branch_utility.py |
+++ b/chrome/common/extensions/docs/server2/branch_utility.py |
@@ -19,9 +19,17 @@ class BranchUtility(object): |
return ['stable', 'beta', 'dev', 'trunk'] |
def GetAllBranchNumbers(self): |
- return [(branch, self.GetBranchNumberForChannelName(branch)) |
+ return [(branch, self.GetChannelInfoForChannelName(branch)['branch']) |
for branch in BranchUtility.GetAllBranchNames()] |
+ def GetAllVersionNumbers(self): |
+ return [self.GetChannelInfoForChannelName(branch)['version'] |
+ for branch in self.GetAllBranchNames()] |
+ |
+ def GetChannelInfoForAllChannels(self): |
+ return [self.GetChannelInfoForChannelName(branch) |
+ for branch in self.GetAllBranchNames()] |
+ |
def SplitChannelNameFromPath(self, path): |
"""Splits the channel name out of |path|, returning the tuple |
(channel_name, real_path). If the channel cannot be determined then returns |
@@ -35,16 +43,27 @@ class BranchUtility(object): |
return (first, second) |
return (None, path) |
- def GetBranchNumberForChannelName(self, channel_name): |
- """Returns the branch number for a channel name. |
+ def GetChannelInfoForChannelName(self, channel_name): |
+ return { |
+ 'name': channel_name, |
+ 'branch': self._ExtractFromVersionJson(channel_name, 'branch'), |
+ 'version': self._ExtractFromVersionJson(channel_name, 'version') |
+ } |
+ |
+ def _ExtractFromVersionJson(self, channel_name, data_type): |
+ """Returns the branch or version number for a channel name. |
""" |
if channel_name == 'trunk': |
- return 'trunk' |
+ if data_type == 'branch': |
+ return 'trunk' |
+ elif data_type == 'version': |
+ return '0' |
- branch_number = self._object_store.Get(channel_name + '.' + self._base_path, |
- object_store.BRANCH_UTILITY).Get() |
- if branch_number is not None: |
- return branch_number |
+ data = self._object_store.Get( |
+ '%s.%s.%s' % (channel_name, self._base_path, data_type), |
+ object_store.BRANCH_UTILITY).Get() |
+ if data is not None: |
+ return data |
try: |
version_json = json.loads(self._fetcher.Fetch(self._base_path).content) |
@@ -53,27 +72,33 @@ class BranchUtility(object): |
# Quick hack fix: just serve from trunk until it's fixed. |
logging.error('Failed to fetch or parse branch from omahaproxy: %s! ' |
'Falling back to "trunk".' % e) |
- return 'trunk' |
+ if data_type == 'branch': |
+ return 'trunk' |
+ elif data_type == 'version': |
+ return '0' |
- branch_numbers = {} |
+ numbers = {} |
for entry in version_json: |
if entry['os'] not in ['win', 'linux', 'mac', 'cros']: |
continue |
for version in entry['versions']: |
if version['channel'] != channel_name: |
continue |
- branch = version['version'].split('.')[2] |
- if branch not in branch_numbers: |
- branch_numbers[branch] = 0 |
+ if data_type == 'branch': |
+ number = version['version'].split('.')[2] |
+ elif data_type == 'version': |
+ number = version['version'].split('.')[0] |
+ if number not in numbers: |
+ numbers[number] = 0 |
else: |
- branch_numbers[branch] += 1 |
- |
- sorted_branches = sorted(branch_numbers.iteritems(), |
- None, |
- operator.itemgetter(1), |
- True) |
- self._object_store.Set(channel_name + '.' + self._base_path, |
- sorted_branches[0][0], |
+ numbers[number] += 1 |
+ sorted_numbers = sorted(numbers.iteritems(), |
+ None, |
+ operator.itemgetter(1), |
+ True) |
+ self._object_store.Set(channel_name + '.' + self._base_path + |
cduvall
2013/03/25 22:59:43
Use %s style string
epeterson
2013/03/27 22:36:09
Done.
|
+ '.' + data_type, |
+ sorted_numbers[0][0], |
object_store.BRANCH_UTILITY) |
- return sorted_branches[0][0] |
+ return sorted_numbers[0][0] |