diff --git a/pyweb/mumble/management.py b/pyweb/mumble/management.py old mode 100644 new mode 100755 index 8e75e36..08829b5 --- a/pyweb/mumble/management.py +++ b/pyweb/mumble/management.py @@ -16,36 +16,29 @@ import models -import dbus from django.db.models import signals +from mctl import * + def find_in_dicts( keys, conf, default, valueIfNotFound=None ): if not isinstance( keys, tuple ): keys = ( keys, ); - + for keyword in keys: if keyword in conf: - if isinstance( conf[keyword], dbus.String ): - return unicode(conf[keyword]); - elif isinstance( conf[keyword], dbus.Int32 ): - return int(conf[keyword]); return conf[keyword]; - + for keyword in keys: keyword = keyword.lower(); if keyword in default: - if isinstance( default[keyword], dbus.String ): - return unicode(default[keyword]); - elif isinstance( default[keyword], dbus.Int32 ): - return int(default[keyword]); return default[keyword]; - + return valueIfNotFound; def find_existing_instances( **kwargs ): - bus = dbus.SystemBus(); - + ctl = MumbleCtlBase.newInstance(); + if "verbosity" in kwargs: v = kwargs['verbosity']; else: @@ -54,7 +47,7 @@ def find_existing_instances( **kwargs ): if v > 1: print "Starting Mumble servers and players detection now."; - dbusName = 'net.sourceforge.mumble.murmur'; + ''' online = False; while not online: try: @@ -71,11 +64,11 @@ def find_existing_instances( **kwargs ): online = True; if v > 1: print "Successfully connected to Murmur via DBus (%s)." % dbusName; + ''' + default = ctl.getDefaultConf(); - default = murmur.getDefaultConf(); - - servIDs = murmur.getAllServers(); - bootedIDs = murmur.getBootedServers(); + servIDs = ctl.getAllServers(); + bootedIDs = ctl.getBootedServers(); for id in servIDs: if v > 1: @@ -84,7 +77,7 @@ def find_existing_instances( **kwargs ): try: instance = models.Mumble.objects.get( srvid=id ); except models.Mumble.DoesNotExist: - conf = murmur.getAllConf( dbus.Int32( id ) ); + conf = ctl.getAllConf(id); servername = find_in_dicts( "registername", conf, default, "noname" ); if not servername: @@ -94,7 +87,7 @@ def find_existing_instances( **kwargs ): values = { "name": servername, "srvid": id, - "dbus": dbusName, + "dbus": 'net.sourceforge.mumble.murmur', "addr": find_in_dicts( ( "registerhostame", "host" ), conf, default, "0.0.0.0" ), "port": find_in_dicts( "port", conf, default ), "url": find_in_dicts( "registerurl", conf, default ), @@ -127,12 +120,7 @@ def find_existing_instances( **kwargs ): if v > 1: print "Looking for registered Players on Server id %d." % id; if id in bootedIDs: - murmurinstance = dbus.Interface( - bus.get_object( 'net.sourceforge.mumble.murmur', '/%d'%id ), - 'net.sourceforge.mumble.Murmur' - ); - - players = murmurinstance.getRegisteredPlayers(''); + players = ctl.getRegisteredPlayers(id); for playerdata in players: if playerdata[0] == 0: diff --git a/pyweb/mumble/mctl.py b/pyweb/mumble/mctl.py index f0e5705..29b65ec 100755 --- a/pyweb/mumble/mctl.py +++ b/pyweb/mumble/mctl.py @@ -12,9 +12,15 @@ import dbus class MumbleCtlBase (): ''' abstract Ctrol Object ''' + def getAllConf(self, srvid): + pass + def setConf(self, srvid, key, value): pass + def getDefaultConf(self): + pass + def getValue(self, srvid, key): pass @@ -42,6 +48,9 @@ class MumbleCtlBase (): def getPlayers(self, srvid): pass + def getRegisteredPlayers(self, srvid): + pass + def getChannels(self, srvid): pass @@ -57,6 +66,9 @@ class MumbleCtlBase (): def getBootedServers(self): pass + def getAllServers(self): + pass + def getACL(self, srvid, identifier): pass @@ -91,9 +103,15 @@ class MumbleCtlDbus(MumbleCtlBase): return dbus.Interface( dbus.SystemBus().get_object( self.dbus_base, '/%d' % srvid ), 'net.sourceforge.mumble.Murmur' ); + def getAllConf(self, srvid): + return MumbleCtlDbus.converDbusTypeToNative(self.meta.getAllConf(dbus.Int32(srvid))) + def setConf(self, srvid, key, value): self.meta.setConf(dbus.Int32( srvid ), key, value) + def getDefaultConf(self): + return MumbleCtlDbus.converDbusTypeToNative(self.meta.getDefaultConf()) + def deleteServer( self, srvid ): srvid = dbus.Int32( srvid ) if self.meta.isBooted( srvid ): @@ -116,6 +134,9 @@ class MumbleCtlDbus(MumbleCtlBase): def getPlayers(self, srvid): return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getPlayers()) + def getRegisteredPlayers(self, srvid): + return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getRegisteredPlayers('')) + def getACL(self, srvid, identifier): return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getACL(identifier)) @@ -125,6 +146,9 @@ class MumbleCtlDbus(MumbleCtlBase): def getBootedServers(self): return MumbleCtlDbus.converDbusTypeToNative(self.meta.getBootedServers()) + def getAllServers(self): + return MumbleCtlDbus.converDbusTypeToNative(self.meta.getAllServers()) + def setSuperUserPassword(self, srvid, value): self.meta.setSuperUserPassword(dbus.Int32(srvid), value) @@ -137,15 +161,19 @@ class MumbleCtlDbus(MumbleCtlBase): #but dbus.* type is not native type. it's not good transparent for using Ice/Dbus. ret = None - if isinstance(data, tuple) or type(data) is data.__class__ is dbus.Array or data.__class__ is dbus.Struct : + if isinstance(data, tuple) or type(data) is data.__class__ is dbus.Array or data.__class__ is dbus.Struct: ret = [] for x in data: ret.append(MumbleCtlDbus.converDbusTypeToNative(x)) + elif data.__class__ is dbus.Dictionary: + ret = {} + for x in data.items(): + ret[MumbleCtlDbus.converDbusTypeToNative(x[0])] = MumbleCtlDbus.converDbusTypeToNative(x[1]) else: if data.__class__ is dbus.Boolean: ret = bool(data) elif data.__class__ is dbus.String: - ret = str(data) + ret = unicode(data) elif data.__class__ is dbus.Int32 or data.__class__ is dbus.UInt32: ret = int(data) return ret @@ -163,6 +191,12 @@ if __name__ == "__main__": print ctl.getPlayers(1) print "getACL", ctl.getACL(1, 0) print ctl.getACL(1, 0)[0].__class__ is dbus.Array + print "getAllServers()" + print ctl.getAllServers() + print "getDefaultConf()" + print ctl.getDefaultConf() + print "getAllConf(1)" + print ctl.getAllConf(1) print "--- test end" diff --git a/pyweb/settings.py b/pyweb/settings.py old mode 100644 new mode 100755 index 31425fd..04372c0 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -56,6 +56,11 @@ if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): DEBUG = True TEMPLATE_DEBUG = DEBUG +DAOTYPE='dbus' +ICE_SLICE='/usr/share/slice/Murmur.ice' +ICE_PROXY='Meta:tcp -h 127.0.0.1 -p 6502' + + ADMINS = ( # ('Your Name', 'your_email@domain.com'), )