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 282c6a4e7bf33d86705dd8e5dccd73fdc6b19bf7..2dba7ea309374d0025dee15659655b6517db0847 100644 |
--- a/chrome/common/extensions/docs/server2/branch_utility.py |
+++ b/chrome/common/extensions/docs/server2/branch_utility.py |
@@ -21,9 +21,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()] |
+ |
@staticmethod |
def SplitChannelNameFromPath(path): |
"""Splits the channel name out of |path|, returning the tuple |
@@ -38,15 +46,22 @@ 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): |
+ return { |
+ 'name': channel, |
+ 'branch': self._ExtractFromVersionJson(channel, 'branch'), |
+ 'version': self._ExtractFromVersionJson(channel, 'version') |
+ } |
+ |
+ def _ExtractFromVersionJson(self, channel_name, data_type): |
+ """Returns the branch or version number for a channel name. |
""" |
if channel_name == 'trunk': |
return 'trunk' |
- branch_number = self._object_store.Get(channel_name).Get() |
- if branch_number is not None: |
- return branch_number |
+ data = self._object_store.Get('%s.%s' % (channel_name, data_type)).Get() |
+ if data is not None: |
+ return data |
try: |
version_json = json.loads(self._fetcher.Fetch(self._fetch_url).content) |
@@ -57,23 +72,27 @@ class BranchUtility(object): |
'Falling back to "trunk".' % e) |
return 'trunk' |
- 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 |
+ numbers[number] += 1 |
- sorted_branches = sorted(branch_numbers.iteritems(), |
- None, |
- operator.itemgetter(1), |
- True) |
- self._object_store.Set(channel_name, sorted_branches[0][0]) |
+ sorted_numbers = sorted(numbers.iteritems(), |
+ None, |
+ operator.itemgetter(1), |
+ True) |
+ self._object_store.Set('%s.%s' % (channel_name, data_type), |
+ sorted_numbers[0][0]) |
- return sorted_branches[0][0] |
+ return sorted_numbers[0][0] |