src/spel/modwsgi.wsgi
author cavaliet
Tue, 15 Jul 2014 17:06:21 +0200
changeset 124 2dea6f70975c
parent 2 bafbf72652b9
permissions -rwxr-xr-x
v0.5.26 correct player
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     1
import os, sys, site
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     2
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     3
def application(environ, start_response):
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     4
    
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     5
    global g_env_set
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     6
    
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     7
    if 'g_env_set' not in globals() or not g_env_set:
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     8
        os.environ.setdefault('DJANGO_SETTINGS_MODULE',environ['DJANGO_SETTINGS_MODULE'])
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
     9
    
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    10
        prev_sys_path = list(sys.path)
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    11
    
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    12
        sys.path.append(environ['PROJECT_PATH'])
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    13
        for path in environ.get('PYTHON_PATH',"").split(os.pathsep):
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    14
            if path:
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    15
                site.addsitedir(path)
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    16
    
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    17
        new_sys_path = [] 
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    18
        for item in list(sys.path): 
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    19
            if item not in prev_sys_path and item not in new_sys_path: 
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    20
                new_sys_path.append(item) 
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    21
                sys.path.remove(item)
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    22
        sys.path[:0] = new_sys_path
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    23
        g_env_set = True 
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    24
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    25
    import django.core.handlers.wsgi
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    26
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    27
    _application = django.core.handlers.wsgi.WSGIHandler()
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    28
    
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    29
    if environ.get('PYDEV_DEBUG', "False").lower() in ["true", "1", "t"]:
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    30
        import pydevd #@UnresolvedImport
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    31
        pydevd.settrace(suspend=False)
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    32
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    33
    return _application(environ, start_response)
bafbf72652b9 virtualenv first commit and structure for spel app
cavaliet
parents:
diff changeset
    34