[cwctl] rewrite wsgi method choices
authorAlain Leufroy <alain@leufroy.fr>
Thu, 15 May 2014 23:05:15 +0200
changeset 10104 cdc0b0216da2
parent 10103 1d648d7f072e
child 10105 a1e8816029af
[cwctl] rewrite wsgi method choices This will help devs to add new choices by adding their callback to WSGI_CHOICES. Note: ``options`` becomes a property because ``wsgichoices()`` should be evaluated at the last-minute.
cwctl.py
--- a/cwctl.py	Mon Dec 01 11:35:05 2014 +0100
+++ b/cwctl.py	Thu May 15 23:05:15 2014 +0200
@@ -1044,19 +1044,30 @@
 
 # WSGI #########
 
+WSGI_CHOICES = {}
+from cubicweb.wsgi import server as stdlib_server
+WSGI_CHOICES['stdlib'] = stdlib_server
+try:
+    from cubicweb.wsgi import wz
+except ImportError:
+    pass
+else:
+    WSGI_CHOICES['werkzeug'] = wz
+
+
 def wsgichoices():
-    try:
-        from werkzeug import serving
-    except ImportError:
-        return ('stdlib',)
-    return ('stdlib', 'werkzeug')
+    return tuple(WSGI_CHOICES)
+
 
 class WSGIStartHandler(InstanceCommand):
     """Start an interactive wsgi server """
     name = 'wsgi'
     actionverb = 'started'
     arguments = '<instance>'
-    options = (
+
+    @property
+    def options(self):
+        return (
         ("debug",
          {'short': 'D', 'action': 'store_true',
           'default': False,
@@ -1083,10 +1094,7 @@
         init_cmdline_log_threshold(config, self['loglevel'])
         assert config.name == 'all-in-one'
         meth = self['method']
-        if meth == 'stdlib':
-            from cubicweb.wsgi import server
-        else:
-            from cubicweb.wsgi import wz as server
+        server = WSGI_CHOICES[meth]
         return server.run(config)