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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import logging
6 import re
7 import json
8
9 class BranchUtility(object):
10 """Utility class for dealing with different doc branches.
11 """
12 def __init__(self, urlfetch):
13 self.omaha_proxy_url = 'http://omahaproxy.appspot.com/json'
14 self.urlfetch = urlfetch
15
16 def SetURL(self, url):
17 self.omaha_proxy_url = url
18
19 def GetChannelNameFromPath(self, path):
20 first_part = path.split('/')[0]
21 if first_part in ['trunk', 'dev', 'beta', 'stable']:
22 return first_part
23 else:
24 return 'stable'
25
26 def GetBranchNumberForChannelName(self, channel_name):
27 """Returns an empty string if the branch number cannot be found.
28 Throws exception on network errors.
29 """
30 if channel_name == 'trunk':
31 return 'trunk'
32
33 fetch_data = self.urlfetch.fetch(self.omaha_proxy_url)
34 if fetch_data.content == '':
35 raise Exception('Fetch returned zero results.')
36
37 version_json = json.loads(fetch_data.content)
38 branch_numbers = {}
39 for entry in version_json:
40 if entry['os'] not in ['win', 'linux', 'mac', 'cros']:
41 continue
42 for version in entry['versions']:
43 if version['channel'] != channel_name:
44 continue
45 if version['true_branch'] not in branch_numbers:
46 branch_numbers[version['true_branch']] = 0
47 else:
48 branch_numbers[version['true_branch']] += 1
49
50 sorted_list = [x for x in branch_numbers.iteritems()]
51 sorted_list.sort(key = lambda x: x[1])
52 sorted_list.reverse()
53
54 branch_number, _ = sorted_list[0]
55
56 return branch_number
OLDNEW
« 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