Browse Source

management.py using mctl.py

Natenom/support-murmur-13-1446181288462
withgod 16 years ago
parent
commit
b1f5ffe10c
  1. 34
      pyweb/mumble/management.py
  2. 36
      pyweb/mumble/mctl.py
  3. 5
      pyweb/settings.py

34
pyweb/mumble/management.py

@ -16,35 +16,28 @@
import models import models
import dbus
from django.db.models import signals from django.db.models import signals
from mctl import *
def find_in_dicts( keys, conf, default, valueIfNotFound=None ): def find_in_dicts( keys, conf, default, valueIfNotFound=None ):
if not isinstance( keys, tuple ): if not isinstance( keys, tuple ):
keys = ( keys, ); keys = ( keys, );
for keyword in keys: for keyword in keys:
if keyword in conf: 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]; return conf[keyword];
for keyword in keys: for keyword in keys:
keyword = keyword.lower(); keyword = keyword.lower();
if keyword in default: 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 default[keyword];
return valueIfNotFound; return valueIfNotFound;
def find_existing_instances( **kwargs ): def find_existing_instances( **kwargs ):
bus = dbus.SystemBus();
ctl = MumbleCtlBase.newInstance();
if "verbosity" in kwargs: if "verbosity" in kwargs:
v = kwargs['verbosity']; v = kwargs['verbosity'];
@ -54,7 +47,7 @@ def find_existing_instances( **kwargs ):
if v > 1: if v > 1:
print "Starting Mumble servers and players detection now."; print "Starting Mumble servers and players detection now.";
dbusName = 'net.sourceforge.mumble.murmur';
'''
online = False; online = False;
while not online: while not online:
try: try:
@ -71,11 +64,11 @@ def find_existing_instances( **kwargs ):
online = True; online = True;
if v > 1: if v > 1:
print "Successfully connected to Murmur via DBus (%s)." % dbusName; 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: for id in servIDs:
if v > 1: if v > 1:
@ -84,7 +77,7 @@ def find_existing_instances( **kwargs ):
try: try:
instance = models.Mumble.objects.get( srvid=id ); instance = models.Mumble.objects.get( srvid=id );
except models.Mumble.DoesNotExist: except models.Mumble.DoesNotExist:
conf = murmur.getAllConf( dbus.Int32( id ) );
conf = ctl.getAllConf(id);
servername = find_in_dicts( "registername", conf, default, "noname" ); servername = find_in_dicts( "registername", conf, default, "noname" );
if not servername: if not servername:
@ -94,7 +87,7 @@ def find_existing_instances( **kwargs ):
values = { values = {
"name": servername, "name": servername,
"srvid": id, "srvid": id,
"dbus": dbusName,
"dbus": 'net.sourceforge.mumble.murmur',
"addr": find_in_dicts( ( "registerhostame", "host" ), conf, default, "0.0.0.0" ), "addr": find_in_dicts( ( "registerhostame", "host" ), conf, default, "0.0.0.0" ),
"port": find_in_dicts( "port", conf, default ), "port": find_in_dicts( "port", conf, default ),
"url": find_in_dicts( "registerurl", conf, default ), "url": find_in_dicts( "registerurl", conf, default ),
@ -127,12 +120,7 @@ def find_existing_instances( **kwargs ):
if v > 1: if v > 1:
print "Looking for registered Players on Server id %d." % id; print "Looking for registered Players on Server id %d." % id;
if id in bootedIDs: 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: for playerdata in players:
if playerdata[0] == 0: if playerdata[0] == 0:

36
pyweb/mumble/mctl.py

@ -12,9 +12,15 @@ import dbus
class MumbleCtlBase (): class MumbleCtlBase ():
''' abstract Ctrol Object ''' ''' abstract Ctrol Object '''
def getAllConf(self, srvid):
pass
def setConf(self, srvid, key, value): def setConf(self, srvid, key, value):
pass pass
def getDefaultConf(self):
pass
def getValue(self, srvid, key): def getValue(self, srvid, key):
pass pass
@ -42,6 +48,9 @@ class MumbleCtlBase ():
def getPlayers(self, srvid): def getPlayers(self, srvid):
pass pass
def getRegisteredPlayers(self, srvid):
pass
def getChannels(self, srvid): def getChannels(self, srvid):
pass pass
@ -57,6 +66,9 @@ class MumbleCtlBase ():
def getBootedServers(self): def getBootedServers(self):
pass pass
def getAllServers(self):
pass
def getACL(self, srvid, identifier): def getACL(self, srvid, identifier):
pass pass
@ -91,9 +103,15 @@ class MumbleCtlDbus(MumbleCtlBase):
return dbus.Interface( dbus.SystemBus().get_object( self.dbus_base, '/%d' % srvid ), 'net.sourceforge.mumble.Murmur' ); 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): def setConf(self, srvid, key, value):
self.meta.setConf(dbus.Int32( srvid ), key, value) self.meta.setConf(dbus.Int32( srvid ), key, value)
def getDefaultConf(self):
return MumbleCtlDbus.converDbusTypeToNative(self.meta.getDefaultConf())
def deleteServer( self, srvid ): def deleteServer( self, srvid ):
srvid = dbus.Int32( srvid ) srvid = dbus.Int32( srvid )
if self.meta.isBooted( srvid ): if self.meta.isBooted( srvid ):
@ -116,6 +134,9 @@ class MumbleCtlDbus(MumbleCtlBase):
def getPlayers(self, srvid): def getPlayers(self, srvid):
return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getPlayers()) return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getPlayers())
def getRegisteredPlayers(self, srvid):
return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getRegisteredPlayers(''))
def getACL(self, srvid, identifier): def getACL(self, srvid, identifier):
return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getACL(identifier)) return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getACL(identifier))
@ -125,6 +146,9 @@ class MumbleCtlDbus(MumbleCtlBase):
def getBootedServers(self): def getBootedServers(self):
return MumbleCtlDbus.converDbusTypeToNative(self.meta.getBootedServers()) return MumbleCtlDbus.converDbusTypeToNative(self.meta.getBootedServers())
def getAllServers(self):
return MumbleCtlDbus.converDbusTypeToNative(self.meta.getAllServers())
def setSuperUserPassword(self, srvid, value): def setSuperUserPassword(self, srvid, value):
self.meta.setSuperUserPassword(dbus.Int32(srvid), value) self.meta.setSuperUserPassword(dbus.Int32(srvid), value)
@ -141,11 +165,15 @@ class MumbleCtlDbus(MumbleCtlBase):
ret = [] ret = []
for x in data: for x in data:
ret.append(MumbleCtlDbus.converDbusTypeToNative(x)) 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: else:
if data.__class__ is dbus.Boolean: if data.__class__ is dbus.Boolean:
ret = bool(data) ret = bool(data)
elif data.__class__ is dbus.String: elif data.__class__ is dbus.String:
ret = str(data)
ret = unicode(data)
elif data.__class__ is dbus.Int32 or data.__class__ is dbus.UInt32: elif data.__class__ is dbus.Int32 or data.__class__ is dbus.UInt32:
ret = int(data) ret = int(data)
return ret return ret
@ -163,6 +191,12 @@ if __name__ == "__main__":
print ctl.getPlayers(1) print ctl.getPlayers(1)
print "getACL", ctl.getACL(1, 0) print "getACL", ctl.getACL(1, 0)
print ctl.getACL(1, 0)[0].__class__ is dbus.Array 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" print "--- test end"

5
pyweb/settings.py

@ -56,6 +56,11 @@ if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ):
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
DAOTYPE='dbus'
ICE_SLICE='/usr/share/slice/Murmur.ice'
ICE_PROXY='Meta:tcp -h 127.0.0.1 -p 6502'
ADMINS = ( ADMINS = (
# ('Your Name', 'your_email@domain.com'), # ('Your Name', 'your_email@domain.com'),
) )

Loading…
Cancel
Save