Browse Source

the syncdb hook now takes verbosity into account

Natenom/support-murmur-13-1446181288462
work 16 years ago
parent
commit
f20c7d19e3
  1. 43
      pyweb/mumble/management.py
  2. 2
      pyweb/mumble/models.py

43
pyweb/mumble/management.py

@ -54,19 +54,31 @@ def find_in_dicts( keys, conf, default, valueIfNotFound=None ):
def find_existing_instances( **kwargs ): def find_existing_instances( **kwargs ):
bus = dbus.SystemBus(); bus = dbus.SystemBus();
if "verbosity" in kwargs:
v = kwargs['verbosity'];
else:
v = 1;
if v > 1:
print "Starting Mumble servers and players detection now.";
dbusName = 'net.sourceforge.mumble.murmur'; dbusName = 'net.sourceforge.mumble.murmur';
online = False; online = False;
while not online: while not online:
try: try:
murmur = dbus.Interface( bus.get_object( dbusName, '/' ), 'net.sourceforge.mumble.Meta');
murmur = dbus.Interface( bus.get_object( dbusName, '/' ), 'net.sourceforge.mumble.Meta' );
except dbus.exceptions.DBusException: except dbus.exceptions.DBusException:
print "Unable to connect to DBus using name %s. Is Murmur even running!?" % dbusName;
if v:
print "Unable to connect to DBus using name %s. Is Murmur even running!?" % dbusName;
dbusName = raw_input( "DBus Service name (or empty to skip Servers/Players detection): " ); dbusName = raw_input( "DBus Service name (or empty to skip Servers/Players detection): " );
if not dbusName: if not dbusName:
print 'Be sure to run "python manage.py syncdb" with Murmur running before trying to use this app! Otherwise, existing Murmur servers won\'t be configurable!';
if v:
print 'Be sure to run "python manage.py syncdb" with Murmur running before trying to use this app! Otherwise, existing Murmur servers won\'t be configurable!';
return False; return False;
else: else:
online = True; online = True;
if v > 1:
print "Successfully connected to Murmur via DBus (%s)." % dbusName;
default = murmur.getDefaultConf(); default = murmur.getDefaultConf();
@ -74,14 +86,13 @@ def find_existing_instances( **kwargs ):
bootedIDs = murmur.getBootedServers(); bootedIDs = murmur.getBootedServers();
for id in servIDs: for id in servIDs:
if v > 1:
print "Checking Murmur instance with id %d." % id;
# first check that the server has not yet been inserted into the DB # first check that the server has not yet been inserted into the DB
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 ) );
# We need at least:
# name srvid addr
conf = murmur.getAllConf( dbus.Int32( id ) );
values = { values = {
"name": find_in_dicts( "registerName", conf, default, "noname" ), "name": find_in_dicts( "registerName", conf, default, "noname" ),
"srvid": id, "srvid": id,
@ -104,13 +115,19 @@ def find_existing_instances( **kwargs ):
# the port field, so we can simply drop it. # the port field, so we can simply drop it.
values['addr'] = values['addr'].split(':')[0]; values['addr'] = values['addr'].split(':')[0];
print 'Found Murmur "%s" running on %s:%s.' % ( values['name'], values['addr'], values['port'] );
if v:
print 'Found new Murmur "%s" running on %s:%s.' % ( values['name'], values['addr'], values['port'] );
# now create a model for the record set. # now create a model for the record set.
instance = models.Mumble( **values ); instance = models.Mumble( **values );
instance.save( dontConfigureMurmur=True ); instance.save( dontConfigureMurmur=True );
else:
if v > 1:
print "This instance is already listed in the database.";
# Now search for players on this server that have not yet been registered # Now search for players on this server that have not yet been registered
if v > 1:
print "Looking for registered Players on Server id %d." % id;
if id in bootedIDs: if id in bootedIDs:
murmurinstance = dbus.Interface( murmurinstance = dbus.Interface(
bus.get_object( 'net.sourceforge.mumble.murmur', '/%d'%id ), bus.get_object( 'net.sourceforge.mumble.murmur', '/%d'%id ),
@ -122,10 +139,13 @@ def find_existing_instances( **kwargs ):
for playerdata in players: for playerdata in players:
if playerdata[0] == 0: if playerdata[0] == 0:
continue; continue;
if v > 1:
print "Checking Player with id %d and name '%s'." % playerdata[:2];
try: try:
models.MumbleUser.objects.get( mumbleid=playerdata[0] ); models.MumbleUser.objects.get( mumbleid=playerdata[0] );
except models.MumbleUser.DoesNotExist: except models.MumbleUser.DoesNotExist:
print 'Found Player "%s"' % playerdata[1];
if v:
print 'Found new Player "%s".' % playerdata[1];
playerinstance = models.MumbleUser( playerinstance = models.MumbleUser(
mumbleid = playerdata[0], mumbleid = playerdata[0],
name = playerdata[1], name = playerdata[1],
@ -134,7 +154,12 @@ def find_existing_instances( **kwargs ):
owner = None owner = None
); );
playerinstance.save( dontConfigureMurmur=True ); playerinstance.save( dontConfigureMurmur=True );
else:
if v > 1:
print "This player is already listed in the database.";
if v > 1:
print "Successfully finished Servers and Players detection.";
return True; return True;

2
pyweb/mumble/models.py

@ -120,7 +120,7 @@ class Mumble( models.Model ):
murmur.setSuperUserPassword( srvid, self.supw ); murmur.setSuperUserPassword( srvid, self.supw );
self.supw = ''; self.supw = '';
if self.booted != murmur.isBooted( dbus.Int32(self.srvid) ):
if self.booted != murmur.isBooted( srvid ):
if self.booted: if self.booted:
murmur.start( srvid ); murmur.start( srvid );
else: else:

Loading…
Cancel
Save