From ae79f33785effc49d745cf51e1cbba86f52f79f5 Mon Sep 17 00:00:00 2001 From: benoitc Date: Mon, 23 Aug 2010 11:06:00 +0200 Subject: [PATCH] build from Settings list the run_gunicorn option list. --- gunicorn/config.py | 13 ++-- gunicorn/management/commands/run_gunicorn.py | 64 ++++++++++++-------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/gunicorn/config.py b/gunicorn/config.py index 17884296..25e8840c 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -22,14 +22,17 @@ def wrap_method(func): return func(*args, **kwargs) return _wrapped +def make_settings(): + settings = {} + for s in KNOWN_SETTINGS: + setting = s() + settings[setting.name] = setting.copy() + return settings + class Config(object): def __init__(self, usage=None): - self.settings = {} - for s in KNOWN_SETTINGS: - setting = s() - self.settings[setting.name] = setting.copy() - + self.settings = make_settings() self.usage = usage def __getattr__(self, name): diff --git a/gunicorn/management/commands/run_gunicorn.py b/gunicorn/management/commands/run_gunicorn.py index 8030a965..2494e8cc 100644 --- a/gunicorn/management/commands/run_gunicorn.py +++ b/gunicorn/management/commands/run_gunicorn.py @@ -13,33 +13,47 @@ from django.conf import settings from django.utils import translation from gunicorn.app.djangoapp import DjangoApplicationCommand +from gunicorn.config import make_settings + +def make_options(): + g_settings = make_settings() + + keys = g_settings.keys() + def sorter(k): + return (g_settings[k].section, g_settings[k].order) + + opts = [ + make_option('--adminmedia', dest='admin_media_path', default='', + help='Specifies the directory from which to serve admin media.') + ] + + for k in keys: + setting = g_settings[k] + if not setting.cli: + continue + + args = tuple(setting.cli) + + kwargs = { + "dest": setting.name, + "metavar": setting.meta or None, + "action": setting.action or "store", + "type": setting.type or "string", + "default": None, + "help": "%s [%s]" % (setting.short, setting.default) + } + if kwargs["action"] != "store": + kwargs.pop("type") + + opts.append(make_option(*args, **kwargs)) + + return tuple(opts) + +GUNICORN_OPTIONS = make_options() + 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='config', type='string', - help='Gunicorn Config file. [%default]'), - make_option('-k', '--worker-class', dest='worker_class', - help="The type of request processing to use "+ - "[egg:gunicorn#sync]"), - make_option('-w', '--workers', dest='workers', - help='Specifies the number of worker processes to use.'), - make_option('--pid', dest='pidfile', - help='set the background PID file'), - make_option( '--daemon', dest='daemon', action="store_true", - help='Run daemonized in the background.'), - make_option('--umask', dest='umask', - help="Define umask of daemon process"), - make_option('-u', '--user', dest="user", - help="Change worker user"), - make_option('-g', '--group', dest="group", - help="Change worker group"), - make_option('-n', '--name', dest='proc_name', - help="Process name"), - make_option('--preload', dest='preload_app', action='store_true', - help="Load application code before the worker processes are forked.") - ) + option_list = BaseCommand.option_list + GUNICORN_OPTIONS help = "Starts a fully-functional Web server using gunicorn." args = '[optional port number, or ipaddr:port or unix:/path/to/sockfile]'