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

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

Issue 10387225: Die build.py, Die: Part 1 (BranchUtility and SubversionFetcher) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Final changes Created 8 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
new file mode 100644
index 0000000000000000000000000000000000000000..a395fc45c8b34c98099fa37f170799e28e9e2fc3
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/branch_utility.py
@@ -0,0 +1,56 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import re
+import json
+
+class BranchUtility(object):
+ """Utility class for dealing with different doc branches.
+ """
+ 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']:
+ 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':
+ return 'trunk'
+
+ 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']:
+ 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
+
+ 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]
+
+ return branch_number
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | chrome/common/extensions/docs/server2/branch_utility_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698