Added some PYTHONPATH hackery to manage.py, wolnelektury.wsgi and wolnelektury.fcgi.
[wolnelektury.git] / wolnelektury.wsgi
index adeb8aa..2732713 100644 (file)
@@ -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()
+