Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Created April 26, 2012 13:49
Show Gist options
  • Save lost-theory/2499745 to your computer and use it in GitHub Desktop.
Save lost-theory/2499745 to your computer and use it in GitHub Desktop.
passenger WSGI stuff
import sys, os
INTERP = "/home/username/domain/env/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
def testapp(environ, start_response):
import pprint
start_response('200 OK', [('Content-type', 'text/plain')])
yield sys.version
yield pprint.pformat(environ)
###############################################################################
sys.path.append("/home/username/domain/env/app/")
from app import app
###############################################################################
#application = testapp
application = app
"""
Fakes a request to the WSGI app that passenger is using.
Passenger always gives an ugly 500 page with no debugging info,
and no info in the logs, so this is kinda the only way to debug.
"""
import os
from cStringIO import StringIO
from passenger_wsgi import application
DOC_ROOT = '/home/user/domain/public'
HOSTNAME = 'www.domain.com'
def start_response(*args, **kwargs):
print args, kwargs
def go(url='/', method='GET'):
io = StringIO()
environ = {
'SCRIPT_NAME': '',
'SERVER_PROTOCOL': 'HTTP/1.1',
'HTTP_USER_AGENT': 'Mozilla/5.0 Gecko/20100101 Firefox/4.0',
'HTTP_CONNECTION': 'keep-alive',
'REMOTE_ADDR': '127.0.0.1',
'wsgi.url_scheme': 'http',
'SERVER_PORT': '80',
'SERVER_ADDR': '127.0.0.1',
'wsgi.multiprocess': False,
'DOCUMENT_ROOT': DOC_ROOT,
'SERVER_NAME': HOSTNAME,
'HTTP_HOST': HOSTNAME,
'wsgi.multithread': False,
'wsgi.run_once': True,
'wsgi.input': io,
'SCRIPT_URI': 'http://%s%s' % (HOSTNAME, url),
'REQUEST_URI': url,
'PATH_INFO': url,
'SCRIPT_URL': url,
'REQUEST_METHOD': method,
'QUERY_STRING': '',
}
os.environ = environ
res = application(environ, start_response)
return list(res)
if __name__ == "__main__":
import sys
arg = sys.argv.pop()
if arg.startswith('/'):
print go(arg)
else:
import code; code.interact(local=locals());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment