# HG changeset patch # User Denis Laxalde # Date 1487869353 -3600 # Node ID 5de78b6fff2e511953c1d0980f950ef9f476cb1c # Parent 8d1525c76e65ef29394fde5f0cadb9c149b1f5f1 [server] Separate repository bootstrap from initialization Thus we now call 'bootstrap' here and there explicitly and remove call of this method in Repository.__init__(). This way instantiation of a Repository does not *implicitly* triggers the "bootstrap" step, which is arguably not a trivial thing and thus deserves to be independent. In __init__, set 'shutting_down' attribute to None and then to False in bootstrap as a mean to indicate that, when initialized, a repository is neither shutting down nor started (not sure where this is used though). diff -r 8d1525c76e65 -r 5de78b6fff2e cubicweb/cwconfig.py --- a/cubicweb/cwconfig.py Thu Feb 23 17:51:11 2017 +0100 +++ b/cubicweb/cwconfig.py Thu Feb 23 18:02:33 2017 +0100 @@ -1119,9 +1119,12 @@ # config -> repository def repository(self, vreg=None): + """Return a new bootstrapped repository.""" from cubicweb.server.repository import Repository from cubicweb.server.utils import TasksManager - return Repository(self, TasksManager(), vreg=vreg) + repo = Repository(self, TasksManager(), vreg=vreg) + repo.bootstrap() + return repo # instance methods used to get instance specific resources ############# diff -r 8d1525c76e65 -r 5de78b6fff2e cubicweb/devtools/stresstester.py --- a/cubicweb/devtools/stresstester.py Thu Feb 23 17:51:11 2017 +0100 +++ b/cubicweb/devtools/stresstester.py Thu Feb 23 18:02:33 2017 +0100 @@ -168,6 +168,7 @@ # get local access to the repository print("Creating repo", prof_file) repo = Repository(config, prof_file) + repo.bootstrap() session = repo.new_session(user, password=password) reporter = ProfileReporter(queries) if threads > 1: diff -r 8d1525c76e65 -r 5de78b6fff2e cubicweb/server/__init__.py --- a/cubicweb/server/__init__.py Thu Feb 23 17:51:11 2017 +0100 +++ b/cubicweb/server/__init__.py Thu Feb 23 18:02:33 2017 +0100 @@ -223,6 +223,7 @@ config.cube_appobject_path = set(('hooks', 'entities')) # only enable the system source at initialization time repo = Repository(config, vreg=vreg) + repo.bootstrap() if init_config is not None: # further config initialization once it has been bootstrapped init_config(config) diff -r 8d1525c76e65 -r 5de78b6fff2e cubicweb/server/repository.py --- a/cubicweb/server/repository.py Thu Feb 23 17:51:11 2017 +0100 +++ b/cubicweb/server/repository.py Thu Feb 23 18:02:33 2017 +0100 @@ -211,7 +211,7 @@ entities and relations """ - def __init__(self, config, tasks_manager=None, vreg=None, bootstrap=True): + def __init__(self, config, tasks_manager=None, vreg=None): self.config = config self.sources_by_eid = {} if vreg is None: @@ -230,7 +230,7 @@ self.schema = schema.CubicWebSchema(config.appid) self.vreg.schema = self.schema # until actual schema is loaded... # shutdown flag - self.shutting_down = False + self.shutting_down = None # sources (additional sources info in the system database) self.system_source = self.get_source('native', 'system', config.system_source_config.copy()) @@ -239,9 +239,6 @@ self.querier = querier.QuerierHelper(self, self.schema) # cache eid -> type self._type_cache = {} - # open some connection sets - if bootstrap: - self.bootstrap() # the hooks manager self.hm = hook.HooksManager(self.vreg) @@ -258,6 +255,7 @@ def bootstrap(self): self.info('starting repository from %s', self.config.apphome) + self.shutting_down = False config = self.config # copy pool size here since config.init_cube() and config.load_schema() # reload configuration from file and could reset a manually set pool diff -r 8d1525c76e65 -r 5de78b6fff2e cubicweb/utils.py --- a/cubicweb/utils.py Thu Feb 23 17:51:11 2017 +0100 +++ b/cubicweb/utils.py Thu Feb 23 18:02:33 2017 +0100 @@ -61,6 +61,7 @@ password = config.default_admin_config['password'] repo = Repository(config, TasksManager()) + repo.bootstrap() session = repo.new_session(login, password=password) return session.new_cnx()