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

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

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 from cache_chain_object_store import CacheChainObjectStore 5 from cache_chain_object_store import CacheChainObjectStore
6 from memcache_object_store import MemcacheObjectStore 6 from memcache_object_store import MemcacheObjectStore
7 from persistent_object_store import PersistentObjectStore 7 from persistent_object_store import PersistentObjectStore
8 8
9 class ObjectStoreCreator(object): 9 class ObjectStoreCreator(object):
10 class Factory(object): 10 class Factory(object):
11 '''Parameters: 11 '''Parameters:
12 - |branch| The branch to create object stores for. This becomes part of the 12 - |branch| The branch to create object stores for. This becomes part of the
13 namespace for the object stores that are created. 13 namespace for the object stores that are created.
14 - |start_empty| Whether the caching object store that gets created should 14 - |start_empty| Whether the caching object store that gets created should
15 start empty, or start with the content of its delegate object stores. 15 start empty, or start with the content of its delegate object stores.
16 - |persistent| Whether the caching object store is persistent.
17 - |more| A dictionary containing other information to include in the
18 namespace.
16 ''' 19 '''
17 def __init__(self, app_version, branch, start_empty=False): 20 def __init__(self,
21 app_version,
22 branch,
23 start_empty=False,
24 persistent=True,
not at google - send to devlin 2013/04/30 15:37:42 I was wondering, it actually seems fine to just pe
方觉(Fang Jue) 2013/05/01 15:27:25 Since you say it's fine, then I'll use persistent
25 more=None):
18 self._app_version = app_version 26 self._app_version = app_version
19 self._branch = branch 27 self._branch = branch
20 self._start_empty = start_empty 28 self._start_empty = start_empty
29 self._persistent = persistent
30 self._more = more
21 31
22 def Create(self, cls, store_type=None): 32 def Create(self, cls, store_type=None):
23 return ObjectStoreCreator(cls, 33 return ObjectStoreCreator(cls,
24 self._app_version, 34 self._app_version,
25 self._branch, 35 self._branch,
26 store_type=store_type, 36 store_type=store_type,
27 start_empty=self._start_empty) 37 start_empty=self._start_empty,
38 persistent=self._persistent,
39 more=self._more)
28 40
29 class SharedFactory(object): 41 class SharedFactory(object):
30 '''A |Factory| for creating object stores shared across branches. 42 '''A |Factory| for creating object stores shared across branches.
31 ''' 43 '''
32 def __init__(self, app_version): 44 def __init__(self, app_version):
33 self._factory = ObjectStoreCreator.Factory(app_version, 'shared') 45 self._factory = ObjectStoreCreator.Factory(app_version, 'shared')
34 46
35 def Create(self, cls, store_type=None): 47 def Create(self, cls, store_type=None):
36 return self._factory.Create(cls, store_type=store_type) 48 return self._factory.Create(cls, store_type=store_type)
37 49
38 class TestFactory(object): 50 class TestFactory(object):
39 '''A |Factory| for creating object stores for tests, with fake defaults. 51 '''A |Factory| for creating object stores for tests, with fake defaults.
40 ''' 52 '''
41 def __init__(self): 53 def __init__(self):
42 self._factory = ObjectStoreCreator.Factory('test-version', 'test-branch') 54 self._factory = ObjectStoreCreator.Factory('test-version', 'test-branch')
43 55
44 def Create(self, cls, store_type=None): 56 def Create(self, cls, store_type=None):
45 return self._factory.Create(cls, store_type=store_type) 57 return self._factory.Create(cls, store_type=store_type)
46 58
47 def __init__(self, 59 def __init__(self,
48 cls, 60 cls,
49 app_version, 61 app_version,
50 branch, 62 branch,
51 store_type=None, 63 store_type=None,
52 start_empty=False): 64 start_empty=False,
65 persistent=True,
66 more=None):
53 '''Creates stores with a top-level namespace given by the name of |cls| 67 '''Creates stores with a top-level namespace given by the name of |cls|
54 combined with |branch|. Set an explicit |store_type| if necessary for tests. 68 combined with |branch|. Set an explicit |store_type| if necessary for tests.
55 69
56 By convention this should be the name of the class which owns the object 70 By convention this should be the name of the class which owns the object
57 store. If a class needs multiple object stores it should use Create with the 71 store. If a class needs multiple object stores it should use Create with the
58 |category| argument. 72 |category| argument.
59 ''' 73 '''
60 assert isinstance(cls, type) 74 assert isinstance(cls, type)
61 assert not cls.__name__[0].islower() # guard against non-class types 75 assert not cls.__name__[0].islower() # guard against non-class types
62 self._name = '%s/%s@%s' % (app_version, cls.__name__, branch) 76 _components = {
77 'version': app_version,
78 'branch': branch,
79 'cls': cls.__name__,
80 }
81 if more:
82 _components.update(more)
83 self._name = '/'.join('%s=%s' % (key, _components[key])
84 for key in sorted(_components.keys()))
63 self._store_type = store_type 85 self._store_type = store_type
64 self._start_empty = start_empty 86 self._start_empty = start_empty
87 self._persistent = persistent
65 88
66 def Create(self, category=None): 89 def Create(self, category=None):
67 '''Creates a new object store with the top namespace given in the 90 '''Creates a new object store with the top namespace given in the
68 constructor with an optional |category| for classes that need multiple 91 constructor with an optional |category| for classes that need multiple
69 object stores (e.g. one for stat and one for read). 92 object stores (e.g. one for stat and one for read).
70 ''' 93 '''
71 namespace = self._name 94 namespace = self._name
72 if category is not None: 95 if category is not None:
73 assert not any(c.isdigit() for c in category) 96 assert not any(c.isdigit() for c in category)
not at google - send to devlin 2013/04/30 15:37:42 to answer your question - the reason why category
74 namespace = '%s/%s' % (namespace, category) 97 namespace = '%s/%s' % (namespace, category)
75 if self._store_type is not None: 98 if self._store_type is not None:
76 return self._store_type(namespace) 99 return self._store_type(namespace)
77 return CacheChainObjectStore( 100 object_stores = (MemcacheObjectStore(namespace),)
78 (MemcacheObjectStore(namespace), PersistentObjectStore(namespace)), 101 if self._persistent:
79 start_empty=self._start_empty) 102 object_stores += (PersistentObjectStore(namespace),)
not at google - send to devlin 2013/04/30 15:37:42 fwiw, if you're modifying lists, use a list not a
103 return CacheChainObjectStore(object_stores, start_empty=self._start_empty)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698