# HG changeset patch # User David Douard # Date 1460450106 -7200 # Node ID 6706c46e24ae158cc1a99f5219c55cfc3da54c6f # Parent 8a516dc485fea89b6e81a755a7ed5543b5225da9 [cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063) cubicweb.wsgi may not be available at all on Debian. diff -r 8a516dc485fe -r 6706c46e24ae cwctl.py --- a/cwctl.py Wed Mar 16 17:59:10 2016 +0100 +++ b/cwctl.py Tue Apr 12 10:35:06 2016 +0200 @@ -1014,8 +1014,12 @@ # WSGI ######### WSGI_CHOICES = {} -from cubicweb.wsgi import server as stdlib_server -WSGI_CHOICES['stdlib'] = stdlib_server +try: + from cubicweb.wsgi import server as stdlib_server +except ImportError: + pass +else: + WSGI_CHOICES['stdlib'] = stdlib_server try: from cubicweb.wsgi import wz except ImportError: @@ -1033,51 +1037,51 @@ def wsgichoices(): return tuple(WSGI_CHOICES) - -class WSGIStartHandler(InstanceCommand): - """Start an interactive wsgi server """ - name = 'wsgi' - actionverb = 'started' - arguments = '' +if WSGI_CHOICES: + class WSGIStartHandler(InstanceCommand): + """Start an interactive wsgi server """ + name = 'wsgi' + actionverb = 'started' + arguments = '' - @property - def options(self): - return ( - ("debug", - {'short': 'D', 'action': 'store_true', - 'default': False, - 'help': 'start server in debug mode.'}), - ('method', - {'short': 'm', - 'type': 'choice', - 'metavar': '', - 'default': 'stdlib', - 'choices': wsgichoices(), - 'help': 'wsgi utility/method'}), - ('loglevel', - {'short': 'l', - 'type': 'choice', - 'metavar': '', - 'default': None, - 'choices': ('debug', 'info', 'warning', 'error'), - 'help': 'debug if -D is set, error otherwise', - }), - ) + @property + def options(self): + return ( + ("debug", + {'short': 'D', 'action': 'store_true', + 'default': False, + 'help': 'start server in debug mode.'}), + ('method', + {'short': 'm', + 'type': 'choice', + 'metavar': '', + 'default': 'stdlib', + 'choices': wsgichoices(), + 'help': 'wsgi utility/method'}), + ('loglevel', + {'short': 'l', + 'type': 'choice', + 'metavar': '', + 'default': None, + 'choices': ('debug', 'info', 'warning', 'error'), + 'help': 'debug if -D is set, error otherwise', + }), + ) - def wsgi_instance(self, appid): - config = cwcfg.config_for(appid, debugmode=self['debug']) - init_cmdline_log_threshold(config, self['loglevel']) - assert config.name == 'all-in-one' - meth = self['method'] - server = WSGI_CHOICES[meth] - return server.run(config) + def wsgi_instance(self, appid): + config = cwcfg.config_for(appid, debugmode=self['debug']) + init_cmdline_log_threshold(config, self['loglevel']) + assert config.name == 'all-in-one' + meth = self['method'] + server = WSGI_CHOICES[meth] + return server.run(config) + CWCTL.register(WSGIStartHandler) for cmdcls in (ListCommand, CreateInstanceCommand, DeleteInstanceCommand, StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand, - WSGIStartHandler, ReloadConfigurationCommand, StatusCommand, UpgradeInstanceCommand, ListVersionsInstanceCommand,