annotate gpp/apache/sg101.wsgi @ 47:6dfcbbf11243

Added a .wsgi file and an offline.html file.
author Brian Neal <bgneal@gmail.com>
date Sun, 21 Jun 2009 21:26:49 +0000
parents
children 31cb8d55e3a1
rev   line source
bgneal@47 1 import os
bgneal@47 2 import sys
bgneal@47 3
bgneal@47 4 OFFLINE = True
bgneal@47 5
bgneal@47 6 sys.path.append('/home/var/django-sites/sg101/django')
bgneal@47 7 sys.path.append('/home/var/django-sites/sg101/3rdparty')
bgneal@47 8 sys.path.append('/home/var/django-sites/sg101/sg101-trunk')
bgneal@47 9 sys.path.append('/home/var/django-sites/sg101/sg101-trunk/gpp')
bgneal@47 10
bgneal@47 11 os.environ['PYTHON_EGG_CACHE'] = '/home/var/django-sites/sg101/eggs/'
bgneal@47 12
bgneal@47 13
bgneal@47 14 def offline_handler(environ, start_response):
bgneal@47 15 wsgi_dir = os.path.dirname(__file__)
bgneal@47 16 sys.path.append(project_dir)
bgneal@47 17
bgneal@47 18 offline_file = os.path.join(wsgi_dir, '..', 'templates', 'offline.html')
bgneal@47 19 if os.path.exists(offline_file):
bgneal@47 20 response_headers = [('Content-type','text/html')]
bgneal@47 21 response = open(offline_file).read()
bgneal@47 22 else:
bgneal@47 23 response_headers = [('Content-type','text/plain')]
bgneal@47 24 response = 'SG101 website maintenance in progress; please check back soon.'
bgneal@47 25
bgneal@47 26 if environ['REQUEST_METHOD'] == 'GET':
bgneal@47 27 status = '503 Service Unavailable'
bgneal@47 28 else:
bgneal@47 29 status = '405 Method Not Allowed'
bgneal@47 30 start_response(status, response_headers)
bgneal@47 31 return [response]
bgneal@47 32
bgneal@47 33
bgneal@47 34 if not OFFLINE:
bgneal@47 35 os.environ['DJANGO_SETTINGS_MODULE'] = 'gpp.settings'
bgneal@47 36 import django.core.handlers.wsgi
bgneal@47 37 application = django.core.handlers.wsgi.WSGIHandler()
bgneal@47 38 else:
bgneal@47 39 application = offline_handler
bgneal@47 40