Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.2 KiB

14 years ago
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. * Copyright © 2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. * Copyright © 2010, Harry "nodefab" Gabriel <rootdesign@gmail.com>
  6. *
  7. * Mumble-Django is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This package is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. """
  17. import webbrowser, sys, os
  18. from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
  19. from django.core.handlers.wsgi import WSGIHandler
  20. from os.path import join, dirname, abspath, exists
  21. from optparse import OptionParser
  22. MUMBLE_DJANGO_ROOT = None
  23. # Path auto-detection
  24. if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ):
  25. MUMBLE_DJANGO_ROOT = dirname(abspath(__file__))
  26. # environment variables
  27. sys.path.append( MUMBLE_DJANGO_ROOT )
  28. sys.path.append( join( MUMBLE_DJANGO_ROOT, 'pyweb' ) )
  29. if __name__ == "__main__":
  30. os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
  31. # parse argv to options
  32. OPARSER = OptionParser()
  33. OPARSER.add_option("-i", "--ip", dest="addr", default="127.0.0.1")
  34. OPARSER.add_option("-p", "--port", dest="port", type="int", default="8080")
  35. (OPTIONS, ARGS) = OPARSER.parse_args()
  36. try:
  37. HANDLER = AdminMediaHandler(WSGIHandler(), '')
  38. webbrowser.open('http://%s:%s' % (OPTIONS.addr, OPTIONS.port))
  39. run(OPTIONS.addr, OPTIONS.port, HANDLER)
  40. except WSGIServerException, e:
  41. # Use helpful error messages instead of ugly tracebacks.
  42. ERRORS = {
  43. 13: "You don't have permission to access that port.",
  44. 98: "That port is already in use.",
  45. 99: "That IP address can't be assigned-to.",
  46. }
  47. try:
  48. ERROR_TEXT = ERRORS[e.args[0].args[0]]
  49. except (AttributeError, KeyError):
  50. ERROR_TEXT = str(e)
  51. sys.stderr.write("Error: %s \n" % ERROR_TEXT)