Add and use paste server selector. Yeah! Smart solutions!
authorChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 9 Oct 2014 23:24:14 +0000 (18:24 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 10 Oct 2014 19:42:17 +0000 (14:42 -0500)
This commit sponsored by Tryggvi Björgvinsson.  Thank you!

mediagoblin/app.py
paste.py3.ini
setup.py

index b3e41835c38da837c5d2db00eb535b6a761691ca..9014bf474c9e92f69cc57b3effa6542f39ae005d 100644 (file)
@@ -290,3 +290,34 @@ def paste_app_factory(global_config, **app_config):
     mgoblin_app = hook_transform('wrap_wsgi', mgoblin_app)
 
     return mgoblin_app
+
+
+def paste_server_selector(wsgi_app, global_config=None, **app_config):
+    """
+    Select between gunicorn and paste depending on what ia available
+    """
+    # See if we can import the gunicorn server...
+    # otherwise we'll use the paste server
+    try:
+        import gunicorn
+    except ImportError:
+        gunicorn = None
+
+    if gunicorn is None:
+        # use paste
+        from paste.httpserver import server_runner
+
+        cleaned_app_config = dict(
+            [(key, app_config[key])
+             for key in app_config
+             if key in ["host", "port", "handler", "ssl_pem", "ssl_context",
+                        "server_version", "protocol_version", "start_loop",
+                        "daemon_threads", "socket_timeout", "use_threadpool",
+                        "threadpool_workers", "threadpool_options",
+                        "request_queue_size"]])
+
+        return server_runner(wsgi_app, global_config, **cleaned_app_config)
+    else:
+        # use gunicorn
+        from gunicorn.app.pasterapp import PasterServerApplication
+        return PasterServerApplication(wsgi_app, global_config, **app_config)
index afd5982b04dbbf0ea073b0efaa5991e686681f38..77364c0929c973efdcb9a578eebe621fe3a86820 100644 (file)
@@ -52,7 +52,7 @@ debug = false
 # The server that is run by default.
 # By default, should only be accessable locally
 [server:main]
-use = egg:gunicorn
+use = egg:mediagoblin#paste_server_selector
 host = 127.0.0.1
 port = 6543
 # Gunicorn settings. See http://docs.gunicorn.org/en/19.0/settings.html
index 562252e3797a300c02061de535f107176baca7f2..624aa409179605a6cc300bf2ca66b48b1e3afcc0 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -123,6 +123,9 @@ try:
         [paste.app_factory]
         app = mediagoblin.app:paste_app_factory
 
+        [paste.server_runner]
+        paste_server_selector = mediagoblin.app:paste_server_selector
+
         [paste.filter_app_factory]
         errors = mediagoblin.errormiddleware:mgoblin_error_middleware