Support running specific paster apps from .ini

Close #400
This commit is contained in:
Randall Leeds 2014-03-08 18:00:01 -08:00
parent 3ad5ee9120
commit e5442332fe
4 changed files with 17 additions and 3 deletions

View File

@ -96,5 +96,9 @@ For example:
gunicorn --paste development.ini -b :8080 --chdir /path/to/project gunicorn --paste development.ini -b :8080 --chdir /path/to/project
Or use a different application:
gunicorn --paste development.ini#admin -b :8080 --chdir /path/to/project
It is all here. No configuration files nor additional python modules to It is all here. No configuration files nor additional python modules to
write !! write !!

View File

@ -25,6 +25,7 @@ def paste_config(gconfig, config_url, relative_to, global_conf=None):
sys.path.insert(0, relative_to) sys.path.insert(0, relative_to)
pkg_resources.working_set.add_entry(relative_to) pkg_resources.working_set.add_entry(relative_to)
config_url = config_url.split('#')[0]
cx = loadwsgi.loadcontext(SERVER, config_url, relative_to=relative_to, cx = loadwsgi.loadcontext(SERVER, config_url, relative_to=relative_to,
global_conf=global_conf) global_conf=global_conf)
gc, lc = cx.global_conf.copy(), cx.local_conf.copy() gc, lc = cx.global_conf.copy(), cx.local_conf.copy()

View File

@ -14,14 +14,18 @@ from gunicorn import util
class WSGIApplication(Application): class WSGIApplication(Application):
def init(self, parser, opts, args): def init(self, parser, opts, args):
if opts.paste and opts.paste is not None: if opts.paste and opts.paste is not None:
app_name = 'main'
path = opts.paste
if '#' in path:
path, app_name = path.split('#')
path = os.path.abspath(os.path.normpath( path = os.path.abspath(os.path.normpath(
os.path.join(util.getcwd(), opts.paste))) os.path.join(util.getcwd(), path)))
if not os.path.exists(path): if not os.path.exists(path):
raise ConfigError("%r not found" % path) raise ConfigError("%r not found" % path)
# paste application, load the config # paste application, load the config
self.cfgurl = 'config:%s' % path self.cfgurl = 'config:%s#%s' % (path, app_name)
self.relpath = os.path.dirname(path) self.relpath = os.path.dirname(path)
from .pasterapp import paste_config from .pasterapp import paste_config

View File

@ -1222,7 +1222,12 @@ class Paste(Setting):
validator = validate_string validator = validate_string
default = None default = None
desc = """\ desc = """\
Load a paste.deploy config file. Load a paste.deploy config file. The argument may contain a "#" symbol
followed by the name of an app section from the config file, e.g.
"production.ini#admin".
At this time, using alternate server blocks is not supported. Use the
command line arguments to control server configuration instead.
""" """