src/hdabo/modwsgi.wsgi
author cavaliet
Wed, 24 Sep 2014 13:07:08 +0200
changeset 336 aec074085a81
parent 266 825ff4d6a8ac
permissions -rw-r--r--
link to change renkan shape to circle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 83
diff changeset
     1
import os, sys, site
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
     2
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
def application(environ, start_response):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    global g_env_set
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    if 'g_env_set' not in globals() or not g_env_set:
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 83
diff changeset
     8
        os.environ.setdefault('DJANGO_SETTINGS_MODULE',environ['DJANGO_SETTINGS_MODULE'])
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
        prev_sys_path = list(sys.path)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        sys.path.append(environ['PROJECT_PATH'])
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 83
diff changeset
    13
        for path in environ.get('PYTHON_PATH',"").split(os.pathsep):
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
            if path:
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 83
diff changeset
    15
                site.addsitedir(path)
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        new_sys_path = [] 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        for item in list(sys.path): 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
            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
    20
                new_sys_path.append(item) 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
                sys.path.remove(item)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        sys.path[:0] = new_sys_path
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
        g_env_set = True 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    import django.core.handlers.wsgi
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    _application = django.core.handlers.wsgi.WSGIHandler()
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 83
diff changeset
    28
    
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
    29
    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
    30
        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
    31
        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
    32
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    return _application(environ, start_response)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34