|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2008 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 __authors__ = [ |
|
18 # alphabetical order by last name, please |
|
19 '"Augie Fackler" <durin42@gmail.com>', |
|
20 ] |
|
21 |
|
22 |
|
23 import logging |
|
24 import os |
|
25 import sys |
|
26 |
|
27 from google.appengine.ext.webapp import util |
|
28 |
|
29 |
|
30 # Remove the standard version of Django. |
|
31 for k in [k for k in sys.modules if k.startswith('django')]: |
|
32 del sys.modules[k] |
|
33 |
|
34 # Force sys.path to have our own directory first, in case we want to import |
|
35 # from it. This lets us replace the built-in Django |
|
36 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
|
37 |
|
38 # Force Django to reload its settings. |
|
39 from django.conf import settings |
|
40 settings._target = None |
|
41 |
|
42 # Must set this env var before importing any part of Django |
|
43 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
|
44 |
|
45 import django.core.handlers.wsgi |
|
46 import django.core.signals |
|
47 import django.db |
|
48 import django.dispatch.dispatcher |
|
49 |
|
50 |
|
51 # Log errors. |
|
52 def log_exception(*args, **kwds): |
|
53 logging.exception('Exception in request:') |
|
54 |
|
55 django.dispatch.dispatcher.connect( |
|
56 log_exception, django.core.signals.got_request_exception) |
|
57 |
|
58 # Unregister the rollback event handler. |
|
59 django.dispatch.dispatcher.disconnect( |
|
60 django.db._rollback_on_exception, |
|
61 django.core.signals.got_request_exception) |
|
62 |
|
63 |
|
64 def main(): |
|
65 # Create a Django application for WSGI. |
|
66 application = django.core.handlers.wsgi.WSGIHandler() |
|
67 |
|
68 # Run the WSGI CGI handler with that application. |
|
69 util.run_wsgi_app(application) |
|
70 |
|
71 |
|
72 if __name__ == '__main__': |
|
73 main() |