OLD | NEW |
1 # Copyright 2014 The Swarming Authors. All rights reserved. | 1 # Copyright 2014 The Swarming Authors. All rights reserved. |
2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Versioned singleton entity with global application configuration. | 5 """Versioned singleton entity with global application configuration. |
6 | 6 |
7 Example usage: | 7 Example usage: |
8 from components.datastore_utils import config | 8 from components.datastore_utils import config |
9 | 9 |
10 class MyConfig(config.GlobalConfig): | 10 class MyConfig(config.GlobalConfig): |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 Advantages over regular ndb.Entity with predefined key: | 27 Advantages over regular ndb.Entity with predefined key: |
28 1. All changes are logged (see datastore_utils.store_new_version). | 28 1. All changes are logged (see datastore_utils.store_new_version). |
29 2. In-memory process-wide cache. | 29 2. In-memory process-wide cache. |
30 | 30 |
31 TODO: Get rid of components.auth dependency. It creates circular import between | 31 TODO: Get rid of components.auth dependency. It creates circular import between |
32 components.auth and components.datastore_utils. components.datastore_utils is on | 32 components.auth and components.datastore_utils. components.datastore_utils is on |
33 "lower" level than components.auth and must not depend on it. | 33 "lower" level than components.auth and must not depend on it. |
34 """ | 34 """ |
35 | 35 |
| 36 # Pylint fails to recognize that ndb.Model.key is defined in ndb.Model. |
| 37 # pylint: disable=attribute-defined-outside-init |
| 38 |
36 from google.appengine.ext import ndb | 39 from google.appengine.ext import ndb |
37 | 40 |
38 from components import auth | 41 from components import auth |
39 from components import datastore_utils | 42 from components import datastore_utils |
40 from components import utils | 43 from components import utils |
41 | 44 |
42 | 45 |
43 class GlobalConfig(ndb.Model): | 46 class GlobalConfig(ndb.Model): |
44 """Singleton entity with the global configuration of the service. | 47 """Singleton entity with the global configuration of the service. |
45 | 48 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 123 |
121 _config_fetcher = None | 124 _config_fetcher = None |
122 | 125 |
123 @classmethod | 126 @classmethod |
124 def _get_root_model(cls): | 127 def _get_root_model(cls): |
125 return datastore_utils.get_versioned_root_model('%sRoot' % cls.__name__) | 128 return datastore_utils.get_versioned_root_model('%sRoot' % cls.__name__) |
126 | 129 |
127 @classmethod | 130 @classmethod |
128 def _get_root_key(cls): | 131 def _get_root_key(cls): |
129 return ndb.Key(cls._get_root_model(), 1) | 132 return ndb.Key(cls._get_root_model(), 1) |
OLD | NEW |