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

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

Issue 14267024: Devserver: have a separate ObjectStore namespace (both memcache and datastore) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove presubmit check, cleanup Created 7 years, 8 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 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 def __init__(self, branch=None): 11 '''Creates ObjectStoreCreators (yes seriously) bound to an SVN branch.
12 '''
13 def __init__(self, app_version, branch):
not at google - send to devlin 2013/04/22 16:43:37 doesn't make sense for branch to be optional reall
14 self._app_version = app_version
12 self._branch = branch 15 self._branch = branch
13 16
14 '''Creates ObjectStoreCreators (yes seriously) bound to an SVN branch. 17 def Create(self, cls, store_type=None):
18 return ObjectStoreCreator(cls,
19 self._app_version,
20 self._branch,
21 store_type=store_type)
22
23 class SharedFactory(object):
24 '''A |Factory| for creating object stores shared across branches.
15 ''' 25 '''
26 def __init__(self, app_version):
27 self._factory = ObjectStoreCreator.Factory(app_version, 'shared')
28
16 def Create(self, cls, store_type=None): 29 def Create(self, cls, store_type=None):
17 return ObjectStoreCreator(cls, branch=self._branch, store_type=store_type) 30 return self._factory.Create(cls, store_type=store_type)
18 31
19 def __init__(self, cls, branch=None, store_type=None): 32 class TestFactory(object):
33 '''A |Factory| for creating object stores for tests, with fake defaults.
34 '''
35 def __init__(self):
36 self._factory = ObjectStoreCreator.Factory('test-version', 'test-branch')
37
38 def Create(self, cls, store_type=None):
39 return self._factory.Create(cls, store_type=store_type)
40
41 def __init__(self, cls, app_version, branch, store_type=None):
20 '''Creates stores with a top-level namespace given by the name of |cls| 42 '''Creates stores with a top-level namespace given by the name of |cls|
21 combined with |branch|. Set an explicit |store_type| if necessary for tests. 43 combined with |branch|. Set an explicit |store_type| if necessary for tests.
22 44
23 By convention this should be the name of the class which owns the object 45 By convention this should be the name of the class which owns the object
24 store. If a class needs multiple object store it should use Create with the 46 store. If a class needs multiple object stores it should use Create with the
25 |category| argument. 47 |category| argument.
26 ''' 48 '''
27 assert isinstance(cls, type) 49 assert isinstance(cls, type)
28 assert not cls.__name__[0].islower() # guard against non-class types 50 assert not cls.__name__[0].islower() # guard against non-class types
29 if branch is None: 51 self._name = '%s/%s@%s' % (app_version, cls.__name__, branch)
30 self._name = cls.__name__
31 else:
32 self._name = '%s@%s' % (cls.__name__, branch)
33 self._store_type = store_type 52 self._store_type = store_type
34 53
35 def Create(self, version=None, category=None): 54 def Create(self, category=None):
36 '''Creates a new object store with the top namespace given in the 55 '''Creates a new object store with the top namespace given in the
37 constructor, at version |version|, with an optional |category| for classes 56 constructor with an optional |category| for classes that need multiple
38 that need multiple object stores (e.g. one for stat and one for read). 57 object stores (e.g. one for stat and one for read).
39 ''' 58 '''
40 namespace = self._name 59 namespace = self._name
41 if category is not None: 60 if category is not None:
42 assert not any(c.isdigit() for c in category) 61 assert not any(c.isdigit() for c in category)
43 namespace = '%s/%s' % (namespace, category) 62 namespace = '%s/%s' % (namespace, category)
44 if version is not None:
45 assert isinstance(version, int)
46 namespace = '%s/%s' % (namespace, version)
47 if self._store_type is not None: 63 if self._store_type is not None:
48 return self._store_type(namespace) 64 return self._store_type(namespace)
49 return CacheChainObjectStore((MemcacheObjectStore(namespace), 65 return CacheChainObjectStore((MemcacheObjectStore(namespace),
50 PersistentObjectStore(namespace))) 66 PersistentObjectStore(namespace)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698