[wsgi] also provide an example using werkzeug (if available)
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 11 Oct 2013 18:00:34 +0200
changeset 9288 823cf14bcc37
parent 9287 e70c8c70e344
child 9289 9bb7b5dc4214
[wsgi] also provide an example using werkzeug (if available) Related to #3005509.
cwctl.py
wsgi/wz.py
--- a/cwctl.py	Tue Oct 01 16:45:58 2013 +0200
+++ b/cwctl.py	Fri Oct 11 18:00:34 2013 +0200
@@ -1036,12 +1036,26 @@
 
 # WSGI #########
 
+def wsgichoices():
+    try:
+        from werkzeug import serving
+    except ImportError:
+        return ('stdlib',)
+    return ('stdlib', 'werkzeug')
+
 class WSGIDebugStartHandler(InstanceCommand):
     """Start an interactive wsgi server """
     name = 'wsgi'
     actionverb = 'started'
     arguments = '<instance>'
     options = (
+        ('method',
+         {'short': 'm',
+          'type': 'choice',
+          'metavar': '<method>',
+          'default': 'stdlib',
+          'choices': wsgichoices(),
+          'help': 'wsgi utility/method'}),
         ('loglevel',
          {'short': 'l',
           'type' : 'choice',
@@ -1056,7 +1070,11 @@
         config = cwcfg.config_for(appid, debugmode=1)
         init_cmdline_log_threshold(config, self['loglevel'])
         assert config.name == 'all-in-one'
-        from cubicweb.wsgi import server
+        meth = self['method']
+        if meth == 'stdlib':
+            from cubicweb.wsgi import server
+        else:
+            from cubicweb.wsgi import wz as server
         return server.run(config)
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wsgi/wz.py	Fri Oct 11 18:00:34 2013 +0200
@@ -0,0 +1,47 @@
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""dummy wsgi server for CubicWeb web instances"""
+
+__docformat__ = "restructuredtext en"
+
+import socket
+
+from cubicweb.wsgi.handler import CubicWebWSGIApplication
+from cubicweb import ConfigurationError
+from werkzeug.serving import run_simple
+
+from logging import getLogger
+LOGGER = getLogger('cubicweb')
+
+
+def run(config):
+    config.check_writeable_uid_directory(config.appdatahome)
+
+    port = config['port'] or 8080
+    interface = config['interface']
+
+    app = CubicWebWSGIApplication(config)
+    repo = app.appli.repo
+    try:
+        repo.start_looping_tasks()
+        run_simple(interface, port, app,
+                   threaded=True,
+                   use_debugger=True,
+                   processes=1) # more processes yield weird errors
+    finally:
+        repo.shutdown()