# HG changeset patch # User Pierre-Yves David # Date 1353683539 -3600 # Node ID 6ff29f2879dac20639d2f81d74a92ee81931b12a # Parent c1d5e8ca15ea9b4514cbeefb70b649de975f7940 web/application: instantiate the repository outside of CubicWebPublisher This improves decoupling and allows ``CubicWebPublisher`` user to choose which argument are used during ``Repository`` instantiation. In particular is allows caller to provide a ``TaskManager``. The `vreg` argument of publisher is made mandatory. See CubicWebPublisher docstring for details. Related to #2249513 diff -r c1d5e8ca15ea -r 6ff29f2879da devtools/testlib.py --- a/devtools/testlib.py Fri Dec 07 17:23:04 2012 +0100 +++ b/devtools/testlib.py Fri Nov 23 16:12:19 2012 +0100 @@ -633,7 +633,7 @@ @cached def app(self): """return a cubicweb publisher""" - publisher = application.CubicWebPublisher(self.config) + publisher = application.CubicWebPublisher(self.repo, self.config) def raise_error_handler(*args, **kwargs): raise publisher.error_handler = raise_error_handler diff -r c1d5e8ca15ea -r 6ff29f2879da etwist/server.py --- a/etwist/server.py Fri Dec 07 17:23:04 2012 +0100 +++ b/etwist/server.py Fri Nov 23 16:12:19 2012 +0100 @@ -62,7 +62,8 @@ self.config = config # instantiate publisher here and not in init_publisher to get some # checks done before daemonization (eg versions consistency) - self.appli = CubicWebPublisher(config) + repo = config.repository() + self.appli = CubicWebPublisher(repo, config) self.base_url = config['base-url'] self.https_url = config['https-url'] global MAX_POST_LENGTH diff -r c1d5e8ca15ea -r 6ff29f2879da web/application.py --- a/web/application.py Fri Dec 07 17:23:04 2012 +0100 +++ b/web/application.py Fri Nov 23 16:12:19 2012 +0100 @@ -250,18 +250,20 @@ The http server will call its main entry point ``application.handle_request``. .. automethod:: cubicweb.web.application.CubicWebPublisher.main_handle_request + + You have to provide both a repository and web-server config at + initialization. In all in one instance both config will be the same. """ - def __init__(self, config, - session_handler_fact=CookieSessionHandler): + def __init__(self, repo, config, session_handler_fact=CookieSessionHandler): self.info('starting web instance from %s', config.apphome) - # connect to the repository and get instance's schema - self.repo = config.repository() - vreg = self.vreg = self.repo.vreg - if not vreg.initialized: + self.repo = repo + self.vreg = repo.vreg + # get instance's schema + if not self.vreg.initialized: config.init_cubes(self.repo.get_cubes()) - vreg.init_properties(self.repo.properties()) - vreg.set_schema(self.repo.get_schema()) + self.vreg.init_properties(self.repo.properties()) + self.vreg.set_schema(self.repo.get_schema()) # set the correct publish method if config['query-log-file']: from threading import Lock diff -r c1d5e8ca15ea -r 6ff29f2879da wsgi/handler.py --- a/wsgi/handler.py Fri Dec 07 17:23:04 2012 +0100 +++ b/wsgi/handler.py Fri Nov 23 16:12:19 2012 +0100 @@ -23,7 +23,7 @@ from itertools import chain, repeat, izip -from cubicweb import AuthenticationError +from cubicweb import cwreg, AuthenticationError from cubicweb.web import DirectResponse from cubicweb.web.application import CubicWebPublisher from cubicweb.wsgi.request import CubicWebWsgiRequest @@ -103,8 +103,8 @@ NOTE: no pyro """ - def __init__(self, config): - self.appli = CubicWebPublisher(config) + def __init__(self, repo, config): + self.appli = CubicWebPublisher(repo, config) self.config = config self.base_url = self.config['base-url'] self.https_url = self.config['https-url']