Implements the 'pyramid' command.
authorChristophe de Vienne <christophe@unlish.com>
Fri, 05 Sep 2014 12:38:13 +0200
changeset 11633 ffe4040cf4a2
parent 11632 b05f361db666
child 11634 fa614537e5ee
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
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/
+
+    <instance>
+      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': '<log level>',
+          '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)