add possibility to set the settings.py path in gunicorn_django command.

(allows you to use different files too)
This commit is contained in:
Benoit Chesneau 2010-02-10 10:10:40 +01:00
parent 593051a43d
commit a7f3d941a3

View File

@ -174,13 +174,25 @@ def run():
def run_django(): def run_django():
def settings_notfound(path):
error = "Settings file '%s' not found in current folder.\n" % path
sys.stderr.write(error)
sys.stderr.flush()
sys.exit(1)
def get_app(parser, opts, args): def get_app(parser, opts, args):
import django.core.handlers.wsgi import django.core.handlers.wsgi
PROJECT_PATH = os.getcwd() PROJECT_PATH = os.getcwd()
if not os.path.isfile(os.path.join(PROJECT_PATH, "settings.py")): settings_path = os.path.join(PROJECT_PATH, "settings.py")
print >>sys.stderr, "settings file not found." if not os.path.isfile(settings_path) and not args:
sys.exit(1) settings_notfound(settings_path)
else:
settings_path = os.path.abspath(os.path.normpath(args[0]))
if not os.path.isfile(settings_path):
settings_notfound(settings_path)
else:
PROJECT_PATH = os.path.dirname(settings_path)
PROJECT_NAME = os.path.split(PROJECT_PATH)[-1] PROJECT_NAME = os.path.split(PROJECT_PATH)[-1]
@ -193,7 +205,7 @@ def run_django():
# django wsgi app # django wsgi app
return django.core.handlers.wsgi.WSGIHandler() return django.core.handlers.wsgi.WSGIHandler()
main(__usage__, get_app) main("%prog [OPTIONS] [SETTINGS_PATH]", get_app)
def run_paster(): def run_paster():