diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-02-25 16:32:17 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-02-25 16:32:17 +0100 |
commit | 83a4073616f9821a8ebf1df0e18e332490503eca (patch) | |
tree | 5c045ed9923dbc05277b36686544958a2afbead8 /module/web/run_server.py | |
parent | gui fix, better click and load support (diff) | |
download | pyload-83a4073616f9821a8ebf1df0e18e332490503eca.tar.xz |
webinterface improvments + server crash fix
Diffstat (limited to 'module/web/run_server.py')
-rwxr-xr-x | module/web/run_server.py | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/module/web/run_server.py b/module/web/run_server.py index 3bb9b13f7..5ffa45781 100755 --- a/module/web/run_server.py +++ b/module/web/run_server.py @@ -1,20 +1,32 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from django.core.management.base import BaseCommand, CommandError import os import sys os.environ["DJANGO_SETTINGS_MODULE"] = 'settings' -def handle( *args ): +class Output: + def __init__(self, stream): + self.stream = stream + def write(self, data): # Do nothing + return None + #self.stream.write(data) + #self.stream.flush() + def __getattr__(self, attr): + return getattr(self.stream, attr) + +sys.stderr = Output(sys.stderr) +#sys.stdout = Output(sys.stdout) + +def handle(* args): import django from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException from django.core.handlers.wsgi import WSGIHandler - + try: if len(args) == 1: try: - addr,port = args[0].split(":") + addr, port = args[0].split(":") except: addr = "127.0.0.1" port = args[0] @@ -28,7 +40,7 @@ def handle( *args ): print addr, port admin_media_path = '' - shutdown_message = '' + shutdown_message = '' quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' from django.conf import settings @@ -41,26 +53,28 @@ def handle( *args ): translation.activate(settings.LANGUAGE_CODE) try: - handler = AdminMediaHandler(WSGIHandler(), admin_media_path) - run(addr, int(port), handler) + handler = AdminMediaHandler(WSGIHandler(), admin_media_path) + run(addr, int(port), handler) + except WSGIServerException, e: - # Use helpful error messages instead of ugly tracebacks. - ERRORS = { - 13: "You don't have permission to access that port.", - 98: "That port is already in use.", - 99: "That IP address can't be assigned-to.", - } - try: - error_text = ERRORS[e.args[0].args[0]] - except (AttributeError, KeyError): - error_text = str(e) - sys.stderr.write(("Error: %s" % error_text) + '\n') - # Need to use an OS exit because sys.exit doesn't work in a thread - os._exit(1) + # Use helpful error messages instead of ugly tracebacks. + ERRORS = { + 13: "You don't have permission to access that port.", + 98: "That port is already in use.", + 99: "That IP address can't be assigned-to.", + } + try: + error_text = ERRORS[e.args[0].args[0]] + except (AttributeError, KeyError): + error_text = str(e) + sys.stderr.write(("Error: %s" % error_text) + '\n') + # Need to use an OS exit because sys.exit doesn't work in a thread + #os._exit(1) except KeyboardInterrupt: - if shutdown_message: - print shutdown_message - sys.exit(0) + if shutdown_message: + print shutdown_message + sys.exit(0) + if __name__ == "__main__": - handle(*sys.argv[1:]) + handle(*sys.argv[1:]) |