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

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

Issue 10831269: Extensions Docs Server: BranchUtility not fetching branch numbers correctly (fixed) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 6
7 import appengine_memcache as memcache 7 import appengine_memcache as memcache
8 import operator 8 import operator
9 9
10 class BranchUtility(object): 10 class BranchUtility(object):
11 def __init__(self, base_path, default_branch, fetcher, memcache): 11 def __init__(self, base_path, default_branch, fetcher, memcache):
12 self._base_path = base_path 12 self._base_path = base_path
13 self._default_branch = default_branch 13 self._default_branch = default_branch
14 self._fetcher = fetcher 14 self._fetcher = fetcher
15 self._memcache = memcache 15 self._memcache = memcache
16 16
17 def SplitChannelNameFromPath(self, path): 17 def SplitChannelNameFromPath(self, path):
18 try: 18 try:
19 first, second = path.split('/', 1) 19 first, second = path.split('/', 1)
20 except ValueError: 20 except ValueError:
21 first = path 21 first = path
22 second = '' 22 second = ''
23 if first in ['trunk', 'dev', 'beta', 'stable']: 23 if first in ['trunk', 'dev', 'beta', 'stable']:
24 return (first, second) 24 return (first, second)
25 else: 25 else:
26 return (self._default_branch, path) 26 return (self._default_branch, path)
27 27
28 def GetBranchNumberForChannelName(self, channel_name): 28 def GetBranchNumberForChannelName(self, channel_name):
29 """Returns an empty string if the branch number cannot be found. 29 """Returns the branch number for a channel name. If the |channel_name| is
30 Throws exception on network errors. 30 'trunk' or 'local', then |channel_name| will be returned unchanged.
not at google - send to devlin 2012/08/13 00:53:00 "... because..."
cduvall 2012/08/13 21:45:04 Done.
31 """ 31 """
32 if channel_name in ['trunk', 'local']: 32 if channel_name in ['trunk', 'local']:
33 return channel_name 33 return channel_name
34 34
35 branch_number = self._memcache.Get(channel_name + '.' + self._base_path, 35 branch_number = self._memcache.Get(channel_name + '.' + self._base_path,
36 memcache.MEMCACHE_BRANCH_UTILITY) 36 memcache.MEMCACHE_BRANCH_UTILITY)
37 if branch_number is not None: 37 if branch_number is not None:
38 return branch_number 38 return branch_number
39 39
40 fetch_data = self._fetcher.Fetch(self._base_path).content 40 fetch_data = self._fetcher.Fetch(self._base_path).content
(...skipping 11 matching lines...) Expand all
52 branch_numbers[version['true_branch']] += 1 52 branch_numbers[version['true_branch']] += 1
53 53
54 sorted_branches = sorted(branch_numbers.iteritems(), 54 sorted_branches = sorted(branch_numbers.iteritems(),
55 None, 55 None,
56 operator.itemgetter(1), 56 operator.itemgetter(1),
57 True) 57 True)
58 # Cache for 24 hours. 58 # Cache for 24 hours.
59 self._memcache.Set(channel_name + '.' + self._base_path, 59 self._memcache.Set(channel_name + '.' + self._base_path,
60 sorted_branches[0][0], 60 sorted_branches[0][0],
61 memcache.MEMCACHE_BRANCH_UTILITY, 61 memcache.MEMCACHE_BRANCH_UTILITY,
62 86400) 62 time=86400)
63 63
64 return sorted_branches[0][0] 64 return sorted_branches[0][0]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698