src/ldt/ldt/core/handlers/modwsgi.py
author ymh <ymh.work@gmail.com>
Fri, 06 May 2011 01:01:51 +0200
changeset 95 8e57d39f660d
parent 63 93325a5d61f0
child 111 4535dafa6007
permissions -rw-r--r--
correct indexation problem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
93325a5d61f0 organize format and import
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     1
import os
93325a5d61f0 organize format and import
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     2
import sys
93325a5d61f0 organize format and import
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     3
import site
0
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
def application(environ, start_response):
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
    os.environ['DJANGO_SETTINGS_MODULE'] = environ['DJANGO_SETTINGS_MODULE']
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    prev_sys_path = list(sys.path)
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    sys.path.append(environ['PROJECT_PATH'])
13
97ab7b3191cf add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents: 1
diff changeset
    11
    for path in environ.get('PYTHON_PATH', "").split(os.pathsep):
1
6a2a816d4ba3 correct virtual env res + htaccess + mod wsgi
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
        if path:
6a2a816d4ba3 correct virtual env res + htaccess + mod wsgi
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
            site.addsitedir(path)
0
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    new_sys_path = [] 
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    for item in list(sys.path): 
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        if item not in prev_sys_path: 
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
            new_sys_path.append(item) 
1
6a2a816d4ba3 correct virtual env res + htaccess + mod wsgi
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
            sys.path.remove(item)
0
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    sys.path[:0] = new_sys_path 
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    import django.core.handlers.wsgi
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    _application = django.core.handlers.wsgi.WSGIHandler()
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
13
97ab7b3191cf add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents: 1
diff changeset
    26
    return _application(environ, start_response)