From e625188196182bc4b2e1aeb54935d542ccdc8091 Mon Sep 17 00:00:00 2001 From: benoitc Date: Mon, 16 Aug 2010 12:10:27 +0200 Subject: [PATCH] fix issue #84. thanks! --- gunicorn/app/djangoapp.py | 30 +++++++++++++++++++- gunicorn/management/commands/run_gunicorn.py | 4 +-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/gunicorn/app/djangoapp.py b/gunicorn/app/djangoapp.py index 18b75332..1baf6daa 100644 --- a/gunicorn/app/djangoapp.py +++ b/gunicorn/app/djangoapp.py @@ -51,6 +51,34 @@ class DjangoApplicationCommand(Application): def __init__(self, options, admin_media_path): self.cfg = Config() self.callable = None + + # Load up the config file if its found. + + config_file = options.get("config") or "" + if config_file and os.path.exists(config_file): + cfg = { + "__builtins__": __builtins__, + "__name__": "__config__", + "__file__": config_file, + "__doc__": None, + "__package__": None + } + try: + execfile(config_file, cfg, cfg) + except Exception, e: + print "Failed to read config file: %s" % config_file + traceback.print_exc() + sys.exit(1) + + for k, v in list(cfg.items()): + # Ignore unknown names + if k not in self.cfg.settings: + continue + try: + self.cfg.set(k.lower(), v) + except: + sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v)) + raise for k, v in list(options.items()): if k.lower() in self.cfg.settings and v is not None: @@ -81,4 +109,4 @@ def run(): applications. """ from gunicorn.app.djangoapp import DjangoApplication - DjangoApplication("%prog [OPTIONS] [SETTINGS_PATH]").run() \ No newline at end of file + DjangoApplication("%prog [OPTIONS] [SETTINGS_PATH]").run() diff --git a/gunicorn/management/commands/run_gunicorn.py b/gunicorn/management/commands/run_gunicorn.py index dd599f9b..9e728bd2 100644 --- a/gunicorn/management/commands/run_gunicorn.py +++ b/gunicorn/management/commands/run_gunicorn.py @@ -13,12 +13,12 @@ from django.conf import settings from django.utils import translation from gunicorn.app.djangoapp import DjangoApplicationCommand - + class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--adminmedia', dest='admin_media_path', default='', help='Specifies the directory from which to serve admin media.'), - make_option('-c', '--config', dest='gconfig', type='string', + make_option('-c', '--config', dest='config', type='string', help='Gunicorn Config file. [%default]'), make_option('-k', '--worker-class', dest='worker_class', help="The type of request processing to use "+