# HG changeset patch # User Christophe de Vienne # Date 1409913493 -7200 # Node ID ffe4040cf4a242ad0667ba0719c922a6c618878c # Parent b05f361db666d4e0833df642eab6d02b2c68deeb Implements the 'pyramid' command. It load an instance config, and load in the pyramid scaffolding provided by pyramid_cubicweb. The application is then served by a waitress server. Closes #4317312 diff -r b05f361db666 -r ffe4040cf4a2 ccplugin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ccplugin.py Fri Sep 05 12:38:13 2014 +0200 @@ -0,0 +1,44 @@ +from cubicweb.cwconfig import CubicWebConfiguration as cwcfg +from cubicweb.cwctl import CWCTL, InstanceCommand, init_cmdline_log_threshold + + +class PyramidStartHandler(InstanceCommand): + """Start an interactive pyramid server. + + This command requires http://hg.logilab.org/review/pyramid_cubicweb/ + + + identifier of the instance to configure. + """ + name = 'pyramid' + + options = ( + ("debug", + {'short': 'D', 'action': 'store_true', + 'help': 'start server in debug mode.'}), + ('loglevel', + {'short': 'l', 'type': 'choice', 'metavar': '', + 'default': None, 'choices': ('debug', 'info', 'warning', 'error'), + 'help': 'debug if -D is set, error otherwise', + }), + ) + + def pyramid_instance(self, appid): + from pyramid_cubicweb import make_cubicweb_application + from waitress import serve + cwconfig = cwcfg.config_for(appid, debugmode=self['debug']) + init_cmdline_log_threshold(cwconfig, self['loglevel']) + + host = cwconfig['interface'] + port = cwconfig['port'] or 8080 + + pyramid_config = make_cubicweb_application(cwconfig) + + repo = cwconfig.repository() + try: + repo.start_looping_tasks() + serve(pyramid_config.make_wsgi_app(), host=host, port=port) + finally: + repo.shutdown() + +CWCTL.register(PyramidStartHandler)