-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbootstrap.py
More file actions
64 lines (51 loc) · 2.11 KB
/
bootstrap.py
File metadata and controls
64 lines (51 loc) · 2.11 KB
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
64
# Standard Python Imports
import os
import sys
import logging
# Log a message each time this module get loaded.
logging.info('Loading %s, app version = %s', __name__, os.getenv('CURRENT_VERSION_ID'))
# Declare the Django version we need.
from google.appengine.dist import use_library
use_library('django', '1.1')
# Fail early if we can't import Django 1.x. Log identifying information.
import django
logging.info('django.__file__ = %r, django.VERSION = %r', django.__file__, django.VERSION)
assert django.VERSION[0] >= 1, "This Django version is too old"
# Custom Django configuration.
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.conf import settings
settings._target = None
# AppEngine imports.
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template as template_registrar
# Helper to enter the debugger. This passes in __stdin__ and
# __stdout__, because stdin and stdout are connected to the request
# and response streams. You must import this from __main__ to use it.
# (I tried to make it universally available via __builtin__, but that
# doesn't seem to work for some reason.)
def BREAKPOINT():
import pdb
p = pdb.Pdb(None, sys.__stdin__, sys.__stdout__)
p.set_trace()
# Import various parts of Django.
import django.core.handlers.wsgi
import django.core.signals
import django.db
import django.dispatch.dispatcher
import django.forms
# Work-around to avoid warning about django.newforms in djangoforms.
django.newforms = django.forms
# Django signal handler to log an exception
def log_exception(*args, **kwds):
cls, err = sys.exc_info()[:2]
logging.exception('Exception in request: %s: %s', cls.__name__, err)
# Log all exceptions detected by Django.
django.core.signals.got_request_exception.connect(log_exception)
# Unregister Django's default rollback event handler.
django.core.signals.got_request_exception.disconnect(django.db._rollback_on_exception)
def main():
application = django.core.handlers.wsgi.WSGIHandler()
template_registrar.register_template_library('opentransit.tags')
util.run_wsgi_app(application)
if __name__ == "__main__":
main()