cubicweb/cwctl.py
changeset 11279 e4f11ef1face
parent 11243 6706c46e24ae
parent 11191 0c27c0da4094
child 11284 d4293b14c664
equal deleted inserted replaced
11277:baed516c6f6e 11279:e4f11ef1face
   981 
   981 
   982 
   982 
   983 # WSGI #########
   983 # WSGI #########
   984 
   984 
   985 WSGI_CHOICES = {}
   985 WSGI_CHOICES = {}
   986 from cubicweb.wsgi import server as stdlib_server
   986 try:
   987 WSGI_CHOICES['stdlib'] = stdlib_server
   987     from cubicweb.wsgi import server as stdlib_server
       
   988 except ImportError:
       
   989     pass
       
   990 else:
       
   991     WSGI_CHOICES['stdlib'] = stdlib_server
   988 try:
   992 try:
   989     from cubicweb.wsgi import wz
   993     from cubicweb.wsgi import wz
   990 except ImportError:
   994 except ImportError:
   991     pass
   995     pass
   992 else:
   996 else:
  1000 
  1004 
  1001 
  1005 
  1002 def wsgichoices():
  1006 def wsgichoices():
  1003     return tuple(WSGI_CHOICES)
  1007     return tuple(WSGI_CHOICES)
  1004 
  1008 
  1005 
  1009 if WSGI_CHOICES:
  1006 class WSGIStartHandler(InstanceCommand):
  1010     class WSGIStartHandler(InstanceCommand):
  1007     """Start an interactive wsgi server """
  1011         """Start an interactive wsgi server """
  1008     name = 'wsgi'
  1012         name = 'wsgi'
  1009     actionverb = 'started'
  1013         actionverb = 'started'
  1010     arguments = '<instance>'
  1014         arguments = '<instance>'
  1011 
  1015 
  1012     @property
  1016         @property
  1013     def options(self):
  1017         def options(self):
  1014         return (
  1018             return (
  1015         ("debug",
  1019                 ("debug",
  1016          {'short': 'D', 'action': 'store_true',
  1020                  {'short': 'D', 'action': 'store_true',
  1017           'default': False,
  1021                   'default': False,
  1018           'help': 'start server in debug mode.'}),
  1022                   'help': 'start server in debug mode.'}),
  1019         ('method',
  1023                 ('method',
  1020          {'short': 'm',
  1024                  {'short': 'm',
  1021           'type': 'choice',
  1025                   'type': 'choice',
  1022           'metavar': '<method>',
  1026                   'metavar': '<method>',
  1023           'default': 'stdlib',
  1027                   'default': 'stdlib',
  1024           'choices': wsgichoices(),
  1028                   'choices': wsgichoices(),
  1025           'help': 'wsgi utility/method'}),
  1029                   'help': 'wsgi utility/method'}),
  1026         ('loglevel',
  1030                 ('loglevel',
  1027          {'short': 'l',
  1031                  {'short': 'l',
  1028           'type': 'choice',
  1032                   'type': 'choice',
  1029           'metavar': '<log level>',
  1033                   'metavar': '<log level>',
  1030           'default': None,
  1034                   'default': None,
  1031           'choices': ('debug', 'info', 'warning', 'error'),
  1035                   'choices': ('debug', 'info', 'warning', 'error'),
  1032           'help': 'debug if -D is set, error otherwise',
  1036                   'help': 'debug if -D is set, error otherwise',
  1033           }),
  1037               }),
  1034         )
  1038             )
  1035 
  1039 
  1036     def wsgi_instance(self, appid):
  1040         def wsgi_instance(self, appid):
  1037         config = cwcfg.config_for(appid, debugmode=self['debug'])
  1041             config = cwcfg.config_for(appid, debugmode=self['debug'])
  1038         init_cmdline_log_threshold(config, self['loglevel'])
  1042             init_cmdline_log_threshold(config, self['loglevel'])
  1039         assert config.name == 'all-in-one'
  1043             assert config.name == 'all-in-one'
  1040         meth = self['method']
  1044             meth = self['method']
  1041         server = WSGI_CHOICES[meth]
  1045             server = WSGI_CHOICES[meth]
  1042         return server.run(config)
  1046             return server.run(config)
  1043 
  1047 
       
  1048     CWCTL.register(WSGIStartHandler)
  1044 
  1049 
  1045 
  1050 
  1046 for cmdcls in (ListCommand,
  1051 for cmdcls in (ListCommand,
  1047                CreateInstanceCommand, DeleteInstanceCommand,
  1052                CreateInstanceCommand, DeleteInstanceCommand,
  1048                StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand,
  1053                StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand,
  1049                WSGIStartHandler,
       
  1050                ReloadConfigurationCommand, StatusCommand,
  1054                ReloadConfigurationCommand, StatusCommand,
  1051                UpgradeInstanceCommand,
  1055                UpgradeInstanceCommand,
  1052                ListVersionsInstanceCommand,
  1056                ListVersionsInstanceCommand,
  1053                ShellCommand,
  1057                ShellCommand,
  1054                RecompileInstanceCatalogsCommand,
  1058                RecompileInstanceCatalogsCommand,