etwist/server.py
changeset 9036 cf519fd876c6
parent 9031 6ff29f2879da
child 9402 2c48c091b6a2
equal deleted inserted replaced
9035:63f3d25bab14 9036:cf519fd876c6
    55     baseurl = urlunsplit((scheme, netloc, url, query, fragment))
    55     baseurl = urlunsplit((scheme, netloc, url, query, fragment))
    56     return baseurl
    56     return baseurl
    57 
    57 
    58 
    58 
    59 class CubicWebRootResource(resource.Resource):
    59 class CubicWebRootResource(resource.Resource):
    60     def __init__(self, config):
    60     def __init__(self, config, repo):
    61         resource.Resource.__init__(self)
    61         resource.Resource.__init__(self)
    62         self.config = config
    62         self.config = config
    63         # instantiate publisher here and not in init_publisher to get some
    63         # instantiate publisher here and not in init_publisher to get some
    64         # checks done before daemonization (eg versions consistency)
    64         # checks done before daemonization (eg versions consistency)
    65         repo = config.repository()
       
    66         self.appli = CubicWebPublisher(repo, config)
    65         self.appli = CubicWebPublisher(repo, config)
    67         self.base_url = config['base-url']
    66         self.base_url = config['base-url']
    68         self.https_url = config['https-url']
    67         self.https_url = config['https-url']
    69         global MAX_POST_LENGTH
    68         global MAX_POST_LENGTH
    70         MAX_POST_LENGTH = config['max-post-length']
    69         MAX_POST_LENGTH = config['max-post-length']
   269 from logging import getLogger
   268 from logging import getLogger
   270 from cubicweb import set_log_methods
   269 from cubicweb import set_log_methods
   271 LOGGER = getLogger('cubicweb.twisted')
   270 LOGGER = getLogger('cubicweb.twisted')
   272 set_log_methods(CubicWebRootResource, LOGGER)
   271 set_log_methods(CubicWebRootResource, LOGGER)
   273 
   272 
   274 def run(config, debug=None):
   273 def run(config, debug=None, repo=None):
       
   274     # repo may by passed during test.
       
   275     #
       
   276     # Test has already created a repo object so we should not create a new one.
       
   277     # Explicitly passing the repo object avoid relying on the fragile
       
   278     # config.repository() cache. We could imagine making repo a mandatory
       
   279     # argument and receives it from the starting command directly.
   275     if debug is not None:
   280     if debug is not None:
   276         config.debugmode = debug
   281         config.debugmode = debug
   277     config.check_writeable_uid_directory(config.appdatahome)
   282     config.check_writeable_uid_directory(config.appdatahome)
   278     # create the site
   283     # create the site
   279     root_resource = CubicWebRootResource(config)
   284     if repo is None:
       
   285         repo = config.repository()
       
   286     root_resource = CubicWebRootResource(config, repo)
   280     website = server.Site(root_resource)
   287     website = server.Site(root_resource)
   281     # serve it via standard HTTP on port set in the configuration
   288     # serve it via standard HTTP on port set in the configuration
   282     port = config['port'] or 8080
   289     port = config['port'] or 8080
   283     interface = config['interface']
   290     interface = config['interface']
   284     reactor.suggestThreadPoolSize(config['webserver-threadpool-size'])
   291     reactor.suggestThreadPoolSize(config['webserver-threadpool-size'])