diff options
Diffstat (limited to 'eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py')
-rw-r--r-- | eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py b/eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py new file mode 100644 index 0000000..9e9d054 --- /dev/null +++ b/eggs/djangorecipe-0.20-py2.6.egg/djangorecipe/wsgi.py @@ -0,0 +1,45 @@ +import sys + +from django.core import management + +def main(settings_file, logfile=None): + try: + mod = __import__(settings_file) + components = settings_file.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + + except ImportError, e: + sys.stderr.write("Error loading the settings module '%s': %s" + % (settings_file, e)) + sys.exit(1) + + # Setup settings + management.setup_environ(mod) + + if logfile: + import datetime + class logger(object): + def __init__(self, logfile): + self.logfile = logfile + + def write(self, data): + self.log(data) + + def writeline(self, data): + self.log(data) + + def log(self, msg): + line = '%s - %s\n' % ( + datetime.datetime.now().strftime('%Y%m%d %H:%M:%S'), msg) + fp = open(self.logfile, 'a') + try: + fp.write(line) + finally: + fp.close() + sys.stdout = sys.stderr = logger(logfile) + + from django.core.handlers.wsgi import WSGIHandler + + # Run WSGI handler for the application + return WSGIHandler() |