# -*- mode: python ;-*-

import os
import sys
import site

# Some libraries (eg. geopy) have an annoying habit of printing to stdout,
# which is a no-no under mod_wsgi.
# Workaround as per http://code.google.com/p/modwsgi/wiki/ApplicationIssues
sys.stdout = sys.stderr

# This may need to be adjusted based on your installation path.
env_root = os.path.join(os.path.dirname(__file__),
                        '..', '..', '..', '..')
env_root = os.path.abspath(env_root)

sitepackages_root = os.path.join(env_root, 'lib')
for d in os.listdir(sitepackages_root):
    if d.startswith('python'):
      
        site.addsitedir(
         os.path.join(sitepackages_root, d, 'site-packages'))
        break
else:
    raise RuntimeError("Could not find any site-packages to add in %r" % env_root)

os.environ['DJANGO_SETTINGS_MODULE'] = 'fixcity.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp/fixcity-python-eggs'

import django.core.handlers.wsgi
from wsgilog import WsgiLog

application = django.core.handlers.wsgi.WSGIHandler()

# Log uncaught exceptions to stderr via WSGI middleware.
#
# This isn't usually necessary: when settings.DEBUG is true, the
# default behavior is to dump errors to stdout and show them nicely in
# the browser; when settings.DEBUG is false, our custom 500 error view
# takes care of logging. But if for any reason *that* view blows up,
# we fall back to this.  (I wouldn't have bothered except I figured
# out how to get this working before I hooked up logging in that
# view.)

# WsgiLog is a bit funny about keyword args: it checks for presence,
# not value, so passing eg. tofile=False means "log to the default
# file", not "don't do file logging".  So I'm not passing any of those
# args.
application = WsgiLog(application, tostream=True)

@@ -267,72 +267,334 @@
 rr%0A%0A
+%0A
 # 
-This may need to be adjusted based on your installation path.%0A
+-*- mode: python ;-*-%0A%0Aimport os%0Aimport sys%0Aimport site%0A%0A# Some libraries (eg. geopy) have an annoying habit of printing to stdout,%0A# which is a no-no under mod_wsgi.%0A# Workaround as per http://code.google.com/p/modwsgi/wiki/ApplicationIssues%0Asys.stdout = sys.stderr%0A%0A# Try to find a virtualenv in our parent chain.%0AHERE = 
 env_
@@ -608,20 +608,23 @@
 os.path.
-join
+abspath
 (os.path
@@ -645,145 +645,403 @@
 e__)
-,%0A                        '..', '..', '..', '..')%0Aenv_root = os.path.abspath(env_root)%0A%0Asitepackages_root = os.path.join(env_root, 'lib')
+)%0Afound = False%0Awhile env_root != '/':%0A    env_root = os.path.abspath(os.path.dirname(env_root))%0A    if os.path.exists(os.path.join(env_root, 'bin', 'activate')):%0A        found = True%0A        break%0Aassert found, %22didn't find a virtualenv in any parent of %25s%22 %25 HERE%0A%0Asitepackages_root = os.path.join(env_root, 'lib')%0Aassert os.path.exists(sitepackages_root), %22no such dir %25s%22 %25 sitepackages_root
 %0Afor
@@ -1112,15 +1112,8 @@
 '):%0A
-      %0A
     
@@ -1136,18 +1136,8 @@
 dir(
-%0A         
 os.p
@@ -1408,16 +1408,17 @@
 -eggs'%0A%0A
+%0A
 import d
@@ -1445,36 +1445,8 @@
 wsgi
-%0Afrom wsgilog import WsgiLog
 %0A%0Aap
@@ -1501,748 +1501,4 @@
 r()%0A
-%0A# Log uncaught exceptions to stderr via WSGI middleware.%0A#%0A# This isn't usually necessary: when settings.DEBUG is true, the%0A# default behavior is to dump errors to stdout and show them nicely in%0A# the browser; when settings.DEBUG is false, our custom 500 error view%0A# takes care of logging. But if for any reason *that* view blows up,%0A# we fall back to this.  (I wouldn't have bothered except I figured%0A# out how to get this working before I hooked up logging in that%0A# view.)%0A%0A# WsgiLog is a bit funny about keyword args: it checks for presence,%0A# not value, so passing eg. tofile=False means %22log to the default%0A# file%22, not %22don't do file logging%22.  So I'm not passing any of those%0A# args.%0Aapplication = WsgiLog(application, tostream=True)%0A

Make wsgi script more adaptable re. installation paths.