annotate bns_website/apache/bns.wsgi @ 104:f00199f1524c

Changes for running in a virtualenv on the new server jaguar.
author Brian Neal <bgneal@gmail.com>
date Tue, 09 Apr 2013 21:29:30 -0500
parents a5e8741452a3
children
rev   line source
bgneal@19 1 import os
bgneal@104 2 import site
bgneal@19 3 import sys
bgneal@19 4
bgneal@19 5 OFFLINE = False
bgneal@19 6
bgneal@104 7 site.addsitedir('/svr/django-sites/bns/lib/python2.7/site-packages')
bgneal@104 8
bgneal@19 9 here = os.path.dirname(__file__)
bgneal@19 10 website = os.path.dirname(here)
bgneal@26 11 repo = os.path.dirname(website)
bgneal@26 12 project = os.path.dirname(repo)
bgneal@19 13 eggs = os.path.join(project, 'eggs')
bgneal@27 14 django = os.path.join(project, 'django')
bgneal@19 15
bgneal@27 16 sys.path.extend([repo, website, django])
bgneal@19 17
bgneal@19 18 os.environ['PYTHON_EGG_CACHE'] = eggs
bgneal@19 19
bgneal@19 20
bgneal@19 21 def offline_handler(environ, start_response):
bgneal@19 22 """
bgneal@19 23 This handler is run when the site is in maintenance mode.
bgneal@19 24 It either displays a brief outage message, or, if a template
bgneal@19 25 file exists, it reads the file and returns its contents.
bgneal@19 26
bgneal@19 27 """
bgneal@19 28 wsgi_dir = os.path.dirname(__file__)
bgneal@19 29 sys.path.append(wsgi_dir)
bgneal@19 30
bgneal@19 31 offline_file = os.path.abspath(
bgneal@19 32 os.path.join(wsgi_dir, '..', 'templates', 'offline.html'))
bgneal@19 33 if os.path.exists(offline_file):
bgneal@19 34 response_headers = [('Content-type','text/html')]
bgneal@19 35 response = open(offline_file).read()
bgneal@19 36 else:
bgneal@19 37 response_headers = [('Content-type','text/plain')]
bgneal@19 38 response = ('Brave New Surf website maintenance in progress; '
bgneal@19 39 'please check back soon.')
bgneal@19 40
bgneal@19 41 if environ['REQUEST_METHOD'] == 'GET':
bgneal@19 42 status = '503 Service Unavailable'
bgneal@19 43 else:
bgneal@19 44 status = '405 Method Not Allowed'
bgneal@19 45 start_response(status, response_headers)
bgneal@19 46 return [response]
bgneal@19 47
bgneal@19 48
bgneal@19 49 if not OFFLINE:
bgneal@19 50 os.environ['DJANGO_SETTINGS_MODULE'] = 'bns_website.settings.production'
bgneal@19 51 import django.core.handlers.wsgi
bgneal@19 52 application = django.core.handlers.wsgi.WSGIHandler()
bgneal@19 53 else:
bgneal@19 54 application = offline_handler