SysAdmin/Pootle: wsgihandler.py

File wsgihandler.py, 1.4 KB (added by Fran Boon, 18 months ago)
Line 
1# -*- coding: utf-8 -*-
2
3import os
4import site
5import sys
6
7
8# You probably will need to change these paths to match your deployment,
9# most likely because of the Python version you are using.
10ALLDIRS = [
11 '/home/pootle/env/lib/python2.7/site-packages',
12 '/home/pootle/env/lib/python2.7/site-packages/pootle/apps',
13]
14
15# Remember original sys.path.
16prev_sys_path = list(sys.path)
17
18# Add each new site-packages directory.
19for directory in ALLDIRS:
20 site.addsitedir(directory)
21
22# Reorder sys.path so new directories at the front.
23new_sys_path = []
24
25for item in list(sys.path):
26 if item not in prev_sys_path:
27 new_sys_path.append(item)
28 sys.path.remove(item)
29
30sys.path[:0] = new_sys_path
31
32# Set the Pootle settings module as DJANGO_SETTINGS_MODULE.
33os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'
34
35
36# Set the WSGI application.
37def application(environ, start_response):
38 """Wrapper for Django's WSGIHandler().
39
40 This allows to get values specified by SetEnv in the Apache
41 configuration or interpose other changes to that environment, like
42 installing middleware.
43 """
44 try:
45 os.environ['POOTLE_SETTINGS'] = environ['POOTLE_SETTINGS']
46 except KeyError:
47 pass
48
49 from django.core.wsgi import get_wsgi_application
50 _wsgi_application = get_wsgi_application()
51 return _wsgi_application(environ, start_response)