mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix paster application
This commit is contained in:
parent
cdffaeff16
commit
d46dfad91f
@ -28,7 +28,7 @@ class Application(object):
|
|||||||
|
|
||||||
# Load up the any app specific configuration
|
# Load up the any app specific configuration
|
||||||
if cfg:
|
if cfg:
|
||||||
for k, v in cfg:
|
for k, v in cfg.items():
|
||||||
self.cfg.set(k.lower(), v)
|
self.cfg.set(k.lower(), v)
|
||||||
|
|
||||||
# Load up the config file if its found.
|
# Load up the config file if its found.
|
||||||
|
|||||||
@ -10,6 +10,9 @@ import sys
|
|||||||
from paste.deploy import loadapp, loadwsgi
|
from paste.deploy import loadapp, loadwsgi
|
||||||
SERVER = loadwsgi.SERVER
|
SERVER = loadwsgi.SERVER
|
||||||
|
|
||||||
|
from gunicorn.app.base import Application
|
||||||
|
from gunicorn.config import Config
|
||||||
|
|
||||||
class PasterApplication(Application):
|
class PasterApplication(Application):
|
||||||
|
|
||||||
def init(self, parser, opts, args):
|
def init(self, parser, opts, args):
|
||||||
@ -31,11 +34,11 @@ class PasterApplication(Application):
|
|||||||
|
|
||||||
def app_config(self):
|
def app_config(self):
|
||||||
cx = loadwsgi.loadcontext(SERVER, self.cfgurl, relative_to=self.relpath)
|
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 = {}
|
cfg = {}
|
||||||
|
|
||||||
host, port = lc.get('host'), lc.get('port')
|
host, port = lc.pop('host', ''), lc.pop('port', '')
|
||||||
if host and port:
|
if host and port:
|
||||||
cfg['bind'] = '%s:%s' % (host, port)
|
cfg['bind'] = '%s:%s' % (host, port)
|
||||||
elif host:
|
elif host:
|
||||||
@ -52,25 +55,28 @@ class PasterApplication(Application):
|
|||||||
|
|
||||||
class PasterServerApplication(Application):
|
class PasterServerApplication(Application):
|
||||||
|
|
||||||
def __init__(self, app, *args, **kwargs):
|
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
|
||||||
self.log = logging.getLogger(__name__)
|
|
||||||
self.cfg = Config()
|
self.cfg = Config()
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
cfg = {}
|
cfg = kwargs.copy()
|
||||||
host, port = kwargs.get('host'), kwargs.get('port')
|
|
||||||
if host and port:
|
if port and not host.startswith("unix:"):
|
||||||
cfg['bind'] = '%s:%s' % (host, port)
|
bind = "%s:%s" % (host, port)
|
||||||
elif host:
|
else:
|
||||||
cfg['bind'] = host
|
bind = host
|
||||||
|
cfg["bind"] = bind
|
||||||
|
|
||||||
if gcfg:
|
if gcfg:
|
||||||
for k, v in list(gcfg.items()):
|
for k, v in list(gcfg.items()):
|
||||||
if k.lower() in self.cfg.settings:
|
cfg[k] = v
|
||||||
self.cfg.set(k.lower(), v)
|
cfg["default_proc_name"] = cfg['__file__']
|
||||||
self.cfg.default_proc_name = kwargs.__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):
|
def load(self):
|
||||||
return self.app
|
return self.app
|
||||||
|
|||||||
@ -27,7 +27,7 @@ def run_paster():
|
|||||||
from gunicorn.app.pasterapp import PasterApplication
|
from gunicorn.app.pasterapp import PasterApplication
|
||||||
PasterApplication("%prog [OPTIONS] pasteconfig.ini").run()
|
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.
|
A paster server.
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ def paste_server(*args, **kwargs):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from gunicorn.app.pasterapp import PasterServerApplication
|
from gunicorn.app.pasterapp import PasterServerApplication
|
||||||
PasterServerApplication(app, *args, **kwargs).run()
|
PasterServerApplication(app, gcfg=gcfg, host=host, port=port, *args, **kwargs).run()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user