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.

116 lines
3.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. import os, getpass
  17. from django.db import DatabaseError
  18. from django.conf import settings
  19. from mumble.models import MumbleServer, Mumble, signals
  20. from mumble.mctl import MumbleCtlBase
  21. def find_in_dicts( keys, conf, default, valueIfNotFound=None ):
  22. if not isinstance( keys, tuple ):
  23. keys = ( keys, )
  24. for keyword in keys:
  25. if keyword in conf:
  26. return conf[keyword]
  27. for keyword in keys:
  28. keyword = keyword.lower()
  29. if keyword in default:
  30. return default[keyword]
  31. return valueIfNotFound
  32. def find_existing_instances( **kwargs ):
  33. if "verbosity" in kwargs:
  34. v = kwargs['verbosity']
  35. else:
  36. v = 1
  37. if v > 1:
  38. print "Starting Mumble servers and players detection now."
  39. triedEnviron = False
  40. online = False
  41. while not online:
  42. env_icesecret = None
  43. if not triedEnviron and 'MURMUR_CONNSTR' in os.environ:
  44. dbusName = os.environ['MURMUR_CONNSTR']
  45. if 'MURMUR_ICESECRET' in os.environ:
  46. env_icesecret = os.environ['MURMUR_ICESECRET']
  47. triedEnviron = True
  48. if v > 1:
  49. print "Trying environment setting", dbusName
  50. else:
  51. print "--- Murmur connection info ---"
  52. print " 1) DBus -- net.sourceforge.mumble.murmur (Murmur 1.1.8 or older)"
  53. print " 2) ICE -- Meta:tcp -h 127.0.0.1 -p 6502 (Recommended)"
  54. print
  55. print "Enter 1 or 2 for the defaults above, nothing to skip Server detection,"
  56. print "and if the defaults do not fit your needs, enter the correct string."
  57. print "Whether to use DBus or Ice will be detected automatically from the"
  58. print "string's format."
  59. print
  60. dbusName = raw_input( "Service string: " ).strip()
  61. if not dbusName:
  62. if v:
  63. print 'Be sure to run "python manage.py syncdb" with Murmur running before'
  64. print "trying to use this app! Otherwise, existing Murmur servers won't be"
  65. print 'configurable!'
  66. return False
  67. elif dbusName == "1":
  68. dbusName = "net.sourceforge.mumble.murmur"
  69. elif dbusName == "2":
  70. dbusName = "Meta:tcp -h 127.0.0.1 -p 6502"
  71. if env_icesecret is None:
  72. icesecret = getpass.getpass("Please enter the Ice secret (if any): ")
  73. else:
  74. icesecret = env_icesecret
  75. try:
  76. ctl = MumbleCtlBase.newInstance( dbusName, settings.SLICE, icesecret )
  77. except Exception, instance:
  78. if v:
  79. print "Unable to connect using name %s. The error was:" % dbusName
  80. print instance
  81. print
  82. else:
  83. online = True
  84. if v > 1:
  85. print "Successfully connected to Murmur via connection string %s, using %s." % ( dbusName, ctl.method )
  86. try:
  87. meta = MumbleServer.objects.get( dbus=dbusName )
  88. except MumbleServer.DoesNotExist:
  89. meta = MumbleServer( dbus=dbusName )
  90. finally:
  91. meta.secret = icesecret
  92. meta.save(run_detection=True, verbosity=v)
  93. print "Successfully finished Servers and Players detection."
  94. print "To add more servers, run this command again."
  95. return True