From 8a0f0f6957a6e5b96ad8c10d8051ba791d084a27 Mon Sep 17 00:00:00 2001 From: Harry Gabriel Date: Fri, 12 Nov 2010 22:34:15 +0100 Subject: [PATCH] Run the embedded Django server and point the web browser to it. (for Desktop usage) --- mdd.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 mdd.py diff --git a/mdd.py b/mdd.py new file mode 100644 index 0000000..017735c --- /dev/null +++ b/mdd.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Run the embedded Django server and point the web browser to it. """ + +import webbrowser, sys, os +from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException +from django.core.handlers.wsgi import WSGIHandler +from os.path import join, dirname, abspath, exists + +MUMBLE_DJANGO_ROOT = None + +# Path auto-detection +if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): + MUMBLE_DJANGO_ROOT = dirname(abspath(__file__)) + +# environment variables +sys.path.append( MUMBLE_DJANGO_ROOT ) +sys.path.append( join( MUMBLE_DJANGO_ROOT, 'pyweb' ) ) + +if __name__ == "__main__": + os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' + PORT = 8000 + + try: + HANDLER = AdminMediaHandler(WSGIHandler(), '') + + webbrowser.open('http://localhost:%s' % PORT) + run('0.0.0.0', 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 \n" % ERROR_TEXT) \ No newline at end of file