view gpp/apache/sg101.wsgi @ 569:3fe2eced1be7

Now developing on Ubuntu 12.04 with Python 2.7. Use symbolic links for media, so add media/banners to .hgignore. I had a syntax error in banner_tags.py that only Python 2.7 caught. For local development, read database name from SECRETS.
author Brian Neal <bgneal@gmail.com>
date Sun, 29 Apr 2012 16:00:01 -0500
parents 5794e3414596
children
line wrap: on
line source
import os
import sys
import site


OFFLINE = False

site.addsitedir('/home/var/django-sites/virtualenvs/sg101/lib/python2.5/site-packages')

sys.path.append('/home/var/django-sites/virtualenvs/sg101/sg101')
sys.path.append('/home/var/django-sites/virtualenvs/sg101/sg101/gpp')
sys.path.append('/home/var/django-sites/virtualenvs/sg101/sg101/tools')

os.environ['PYTHON_EGG_CACHE'] = '/home/var/django-sites/virtualenvs/sg101/eggs'
os.environ['CELERY_LOADER'] = 'django'


def offline_handler(environ, start_response):
    wsgi_dir = os.path.dirname(__file__)
    sys.path.append(wsgi_dir)

    offline_file = os.path.join(wsgi_dir, '..', 'templates', 'offline.html')
    if os.path.exists(offline_file):
        response_headers = [('Content-type','text/html')]
        response = open(offline_file).read()
    else:
        response_headers = [('Content-type','text/plain')]
        response = 'SG101 website maintenance in progress; please check back soon.'
 
    if environ['REQUEST_METHOD'] == 'GET':
        status = '503 Service Unavailable'
    else:
        status = '405 Method Not Allowed'
    start_response(status, response_headers)
    return [response]


if not OFFLINE:
   os.environ['DJANGO_SETTINGS_MODULE'] = 'gpp.settings.production'
   import django.core.handlers.wsgi
   application = django.core.handlers.wsgi.WSGIHandler()
else:
   application = offline_handler