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

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

Issue 10545043: Extensions docs server: Design changes, partial template support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made suggested changes Created 8 years, 6 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 5d386ebba205ed1d7b7c3e787651d9209ba9f7ef..795e62f35b56c34aae9b1c1dcb124db3a7aca264 100644
--- a/chrome/common/extensions/docs/server2/branch_utility.py
+++ b/chrome/common/extensions/docs/server2/branch_utility.py
@@ -3,54 +3,47 @@
# found in the LICENSE file.
import logging
-import re
import json
-class BranchUtility(object):
- """Utility class for dealing with different doc branches.
+OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json'
+
+def GetChannelNameFromPath(path):
+ first_part = path.split('/')[0]
+ if first_part in ['trunk', 'dev', 'beta', 'stable', 'local']:
+ return first_part
+ else:
+ return 'stable'
+
+def GetBranchNumberForChannelName(channel_name,
+ urlfetch,
+ base_path=OMAHA_PROXY_URL):
+ """Returns an empty string if the branch number cannot be found.
+ Throws exception on network errors.
"""
- def __init__(self, urlfetch):
- self.omaha_proxy_url = 'http://omahaproxy.appspot.com/json'
- self.urlfetch = urlfetch
-
- def SetURL(self, url):
- self.omaha_proxy_url = url
-
- def GetChannelNameFromPath(self, path):
- first_part = path.split('/')[0]
- if first_part in ['trunk', 'dev', 'beta', 'stable', 'local']:
- return first_part
- else:
- return 'stable'
-
- def GetBranchNumberForChannelName(self, channel_name):
- """Returns an empty string if the branch number cannot be found.
- Throws exception on network errors.
- """
- if channel_name == 'trunk' or channel_name == 'local':
- return channel_name
-
- fetch_data = self.urlfetch.fetch(self.omaha_proxy_url)
- if fetch_data.content == '':
- raise Exception('Fetch returned zero results.')
-
- version_json = json.loads(fetch_data.content)
- branch_numbers = {}
- for entry in version_json:
- if entry['os'] not in ['win', 'linux', 'mac', 'cros']:
+ if channel_name == 'trunk' or channel_name == 'local':
+ return channel_name
+
+ fetch_data = urlfetch.fetch(base_path)
+ if fetch_data.content == '':
+ raise Exception('Fetch returned zero results.')
+
+ version_json = json.loads(fetch_data.content)
+ branch_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
- for version in entry['versions']:
- if version['channel'] != channel_name:
- continue
- if version['true_branch'] not in branch_numbers:
- branch_numbers[version['true_branch']] = 0
- else:
- branch_numbers[version['true_branch']] += 1
+ if version['true_branch'] not in branch_numbers:
+ branch_numbers[version['true_branch']] = 0
+ else:
+ branch_numbers[version['true_branch']] += 1
- sorted_list = [x for x in branch_numbers.iteritems()]
- sorted_list.sort(key = lambda x: x[1])
- sorted_list.reverse()
+ sorted_list = [x for x in branch_numbers.iteritems()]
+ sorted_list.sort(key = lambda x: x[1])
+ sorted_list.reverse()
- branch_number, _ = sorted_list[0]
+ branch_number, _ = sorted_list[0]
- return branch_number
+ return branch_number

Powered by Google App Engine
This is Rietveld 408576698