mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
The config may be specified as a Python module, in which case we want to ensure that the Python path is fixed up properly before we try to load it. That means we should follow symlinks and add the current working directory before and after the configuration is loaded. Fix #1349
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
# -*- coding: utf-8 -
|
|
#
|
|
# This file is part of gunicorn released under the MIT license.
|
|
# See the NOTICE for more information.
|
|
|
|
import os
|
|
|
|
from gunicorn.errors import ConfigError
|
|
from gunicorn.app.base import Application
|
|
from gunicorn import util
|
|
|
|
|
|
class WSGIApplication(Application):
|
|
def init(self, parser, opts, args):
|
|
if opts.paste:
|
|
app_name = 'main'
|
|
path = opts.paste
|
|
if '#' in path:
|
|
path, app_name = path.split('#')
|
|
path = os.path.abspath(os.path.normpath(
|
|
os.path.join(util.getcwd(), path)))
|
|
|
|
if not os.path.exists(path):
|
|
raise ConfigError("%r not found" % path)
|
|
|
|
# paste application, load the config
|
|
self.cfgurl = 'config:%s#%s' % (path, app_name)
|
|
self.relpath = os.path.dirname(path)
|
|
|
|
from .pasterapp import paste_config
|
|
return paste_config(self.cfg, self.cfgurl, self.relpath)
|
|
|
|
if len(args) < 1:
|
|
parser.error("No application module specified.")
|
|
|
|
self.cfg.set("default_proc_name", args[0])
|
|
self.app_uri = args[0]
|
|
|
|
def load_wsgiapp(self):
|
|
# load the app
|
|
return util.import_app(self.app_uri)
|
|
|
|
def load_pasteapp(self):
|
|
# load the paste app
|
|
from .pasterapp import load_pasteapp
|
|
return load_pasteapp(self.cfgurl, self.relpath, global_conf=self.cfg.paste_global_conf)
|
|
|
|
def load(self):
|
|
if self.cfg.paste is not None:
|
|
return self.load_pasteapp()
|
|
else:
|
|
return self.load_wsgiapp()
|
|
|
|
|
|
def run():
|
|
"""\
|
|
The ``gunicorn`` command line runner for launching Gunicorn with
|
|
generic WSGI applications.
|
|
"""
|
|
from gunicorn.app.wsgiapp import WSGIApplication
|
|
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|