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

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: Created 7 years, 9 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 eb74846e4a5622013ec52c5f204a5c9281c791af..70b15d4106c450b16caa9a8a01db3b9c22a7b67d 100644
--- a/chrome/common/extensions/docs/server2/branch_utility.py
+++ b/chrome/common/extensions/docs/server2/branch_utility.py
@@ -15,10 +15,18 @@ class BranchUtility(object):
self._object_store = object_store
def GetAllBranchNames(self):
- return ['dev', 'beta', 'stable', 'trunk']
+ return ['stable', 'beta', 'dev', 'trunk']
def GetAllBranchNumbers(self):
- return [(branch, self.GetBranchNumberForChannelName(branch))
+ return [(branch, self.GetBranchAndVersionForChannelName(branch)['branch'])
+ for branch in self.GetAllBranchNames()]
+
+ def GetAllVersionNumbers(self):
+ return [self.GetBranchAndVersionForChannelName(branch)['version']
+ for branch in self.GetAllBranchNames()]
+
+ def GetBranchAndVersionForAllChannels(self):
+ return [self.GetBranchAndVersionForChannelName(branch)
for branch in self.GetAllBranchNames()]
def SplitChannelNameFromPath(self, path):
@@ -34,16 +42,26 @@ class BranchUtility(object):
return (first, second)
return (None, path)
- def GetBranchNumberForChannelName(self, channel_name):
- """Returns the branch number for a channel name.
+ def GetBranchAndVersionForChannelName(self, channel_name):
+ return {'name' : channel_name,
cduvall 2013/03/21 18:43:53 format like: return { 'name': channel_name, ..
epeterson 2013/03/25 19:35:11 Done.
+ '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'
+
+ data = self._object_store.Get(channel_name + '.' +
cduvall 2013/03/21 18:43:53 Use '%s.%s.%s'
epeterson 2013/03/25 19:35:11 Done.
+ self._base_path + '.' + data_type,
+ object_store.BRANCH_UTILITY).Get()
- 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
+ if data is not None:
+ return data
try:
version_json = json.loads(self._fetcher.Fetch(self._base_path).content)
@@ -52,27 +70,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 ''
epeterson 2013/03/25 19:35:11 return '0' -- done
- 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(),
+ numbers[number] += 1
+ sorted_numbers = sorted(numbers.iteritems(),
None,
operator.itemgetter(1),
True)
- self._object_store.Set(channel_name + '.' + self._base_path,
- sorted_branches[0][0],
+ self._object_store.Set(channel_name + '.' + self._base_path +
+ '.' + data_type,
+ sorted_numbers[0][0],
object_store.BRANCH_UTILITY)
- return sorted_branches[0][0]
+ return sorted_numbers[0][0]

Powered by Google App Engine
This is Rietveld 408576698