ccplugin.py
changeset 11633 ffe4040cf4a2
child 11637 a9cde6a3394c
equal deleted inserted replaced
11632:b05f361db666 11633:ffe4040cf4a2
       
     1 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
       
     2 from cubicweb.cwctl import CWCTL, InstanceCommand, init_cmdline_log_threshold
       
     3 
       
     4 
       
     5 class PyramidStartHandler(InstanceCommand):
       
     6     """Start an interactive pyramid server.
       
     7 
       
     8     This command requires http://hg.logilab.org/review/pyramid_cubicweb/
       
     9 
       
    10     <instance>
       
    11       identifier of the instance to configure.
       
    12     """
       
    13     name = 'pyramid'
       
    14 
       
    15     options = (
       
    16         ("debug",
       
    17          {'short': 'D', 'action': 'store_true',
       
    18           'help': 'start server in debug mode.'}),
       
    19         ('loglevel',
       
    20          {'short': 'l', 'type': 'choice', 'metavar': '<log level>',
       
    21           'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
       
    22           'help': 'debug if -D is set, error otherwise',
       
    23           }),
       
    24     )
       
    25 
       
    26     def pyramid_instance(self, appid):
       
    27         from pyramid_cubicweb import make_cubicweb_application
       
    28         from waitress import serve
       
    29         cwconfig = cwcfg.config_for(appid, debugmode=self['debug'])
       
    30         init_cmdline_log_threshold(cwconfig, self['loglevel'])
       
    31 
       
    32         host = cwconfig['interface']
       
    33         port = cwconfig['port'] or 8080
       
    34 
       
    35         pyramid_config = make_cubicweb_application(cwconfig)
       
    36 
       
    37         repo = cwconfig.repository()
       
    38         try:
       
    39             repo.start_looping_tasks()
       
    40             serve(pyramid_config.make_wsgi_app(), host=host, port=port)
       
    41         finally:
       
    42             repo.shutdown()
       
    43 
       
    44 CWCTL.register(PyramidStartHandler)