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

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: Minor changes Created 7 years, 8 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 633c5f3a6df26ef1bd3c406f93adc4dca8da4c9b..2a7de28ee12275c292c85ab7629a29e5bc943aaa 100644
--- a/chrome/common/extensions/docs/server2/branch_utility.py
+++ b/chrome/common/extensions/docs/server2/branch_utility.py
@@ -23,9 +23,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
@@ -40,15 +48,26 @@ 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):
not at google - send to devlin 2013/04/30 18:34:19 Ok I think that the "ForChannelName" is tautologic
epeterson 2013/05/13 02:38:10 Done.
+ 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)
@@ -59,23 +78,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]

Powered by Google App Engine
This is Rietveld 408576698