209 class Repository(object): |
209 class Repository(object): |
210 """a repository provides access to a set of persistent storages for |
210 """a repository provides access to a set of persistent storages for |
211 entities and relations |
211 entities and relations |
212 """ |
212 """ |
213 |
213 |
214 def __init__(self, config, tasks_manager=None, vreg=None, bootstrap=True): |
214 def __init__(self, config, tasks_manager=None, vreg=None): |
215 self.config = config |
215 self.config = config |
216 self.sources_by_eid = {} |
216 self.sources_by_eid = {} |
217 if vreg is None: |
217 if vreg is None: |
218 vreg = cwvreg.CWRegistryStore(config) |
218 vreg = cwvreg.CWRegistryStore(config) |
219 self.vreg = vreg |
219 self.vreg = vreg |
228 self._running_threads = [] |
228 self._running_threads = [] |
229 # initial schema, should be build or replaced latter |
229 # initial schema, should be build or replaced latter |
230 self.schema = schema.CubicWebSchema(config.appid) |
230 self.schema = schema.CubicWebSchema(config.appid) |
231 self.vreg.schema = self.schema # until actual schema is loaded... |
231 self.vreg.schema = self.schema # until actual schema is loaded... |
232 # shutdown flag |
232 # shutdown flag |
233 self.shutting_down = False |
233 self.shutting_down = None |
234 # sources (additional sources info in the system database) |
234 # sources (additional sources info in the system database) |
235 self.system_source = self.get_source('native', 'system', |
235 self.system_source = self.get_source('native', 'system', |
236 config.system_source_config.copy()) |
236 config.system_source_config.copy()) |
237 self.sources_by_uri = {'system': self.system_source} |
237 self.sources_by_uri = {'system': self.system_source} |
238 # querier helper, need to be created after sources initialization |
238 # querier helper, need to be created after sources initialization |
239 self.querier = querier.QuerierHelper(self, self.schema) |
239 self.querier = querier.QuerierHelper(self, self.schema) |
240 # cache eid -> type |
240 # cache eid -> type |
241 self._type_cache = {} |
241 self._type_cache = {} |
242 # open some connection sets |
|
243 if bootstrap: |
|
244 self.bootstrap() |
|
245 # the hooks manager |
242 # the hooks manager |
246 self.hm = hook.HooksManager(self.vreg) |
243 self.hm = hook.HooksManager(self.vreg) |
247 |
244 |
248 # registry hook to fix user class on registry reload |
245 # registry hook to fix user class on registry reload |
249 @onevent('after-registry-reload', self) |
246 @onevent('after-registry-reload', self) |
256 if not isinstance(session.user, InternalManager): |
253 if not isinstance(session.user, InternalManager): |
257 session.user.__class__ = usercls |
254 session.user.__class__ = usercls |
258 |
255 |
259 def bootstrap(self): |
256 def bootstrap(self): |
260 self.info('starting repository from %s', self.config.apphome) |
257 self.info('starting repository from %s', self.config.apphome) |
|
258 self.shutting_down = False |
261 config = self.config |
259 config = self.config |
262 # copy pool size here since config.init_cube() and config.load_schema() |
260 # copy pool size here since config.init_cube() and config.load_schema() |
263 # reload configuration from file and could reset a manually set pool |
261 # reload configuration from file and could reset a manually set pool |
264 # size. |
262 # size. |
265 if config['connections-pooler-enabled']: |
263 if config['connections-pooler-enabled']: |