Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4927)

Unified Diff: chrome/common/extensions/docs/server2/branch_utility.py

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revisions, Offline/Online Access (bypassed-hooks) Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0dd43d102637f061a065074980889ebebb71a404..44a099ce854ad3491740012b089a13264cd32aa1 100644
--- a/chrome/common/extensions/docs/server2/branch_utility.py
+++ b/chrome/common/extensions/docs/server2/branch_utility.py
@@ -18,16 +18,34 @@ class BranchUtility(object):
channel=None)
@staticmethod
+ def GetAllChannelNames():
+ return ['stable', 'beta', 'dev', 'trunk']
not at google - send to devlin 2013/05/13 21:26:41 cleanup: use a tuple here not a list. my bad from
epeterson 2013/05/15 07:38:34 Done.
+
+ def GetAllBranchNumbers(self):
+ return [(branch, self.GetChannelInfoForChannelName(branch).branch)
+ for branch in BranchUtility.GetAllChannelNames()]
+
+ def GetAllVersionNumbers(self):
+ return [self.GetChannelInfoForChannelName(branch).version
+ for branch in self.GetAllChannelNames()]
+
+ def GetChannelInfoForAllChannels(self):
+ return [self.GetChannelInfoForChannelName(branch)
+ for branch in self.GetAllChannelNames()]
+
+ @staticmethod
+ def NewestChannel(channels):
+ for channel in ['trunk', 'dev', 'beta', 'stable']:
not at google - send to devlin 2013/05/13 21:26:41 for channel in reversed(BranchUtility.GetAllChanne
epeterson 2013/05/15 07:38:34 Done.
+ if channel in channels:
+ return channel
+
+ @staticmethod
def Create(object_store_creator):
return BranchUtility(url_constants.OMAHA_PROXY_URL,
AppEngineUrlFetcher(),
object_store_creator)
@staticmethod
- def GetAllChannelNames():
- return ['stable', 'beta', 'dev', 'trunk']
-
- @staticmethod
def SplitChannelNameFromPath(path):
"""Splits the channel name out of |path|, returning the tuple
(channel_name, real_path). If the channel cannot be determined then returns
@@ -41,15 +59,26 @@ class BranchUtility(object):
return (first, second)
return (None, path)
- def GetBranchForChannel(self, channel_name):
- """Returns the branch number for a channel name.
+ def GetChannelInfo(self, channel):
+ class ChannelInfo(object):
+ def __init__(self, name, branch, version):
+ self.name = name
+ self.branch = branch
+ self.version = version
+
+ return ChannelInfo(channel,
+ self._ExtractFromVersionJson(channel, 'branch'),
+ 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)
@@ -60,23 +89,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),
not at google - send to devlin 2013/05/13 21:26:41 use two separate object stores with different cate
+ sorted_numbers[0][0])
- return sorted_branches[0][0]
+ return sorted_numbers[0][0]

Powered by Google App Engine
This is Rietveld 408576698