Add a wsgi application factory suitable for wsgi servers.
authorChristophe de Vienne <christophe@unlish.com>
Thu, 28 Aug 2014 15:42:51 +0200
changeset 11503 ddf61aa73384
parent 11502 e4682c567e86
child 11504 8701caf9edf0
Add a wsgi application factory suitable for wsgi servers. This factory can generate a wsgi application for a cubicweb instance. It reads the instance name from the CW_INSTANCE environment variable, and activates the debugmode if CW_DEBUG is defined in environment. It is usable by uwsgi as the 'module' parameter : CW_INSTANCE=test uwsgi --plugins python,http --http 0.0.0.0:8080 --module pyramid_cubicweb:wsgi_application()
pyramid_cubicweb/__init__.py
--- a/pyramid_cubicweb/__init__.py	Wed Aug 27 19:26:44 2014 +0200
+++ b/pyramid_cubicweb/__init__.py	Thu Aug 28 15:42:51 2014 +0200
@@ -1,3 +1,6 @@
+import os
+
+from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
 from pyramid.config import Configurator
 
 
@@ -26,3 +29,14 @@
     config.include('pyramid_cubicweb.core')
     config.include('pyramid_cubicweb.bwcompat')
     return config
+
+
+def wsgi_application(instance_name=None, debug=None):
+    if instance_name is None:
+        instance_name = os.environ.get('CW_INSTANCE')
+    if debug is None:
+        debug = 'CW_DEBUG' in os.environ
+
+    cwconfig = cwcfg.config_for(instance_name, debugmode=debug)
+    config = make_cubicweb_application(cwconfig)
+    return config.make_wsgi_app()