Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 prefix = '' | |
| 19 if path.startswith('extensions/'): | |
| 20 prefix = 'extensions/' | |
| 21 path = path[len('extensions/'):] | |
| 22 elif path.startswith('apps/'): | |
| 23 prefix = 'apps/' | |
| 24 path = path[len('apps/'):] | |
|
not at google - send to devlin
2012/08/06 08:38:33
Is all of this necessary? The paths will be
http:
cduvall
2012/08/06 18:36:16
In the old docs, the branch came last. For example
| |
| 18 try: | 25 try: |
| 19 first, second = path.split('/', 1) | 26 first, second = path.split('/', 1) |
| 20 except ValueError: | 27 except ValueError: |
| 21 first = path | 28 first = path |
| 22 second = '' | 29 second = '' |
| 23 if first in ['trunk', 'dev', 'beta', 'stable']: | 30 if first in ['trunk', 'dev', 'beta', 'stable']: |
| 24 return (first, second) | 31 return (first, prefix + second) |
| 25 else: | 32 else: |
| 26 return (self._default_branch, path) | 33 return (self._default_branch, prefix + path) |
| 27 | 34 |
| 28 def GetBranchNumberForChannelName(self, channel_name): | 35 def GetBranchNumberForChannelName(self, channel_name): |
| 29 """Returns an empty string if the branch number cannot be found. | 36 """Returns an empty string if the branch number cannot be found. |
| 30 Throws exception on network errors. | 37 Throws exception on network errors. |
| 31 """ | 38 """ |
| 32 if channel_name in ['trunk', 'local']: | 39 if channel_name in ['trunk', 'local']: |
| 33 return channel_name | 40 return channel_name |
| 34 | 41 |
| 35 branch_number = self._memcache.Get(channel_name + '.' + self._base_path, | 42 branch_number = self._memcache.Get(channel_name + '.' + self._base_path, |
| 36 memcache.MEMCACHE_BRANCH_UTILITY) | 43 memcache.MEMCACHE_BRANCH_UTILITY) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 55 None, | 62 None, |
| 56 operator.itemgetter(1), | 63 operator.itemgetter(1), |
| 57 True) | 64 True) |
| 58 # Cache for 24 hours. | 65 # Cache for 24 hours. |
| 59 self._memcache.Set(channel_name + '.' + self._base_path, | 66 self._memcache.Set(channel_name + '.' + self._base_path, |
| 60 sorted_branches[0][0], | 67 sorted_branches[0][0], |
| 61 memcache.MEMCACHE_BRANCH_UTILITY, | 68 memcache.MEMCACHE_BRANCH_UTILITY, |
| 62 86400) | 69 86400) |
| 63 | 70 |
| 64 return sorted_branches[0][0] | 71 return sorted_branches[0][0] |
| OLD | NEW |