-
Notifications
You must be signed in to change notification settings - Fork 1
/
passenger_wsgi.py
63 lines (49 loc) · 1.85 KB
/
passenger_wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!env/bin/python
# Wrapper script to make this work in Passenger environments (e.g. Dreamhost)
import logging
import logging.handlers
import os
import subprocess
import sys
# hackish way to make Passenger urldecode the same way WSGI does
import urllib.parse
# load the app
import app
# hack to keep click happy
os.environ['LANG'] = 'C.UTF-8'
os.environ['LC_ALL'] = 'C.UTF-8'
logging.basicConfig(level=logging.INFO)
# set up logging; see
# https://docs.python.org/2/library/logging.config.html#logging-config-fileformat
# for details
if os.path.isfile('logging.conf'):
logging.config.fileConfig('logging.conf')
else:
# This needs to be compatible with both python2 and python3, so unfortunately
# we can't just use logging.basicConfig(handlers=...)
log_handler = logging.handlers.TimedRotatingFileHandler('tmp/publ.log')
log_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
))
log_handler.setLevel(logging.INFO)
logging.getLogger().addHandler(log_handler)
logger = logging.getLogger(__name__)
logger.info('My interpreter: %s' % sys.executable)
INTERP = subprocess.check_output(
['poetry', 'run', 'which', 'python3']).strip().decode('utf-8')
if sys.executable != INTERP:
logger.info('Restarting with interpreter: %s', INTERP)
[h.flush() for h in logger.handlers]
os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())
def application(environ, start_response):
"""
make Passenger interpret PATH_INFO the same way that the WSGI standard
does
"""
environ["PATH_INFO"] = urllib.parse.unquote(environ["PATH_INFO"])
return app.app(environ, start_response)
# Uncomment next two lines to enable debugging
# from werkzeug.debug import DebuggedApplication
# application = DebuggedApplication(application, evalex=True)