fix paster application

This commit is contained in:
Benoit Chesneau 2010-05-17 06:46:12 +02:00 committed by Paul J. Davis
parent cdffaeff16
commit d46dfad91f
3 changed files with 23 additions and 17 deletions

View File

@ -28,7 +28,7 @@ class Application(object):
# Load up the any app specific configuration
if cfg:
for k, v in cfg:
for k, v in cfg.items():
self.cfg.set(k.lower(), v)
# Load up the config file if its found.

View File

@ -10,6 +10,9 @@ import sys
from paste.deploy import loadapp, loadwsgi
SERVER = loadwsgi.SERVER
from gunicorn.app.base import Application
from gunicorn.config import Config
class PasterApplication(Application):
def init(self, parser, opts, args):
@ -31,11 +34,11 @@ class PasterApplication(Application):
def app_config(self):
cx = loadwsgi.loadcontext(SERVER, self.cfgurl, relative_to=self.relpath)
gc, lc = cx.global_conf, cx.local_conf
gc, lc = cx.global_conf.copy(), cx.local_conf.copy()
cfg = {}
host, port = lc.get('host'), lc.get('port')
host, port = lc.pop('host', ''), lc.pop('port', '')
if host and port:
cfg['bind'] = '%s:%s' % (host, port)
elif host:
@ -52,25 +55,28 @@ class PasterApplication(Application):
class PasterServerApplication(Application):
def __init__(self, app, *args, **kwargs):
self.log = logging.getLogger(__name__)
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
self.cfg = Config()
self.app = app
cfg = {}
host, port = kwargs.get('host'), kwargs.get('port')
if host and port:
cfg['bind'] = '%s:%s' % (host, port)
elif host:
cfg['bind'] = host
cfg = kwargs.copy()
if port and not host.startswith("unix:"):
bind = "%s:%s" % (host, port)
else:
bind = host
cfg["bind"] = bind
if gcfg:
for k, v in list(gcfg.items()):
if k.lower() in self.cfg.settings:
self.cfg.set(k.lower(), v)
self.cfg.default_proc_name = kwargs.__file__
cfg[k] = v
cfg["default_proc_name"] = cfg['__file__']
self.configure_logging(cfg)
for k, v in list(cfg.items()):
if k.lower() in self.cfg.settings and v is not None:
self.cfg.set(k.lower(), v)
self.configure_logging()
def load(self):
return self.app

View File

@ -27,7 +27,7 @@ def run_paster():
from gunicorn.app.pasterapp import PasterApplication
PasterApplication("%prog [OPTIONS] pasteconfig.ini").run()
def paste_server(*args, **kwargs):
def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
"""\
A paster server.
@ -40,7 +40,7 @@ def paste_server(*args, **kwargs):
"""
from gunicorn.app.pasterapp import PasterServerApplication
PasterServerApplication(app, *args, **kwargs).run()
PasterServerApplication(app, gcfg=gcfg, host=host, port=port, *args, **kwargs).run()