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

Side by Side Diff: chrome/common/extensions/docs/server2/branch_utility.py

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import logging 6 import logging
7 import operator 7 import operator
8 8
9 from appengine_wrappers import GetAppVersion 9 from appengine_url_fetcher import AppEngineUrlFetcher
10 from object_store_creator import ObjectStoreCreator 10 import url_constants
11 11
12 class BranchUtility(object): 12 class BranchUtility(object):
13 def __init__(self, fetch_url, fetcher, object_store=None): 13 def __init__(self, fetch_url, fetcher, object_store_creator):
14 self._fetch_url = fetch_url 14 self._fetch_url = fetch_url
15 self._fetcher = fetcher 15 self._fetcher = fetcher
16 if object_store is None: 16 # BranchUtility is obviously cross-channel, so set the channel to None.
17 object_store = (ObjectStoreCreator.SharedFactory(GetAppVersion()) 17 self._object_store = object_store_creator.Create(BranchUtility,
18 .Create(BranchUtility).Create()) 18 channel=None)
19 self._object_store = object_store
20 19
21 @staticmethod 20 @staticmethod
22 def GetAllBranchNames(): 21 def Create(object_store_creator):
22 return BranchUtility(url_constants.OMAHA_PROXY_URL,
23 AppEngineUrlFetcher(),
24 object_store_creator)
25
26 @staticmethod
27 def GetAllChannelNames():
23 return ['stable', 'beta', 'dev', 'trunk'] 28 return ['stable', 'beta', 'dev', 'trunk']
24 29
25 def GetAllBranchNumbers(self):
26 return [(branch, self.GetBranchNumberForChannelName(branch))
27 for branch in BranchUtility.GetAllBranchNames()]
28
29 @staticmethod 30 @staticmethod
30 def SplitChannelNameFromPath(path): 31 def SplitChannelNameFromPath(path):
31 """Splits the channel name out of |path|, returning the tuple 32 """Splits the channel name out of |path|, returning the tuple
32 (channel_name, real_path). If the channel cannot be determined then returns 33 (channel_name, real_path). If the channel cannot be determined then returns
33 (None, path). 34 (None, path).
34 """ 35 """
35 if '/' in path: 36 if '/' in path:
36 first, second = path.split('/', 1) 37 first, second = path.split('/', 1)
37 else: 38 else:
38 first, second = (path, '') 39 first, second = (path, '')
39 if first in ['trunk', 'dev', 'beta', 'stable']: 40 if first in ['trunk', 'dev', 'beta', 'stable']:
40 return (first, second) 41 return (first, second)
41 return (None, path) 42 return (None, path)
42 43
43 def GetBranchNumberForChannelName(self, channel_name): 44 def GetBranchForChannel(self, channel_name):
44 """Returns the branch number for a channel name. 45 """Returns the branch number for a channel name.
45 """ 46 """
46 if channel_name == 'trunk': 47 if channel_name == 'trunk':
47 return 'trunk' 48 return 'trunk'
48 49
49 branch_number = self._object_store.Get(channel_name).Get() 50 branch_number = self._object_store.Get(channel_name).Get()
50 if branch_number is not None: 51 if branch_number is not None:
51 return branch_number 52 return branch_number
52 53
53 try: 54 try:
(...skipping 18 matching lines...) Expand all
72 else: 73 else:
73 branch_numbers[branch] += 1 74 branch_numbers[branch] += 1
74 75
75 sorted_branches = sorted(branch_numbers.iteritems(), 76 sorted_branches = sorted(branch_numbers.iteritems(),
76 None, 77 None,
77 operator.itemgetter(1), 78 operator.itemgetter(1),
78 True) 79 True)
79 self._object_store.Set(channel_name, sorted_branches[0][0]) 80 self._object_store.Set(channel_name, sorted_branches[0][0])
80 81
81 return sorted_branches[0][0] 82 return sorted_branches[0][0]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698