From ec2ee0b1278f32f79cc6a40ad0247eb2cf14bf90 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Mon, 5 Aug 2013 21:59:00 -0700 Subject: [PATCH] Support for python config file option in paster It is now possible to specify a file with "config" as an application configuration key in a paste deploy configuration file. This allows paster applications to use the full range of gunicorn settings even when using paste/pserve rather than gunicorn_paster. Fixes #540. --- docs/source/run.rst | 2 ++ .../frameworks/pylonstest/development.ini | 2 ++ gunicorn/app/pasterapp.py | 19 +++++++------------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/source/run.rst b/docs/source/run.rst index 072b7be7..a01624f6 100644 --- a/docs/source/run.rst +++ b/docs/source/run.rst @@ -115,6 +115,8 @@ you can specify the Gunicorn server settings in your configuration file:: use = egg:gunicorn#main host = 127.0.0.1 port = 5000 + # Uncomment the line below to use other advanced gunicorn settings + #config = %(here)/gunicorn.conf.py And then as per usual:: diff --git a/examples/frameworks/pylonstest/development.ini b/examples/frameworks/pylonstest/development.ini index 4a14bdc7..4a6d2f45 100644 --- a/examples/frameworks/pylonstest/development.ini +++ b/examples/frameworks/pylonstest/development.ini @@ -14,6 +14,8 @@ error_email_from = paste@localhost use = egg:gunicorn#main host = 127.0.0.1 port = 5000 +# Uncomment and replace with a file containing advanced gunicorn configuration +#config = %(here)/gunicorn.conf.py [app:main] use = egg:pylonstest diff --git a/gunicorn/app/pasterapp.py b/gunicorn/app/pasterapp.py index f3f04bf0..5543e72e 100644 --- a/gunicorn/app/pasterapp.py +++ b/gunicorn/app/pasterapp.py @@ -16,7 +16,7 @@ from paste.deploy import loadapp, loadwsgi SERVER = loadwsgi.SERVER from gunicorn.app.base import Application -from gunicorn.config import Config +from gunicorn.config import Config, get_default_config_file from gunicorn import util @@ -126,17 +126,12 @@ class PasterServerApplication(PasterBaseApplication): sys.stderr.flush() sys.exit(1) - def load_config(self): - if not hasattr(self, "cfgfname"): - return - - cfg = self.app_config() - for k, v in cfg.items(): - try: - self.cfg.set(k.lower(), v) - except: - sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v)) - raise + if cfg.get("config"): + self.load_config_from_file(cfg["config"]) + else: + default_config = get_defalult_config_file() + if default_config is not None: + self.load_config_from_file(default_config) def load(self): if hasattr(self, "cfgfname"):