bgneal@19: import os bgneal@104: import site bgneal@19: import sys bgneal@19: bgneal@19: OFFLINE = False bgneal@19: bgneal@104: site.addsitedir('/svr/django-sites/bns/lib/python2.7/site-packages') bgneal@104: bgneal@19: here = os.path.dirname(__file__) bgneal@19: website = os.path.dirname(here) bgneal@26: repo = os.path.dirname(website) bgneal@26: project = os.path.dirname(repo) bgneal@19: eggs = os.path.join(project, 'eggs') bgneal@27: django = os.path.join(project, 'django') bgneal@19: bgneal@27: sys.path.extend([repo, website, django]) bgneal@19: bgneal@19: os.environ['PYTHON_EGG_CACHE'] = eggs bgneal@19: bgneal@19: bgneal@19: def offline_handler(environ, start_response): bgneal@19: """ bgneal@19: This handler is run when the site is in maintenance mode. bgneal@19: It either displays a brief outage message, or, if a template bgneal@19: file exists, it reads the file and returns its contents. bgneal@19: bgneal@19: """ bgneal@19: wsgi_dir = os.path.dirname(__file__) bgneal@19: sys.path.append(wsgi_dir) bgneal@19: bgneal@19: offline_file = os.path.abspath( bgneal@19: os.path.join(wsgi_dir, '..', 'templates', 'offline.html')) bgneal@19: if os.path.exists(offline_file): bgneal@19: response_headers = [('Content-type','text/html')] bgneal@19: response = open(offline_file).read() bgneal@19: else: bgneal@19: response_headers = [('Content-type','text/plain')] bgneal@19: response = ('Brave New Surf website maintenance in progress; ' bgneal@19: 'please check back soon.') bgneal@19: bgneal@19: if environ['REQUEST_METHOD'] == 'GET': bgneal@19: status = '503 Service Unavailable' bgneal@19: else: bgneal@19: status = '405 Method Not Allowed' bgneal@19: start_response(status, response_headers) bgneal@19: return [response] bgneal@19: bgneal@19: bgneal@19: if not OFFLINE: bgneal@19: os.environ['DJANGO_SETTINGS_MODULE'] = 'bns_website.settings.production' bgneal@19: import django.core.handlers.wsgi bgneal@19: application = django.core.handlers.wsgi.WSGIHandler() bgneal@19: else: bgneal@19: application = offline_handler