120 request.setHeader('Expires', generateDateTime(mktime(expires.timetuple()))) |
120 request.setHeader('Expires', generateDateTime(mktime(expires.timetuple()))) |
121 return File.render(self, request) |
121 return File.render(self, request) |
122 |
122 |
123 |
123 |
124 class CubicWebRootResource(resource.Resource): |
124 class CubicWebRootResource(resource.Resource): |
125 def __init__(self, config, debug=None): |
125 def __init__(self, config): |
126 self.debugmode = debug |
|
127 self.config = config |
126 self.config = config |
128 # instantiate publisher here and not in init_publisher to get some |
127 # instantiate publisher here and not in init_publisher to get some |
129 # checks done before daemonization (eg versions consistency) |
128 # checks done before daemonization (eg versions consistency) |
130 self.appli = CubicWebPublisher(config, debug=self.debugmode) |
129 self.appli = CubicWebPublisher(config) |
131 self.base_url = config['base-url'] |
130 self.base_url = config['base-url'] |
132 self.https_url = config['https-url'] |
131 self.https_url = config['https-url'] |
133 self.children = {} |
132 self.children = {} |
134 self.static_directories = set(('data%s' % config.instance_md5_version(), |
133 self.static_directories = set(('data%s' % config.instance_md5_version(), |
135 'data', 'static', 'fckeditor')) |
134 'data', 'static', 'fckeditor')) |
208 return self |
207 return self |
209 |
208 |
210 def render(self, request): |
209 def render(self, request): |
211 """Render a page from the root resource""" |
210 """Render a page from the root resource""" |
212 # reload modified files in debug mode |
211 # reload modified files in debug mode |
213 if self.debugmode: |
212 if self.config.debugmode: |
214 self.appli.vreg.reload_if_needed() |
213 self.appli.vreg.reload_if_needed() |
215 if self.config['profile']: # default profiler don't trace threads |
214 if self.config['profile']: # default profiler don't trace threads |
216 return self.render_request(request) |
215 return self.render_request(request) |
217 else: |
216 else: |
218 deferred = threads.deferToThread(self.render_request, request) |
217 deferred = threads.deferToThread(self.render_request, request) |
403 from logging import getLogger |
402 from logging import getLogger |
404 from cubicweb import set_log_methods |
403 from cubicweb import set_log_methods |
405 LOGGER = getLogger('cubicweb.twisted') |
404 LOGGER = getLogger('cubicweb.twisted') |
406 set_log_methods(CubicWebRootResource, LOGGER) |
405 set_log_methods(CubicWebRootResource, LOGGER) |
407 |
406 |
408 def run(config, debug): |
407 def run(config): |
409 # create the site |
408 # create the site |
410 root_resource = CubicWebRootResource(config, debug) |
409 root_resource = CubicWebRootResource(config) |
411 website = server.Site(root_resource) |
410 website = server.Site(root_resource) |
412 # serve it via standard HTTP on port set in the configuration |
411 # serve it via standard HTTP on port set in the configuration |
413 port = config['port'] or 8080 |
412 port = config['port'] or 8080 |
414 reactor.listenTCP(port, website) |
413 reactor.listenTCP(port, website) |
415 logger = getLogger('cubicweb.twisted') |
414 logger = getLogger('cubicweb.twisted') |
416 if not debug: |
415 if not config.debugmode: |
417 if sys.platform == 'win32': |
416 if sys.platform == 'win32': |
418 raise ConfigurationError("Under windows, you must use the service management " |
417 raise ConfigurationError("Under windows, you must use the service management " |
419 "commands (e.g : 'net start my_instance)'") |
418 "commands (e.g : 'net start my_instance)'") |
420 print 'instance starting in the background' |
419 print 'instance starting in the background' |
421 if daemonize(): |
420 if daemonize(): |