src/hdalab/modwsgi.wsgi
author ymh <ymh.work@gmail.com>
Tue, 07 Jul 2015 15:59:31 +0200
changeset 640 939461cc322b
parent 279 177b508612f4
permissions -rw-r--r--
improve filter display + default sort order for managing renkans
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
279
177b508612f4 add, configure and correct hdalab to installed apps
cavaliet
parents: 266
diff changeset
     1
import os, sys, site
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
def application(environ, start_response):
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    global g_env_set
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
    
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    if 'g_env_set' not in globals() or not g_env_set:
279
177b508612f4 add, configure and correct hdalab to installed apps
cavaliet
parents: 266
diff changeset
     8
        os.environ.setdefault('DJANGO_SETTINGS_MODULE',environ['DJANGO_SETTINGS_MODULE'])
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
        prev_sys_path = list(sys.path)
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        sys.path.append(environ['PROJECT_PATH'])
279
177b508612f4 add, configure and correct hdalab to installed apps
cavaliet
parents: 266
diff changeset
    13
        for path in environ.get('PYTHON_PATH',"").split(os.pathsep):
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
            if path:
279
177b508612f4 add, configure and correct hdalab to installed apps
cavaliet
parents: 266
diff changeset
    15
                site.addsitedir(path)
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        new_sys_path = [] 
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        for item in list(sys.path): 
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
            if item not in prev_sys_path and item not in new_sys_path: 
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
                new_sys_path.append(item) 
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
                sys.path.remove(item)
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        sys.path[:0] = new_sys_path
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
        g_env_set = True 
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    import django.core.handlers.wsgi
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    _application = django.core.handlers.wsgi.WSGIHandler()
279
177b508612f4 add, configure and correct hdalab to installed apps
cavaliet
parents: 266
diff changeset
    28
    
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    if environ.get('PYDEV_DEBUG', "False").lower() in ["true", "1", "t"]:
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
        import pydevd #@UnresolvedImport
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        pydevd.settrace(suspend=False)
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    return _application(environ, start_response)
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34