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

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

Issue 14856006: Docserver: achieve online vs offline (cron vs instance) behaviour at the object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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_wrappers import GetAppVersion
10 from object_store_creator import ObjectStoreCreator
11 10
12 class BranchUtility(object): 11 class BranchUtility(object):
13 def __init__(self, fetch_url, fetcher, object_store=None): 12 def __init__(self, fetch_url, fetcher, object_store_creator_factory):
14 self._fetch_url = fetch_url 13 self._fetch_url = fetch_url
15 self._fetcher = fetcher 14 self._fetcher = fetcher
16 if object_store is None: 15 self._object_store = (object_store_creator_factory.Create(BranchUtility)
17 object_store = (ObjectStoreCreator.SharedFactory(GetAppVersion()) 16 .Create())
18 .Create(BranchUtility).Create())
19 self._object_store = object_store
20 17
21 @staticmethod 18 @staticmethod
22 def GetAllBranchNames(): 19 def GetAllBranchNames():
23 return ['stable', 'beta', 'dev', 'trunk'] 20 return ['stable', 'beta', 'dev', 'trunk']
24 21
25 def GetAllBranchNumbers(self): 22 def GetAllBranchNumbers(self):
26 return [(branch, self.GetBranchNumberForChannelName(branch)) 23 return [(branch, self.GetBranchNumberForChannelName(branch))
27 for branch in BranchUtility.GetAllBranchNames()] 24 for branch in BranchUtility.GetAllBranchNames()]
28 25
29 @staticmethod 26 @staticmethod
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 else: 69 else:
73 branch_numbers[branch] += 1 70 branch_numbers[branch] += 1
74 71
75 sorted_branches = sorted(branch_numbers.iteritems(), 72 sorted_branches = sorted(branch_numbers.iteritems(),
76 None, 73 None,
77 operator.itemgetter(1), 74 operator.itemgetter(1),
78 True) 75 True)
79 self._object_store.Set(channel_name, sorted_branches[0][0]) 76 self._object_store.Set(channel_name, sorted_branches[0][0])
80 77
81 return sorted_branches[0][0] 78 return sorted_branches[0][0]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698