mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #1481 from benoitc/fix/1349-config-module-path
Set CWD and Python path before and after config
This commit is contained in:
commit
ccad26dd91
@ -75,8 +75,18 @@ class BaseApplication(object):
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
class Application(BaseApplication):
|
class Application(BaseApplication):
|
||||||
|
|
||||||
|
def chdir(self):
|
||||||
|
# chdir to the configured path before loading,
|
||||||
|
# default is the current dir
|
||||||
|
os.chdir(self.cfg.chdir)
|
||||||
|
|
||||||
|
# add the path to sys.path
|
||||||
|
if self.cfg.chdir not in sys.path:
|
||||||
|
sys.path.insert(0, self.cfg.chdir)
|
||||||
|
|
||||||
def get_config_from_filename(self, filename):
|
def get_config_from_filename(self, filename):
|
||||||
|
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
@ -142,6 +152,9 @@ class Application(BaseApplication):
|
|||||||
# optional settings from apps
|
# optional settings from apps
|
||||||
cfg = self.init(parser, args, args.args)
|
cfg = self.init(parser, args, args.args)
|
||||||
|
|
||||||
|
# set up import paths and follow symlinks
|
||||||
|
self.chdir()
|
||||||
|
|
||||||
# Load up the any app specific configuration
|
# Load up the any app specific configuration
|
||||||
if cfg:
|
if cfg:
|
||||||
for k, v in cfg.items():
|
for k, v in cfg.items():
|
||||||
@ -174,6 +187,10 @@ class Application(BaseApplication):
|
|||||||
continue
|
continue
|
||||||
self.cfg.set(k.lower(), v)
|
self.cfg.set(k.lower(), v)
|
||||||
|
|
||||||
|
# current directory might be changed by the config now
|
||||||
|
# set up import paths and follow symlinks
|
||||||
|
self.chdir()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.cfg.check_config:
|
if self.cfg.check_config:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -163,10 +163,6 @@ class PasterServerApplication(PasterBaseApplication):
|
|||||||
self.load_config_from_file(default_config)
|
self.load_config_from_file(default_config)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
# chdir to the configured path before loading,
|
|
||||||
# default is the current dir
|
|
||||||
os.chdir(self.cfg.chdir)
|
|
||||||
|
|
||||||
return self.app
|
return self.app
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
# See the NOTICE for more information.
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from gunicorn.errors import ConfigError
|
from gunicorn.errors import ConfigError
|
||||||
from gunicorn.app.base import Application
|
from gunicorn.app.base import Application
|
||||||
@ -37,23 +36,11 @@ class WSGIApplication(Application):
|
|||||||
self.cfg.set("default_proc_name", args[0])
|
self.cfg.set("default_proc_name", args[0])
|
||||||
self.app_uri = args[0]
|
self.app_uri = args[0]
|
||||||
|
|
||||||
def chdir(self):
|
|
||||||
# chdir to the configured path before loading,
|
|
||||||
# default is the current dir
|
|
||||||
os.chdir(self.cfg.chdir)
|
|
||||||
|
|
||||||
# add the path to sys.path
|
|
||||||
sys.path.insert(0, self.cfg.chdir)
|
|
||||||
|
|
||||||
def load_wsgiapp(self):
|
def load_wsgiapp(self):
|
||||||
self.chdir()
|
|
||||||
|
|
||||||
# load the app
|
# load the app
|
||||||
return util.import_app(self.app_uri)
|
return util.import_app(self.app_uri)
|
||||||
|
|
||||||
def load_pasteapp(self):
|
def load_pasteapp(self):
|
||||||
self.chdir()
|
|
||||||
|
|
||||||
# load the paste app
|
# load the paste app
|
||||||
from .pasterapp import load_pasteapp
|
from .pasterapp import load_pasteapp
|
||||||
return load_pasteapp(self.cfgurl, self.relpath, global_conf=self.cfg.paste_global_conf)
|
return load_pasteapp(self.cfgurl, self.relpath, global_conf=self.cfg.paste_global_conf)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user