# HG changeset patch # User Aurelien Campeas # Date 1381507234 -7200 # Node ID 823cf14bcc37c6828fc9da280de9663424e023bc # Parent e70c8c70e344d7f286c53035fb4a09a86f08da19 [wsgi] also provide an example using werkzeug (if available) Related to #3005509. diff -r e70c8c70e344 -r 823cf14bcc37 cwctl.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 = '' options = ( + ('method', + {'short': 'm', + 'type': 'choice', + 'metavar': '', + '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) diff -r e70c8c70e344 -r 823cf14bcc37 wsgi/wz.py --- /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 . +"""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()