From 443a6c83635369c523b4c10357f4aaeb4a86884f Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Wed, 17 Feb 2010 10:01:05 +0100 Subject: [PATCH] refactor paster entry point to use Config object. --- gunicorn/main.py | 47 +++++++------------- gunicorn/management/commands/run_gunicorn.py | 3 -- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/gunicorn/main.py b/gunicorn/main.py index fab3e031..940bccfa 100644 --- a/gunicorn/main.py +++ b/gunicorn/main.py @@ -154,40 +154,27 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None, port = 5000 """ + options = kwargs.copy() + if port and not host.startswith("unix:"): + bind = "%s:%s" % (host, port) + else: + bind = host + options['bind'] = bind - bind_addr = util.parse_address(util.to_bytestring(host), port) - - # set others options - debug = kwargs.get('debug') - workers = kwargs.get("workers", 1) - pid = kwargs.get("pid") - daemon = kwargs.get("daemon") - umask = kwargs.get('umask', UMASK) - user = kwargs.get('user') - group = kwargs.get('group') if global_conf: - workers = int(global_conf.get('workers', workers)) - debug = global_conf.get('debug', debug) == "true" - if debug: - # we force to one worker in debug mode. - workers = 1 - pid = global_conf.get('pid', pid) - daemon = global_conf.get('daemon', daemonize) - umask = global_conf.get('umask', umask) - user = global_conf.get('user', user) - group = global_conf.get('group', group) - - kwargs = dict( - debug=debug, - pidfile=pid - ) - - arbiter = Arbiter(bind_addr, workers, app, **kwargs) - if daemon == "true": - daemonize(umask) + for key, value in list(global_conf.items()): + if value and value is not None: + options[key] = value + + conf = Config(options) + arbiter = Arbiter(conf.address, conf.workers, app, debug=conf["debug"], + pidfile=pidfile=conf["pidfile"], config=conf) + if conf["daemon"] : + daemonize(conf["umask"]) else: os.setpgrp() - set_owner_process(user, group) + set_owner_process(conf["user"], conf["group"]) + configure_logging(conf) arbiter.run() def run(): diff --git a/gunicorn/management/commands/run_gunicorn.py b/gunicorn/management/commands/run_gunicorn.py index de26656c..a300d1b7 100644 --- a/gunicorn/management/commands/run_gunicorn.py +++ b/gunicorn/management/commands/run_gunicorn.py @@ -47,7 +47,6 @@ class Command(BaseCommand): if args: raise CommandError('Usage is runserver %s' % self.args) - options['bind'] = addrport or '127.0.0.1' conf = Config(options) @@ -57,8 +56,6 @@ class Command(BaseCommand): print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE) - - print "Development server is running at %s" % str(conf.address) print "Quit the server with %s." % quit_command