fix issue #84. thanks!

This commit is contained in:
benoitc 2010-08-16 12:10:27 +02:00
parent ea77f56449
commit e625188196
2 changed files with 31 additions and 3 deletions

View File

@ -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()
DjangoApplication("%prog [OPTIONS] [SETTINGS_PATH]").run()

View File

@ -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 "+