From: Marek Stępniowski Date: Wed, 1 Oct 2008 11:17:05 +0000 (+0200) Subject: Added some PYTHONPATH hackery to manage.py, wolnelektury.wsgi and wolnelektury.fcgi. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/dcee135486c7e144626b0658cfe000f1303ab80a?ds=sidebyside;hp=941ff3d02aa4e8566863b0f06730186761710c13 Added some PYTHONPATH hackery to manage.py, wolnelektury.wsgi and wolnelektury.fcgi. --- diff --git a/wolnelektury.fcgi b/wolnelektury.fcgi index badca95ae..fd41ab24d 100644 --- a/wolnelektury.fcgi +++ b/wolnelektury.fcgi @@ -1,16 +1,21 @@ -#!/usr/bin/python +#!/usr/bin/env python +from os.path import abspath, dirname, join import sys -import os -from os import path -# Add project directories to PYTHONPATH -PROJECT_DIR = path.abspath(path.dirname(__file__)) -PROJECT_MODULE_DIRS = [PROJECT_DIR + '/lib', PROJECT_DIR + '/apps', PROJECT_DIR + '/wolnelektury'] +# Redirect sys.stdout to sys.stderr for bad libraries like geopy that use +# print statements for optional import exceptions. +sys.stdout = sys.stderr -sys.path = PROJECT_MODULE_DIRS + sys.path +# Add apps and lib directories to PYTHONPATH +sys.path.insert(0, abspath(join(dirname(__file__), '../apps'))) +sys.path.insert(0, abspath(join(dirname(__file__), '../lib'))) -# Set the DJANGO_SETTINGS_MODULE environment variable. -os.environ['DJANGO_SETTINGS_MODULE'] = 'settings_eo' +# Emulate manage.py path hacking. +sys.path.insert(0, abspath(join(dirname(__file__), "../../"))) +sys.path.insert(0, abspath(join(dirname(__file__), "../"))) + +# Run Django +os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.core.servers.fastcgi import runfastcgi runfastcgi(method='threaded', daemonize='false') diff --git a/wolnelektury.wsgi b/wolnelektury.wsgi index adeb8aa33..27327133b 100644 --- a/wolnelektury.wsgi +++ b/wolnelektury.wsgi @@ -1,16 +1,22 @@ +#!/usr/bin/env python +from os.path import abspath, dirname, join import sys -import os -from os import path -# Add project directories to PYTHONPATH -PROJECT_DIR = path.abspath(path.dirname(__file__)) -PROJECT_MODULE_DIRS = [PROJECT_DIR + '/lib', PROJECT_DIR + '/apps', PROJECT_DIR + '/wolnelektury'] +# Redirect sys.stdout to sys.stderr for bad libraries like geopy that use +# print statements for optional import exceptions. +sys.stdout = sys.stderr -sys.path = PROJECT_MODULE_DIRS + sys.path +# Add apps and lib directories to PYTHONPATH +sys.path.insert(0, abspath(join(dirname(__file__), '../apps'))) +sys.path.insert(0, abspath(join(dirname(__file__), '../lib'))) +# Emulate manage.py path hacking. +sys.path.insert(0, abspath(join(dirname(__file__), "../../"))) +sys.path.insert(0, abspath(join(dirname(__file__), "../"))) # Run Django -from django.core.handlers.wsgi import WSGIHandler - os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' + +from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler() + diff --git a/wolnelektury/manage.py b/wolnelektury/manage.py index a26ce5c88..a9acc04a7 100755 --- a/wolnelektury/manage.py +++ b/wolnelektury/manage.py @@ -1,9 +1,8 @@ #!/usr/bin/env python from os.path import abspath, dirname, join -from site import addsitedir import sys -path = addsitedir(abspath(join(dirname(__file__), '../external_libs')), set()) -if path: sys.path = list(path) + sys.path + +# Add apps and lib directories to PYTHONPATH sys.path.insert(0, abspath(join(dirname(__file__), '../apps'))) sys.path.insert(0, abspath(join(dirname(__file__), '../lib')))