web/hdabo/modwsgi.wsgi
author ymh <ymh.work@gmail.com>
Mon, 22 Oct 2012 17:29:44 +0200
changeset 258 0368e86e4cbd
parent 83 1c4729b3dac1
permissions -rw-r--r--
upgrade Django
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
62df01506d36 reformat code
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
import os
62df01506d36 reformat code
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     2
import sys
62df01506d36 reformat code
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     3
import site
62df01506d36 reformat code
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     4
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
83
1c4729b3dac1 Correction bug #20. The solution is mainly to make sure that the index is recalculated
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
     6
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
def application(environ, start_response):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    global g_env_set
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    if 'g_env_set' not in globals() or not g_env_set:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        os.environ['DJANGO_SETTINGS_MODULE'] = environ['DJANGO_SETTINGS_MODULE']
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
        prev_sys_path = list(sys.path)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        sys.path.append(environ['PROJECT_PATH'])
22
62df01506d36 reformat code
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
        for path in environ.get('PYTHON_PATH', "").split(os.pathsep):
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
            if path:
23
7aad42e75285 reformat code
ymh <ymh.work@gmail.com>
parents: 22
diff changeset
    19
                site.addsitedir(path) #@UndefinedVariable
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        new_sys_path = [] 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        for item in list(sys.path): 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
            if item not in prev_sys_path and item not in new_sys_path: 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
                new_sys_path.append(item) 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
                sys.path.remove(item)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        sys.path[:0] = new_sys_path
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        g_env_set = True 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    import django.core.handlers.wsgi
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    _application = django.core.handlers.wsgi.WSGIHandler()
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
83
1c4729b3dac1 Correction bug #20. The solution is mainly to make sure that the index is recalculated
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
    33
    if environ.get('PYDEV_DEBUG', "False").lower() in ["true", "1", "t"]:
1c4729b3dac1 Correction bug #20. The solution is mainly to make sure that the index is recalculated
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
    34
        import pydevd #@UnresolvedImport
1c4729b3dac1 Correction bug #20. The solution is mainly to make sure that the index is recalculated
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
    35
        pydevd.settrace(suspend=False)
1c4729b3dac1 Correction bug #20. The solution is mainly to make sure that the index is recalculated
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
    36
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    return _application(environ, start_response)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38