Browse Source

move the server detection code to MumbleServer.save(). see #166

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
5fdcc0b541
  1. 76
      pyweb/mumble/management/server_detect.py
  2. 80
      pyweb/mumble/models.py

76
pyweb/mumble/management/server_detect.py

@ -101,87 +101,13 @@ def find_existing_instances( **kwargs ):
if v > 1:
print "Successfully connected to Murmur via connection string %s, using %s." % ( dbusName, ctl.method )
servIDs = ctl.getAllServers()
unseen_ids = [rec["srvid"] for rec in Mumble.objects.values( "srvid" )]
try:
meta = MumbleServer.objects.get( dbus=dbusName )
except MumbleServer.DoesNotExist:
meta = MumbleServer( dbus=dbusName )
finally:
meta.secret = icesecret
meta.save()
for id in servIDs:
if id in unseen_ids:
unseen_ids.remove(id)
if v > 1:
print "Checking Murmur instance with id %d." % id
# first check that the server has not yet been inserted into the DB
try:
instance = Mumble.objects.get( server=meta, srvid=id )
except Mumble.DoesNotExist:
values = {
"server": meta,
"srvid": id,
}
if v:
print "Found new Murmur instance %d on bus '%s'... " % ( id, dbusName )
# now create a model for the record set.
instance = Mumble( **values )
else:
if v:
print "Syncing Murmur instance %d: '%s'... " % ( instance.id, instance.name )
try:
instance.configureFromMurmur()
except DatabaseError, err:
try:
# Find instances with the same address/port
dup = Mumble.objects.get( addr=instance.addr, port=instance.port )
except Mumble.DoesNotExist:
# None exist - this must've been something else.
print "Server ID / Name: %d / %s" % ( instance.srvid, instance.name )
raise err
else:
print "ERROR: There is already another server instance registered"
print " on the same address and port."
print " -------------"
print " New Server ID:", instance.srvid,
print " New Server Name:", instance.name
print " Address:", instance.addr
print " Port:", instance.port
print " Connection string:", instance.server.dbus
print " -------------"
print " Duplicate Server ID:", dup.srvid,
print "Duplicate Server Name:", dup.name
print " Address:", dup.addr
print " Port:", dup.port
print " Connection string:", dup.server.dbus
return False
except Exception, err:
print "Server ID / Name: %d / %s" % ( instance.srvid, instance.name )
raise err
# Now search for players on this server that have not yet been registered
if instance.booted:
if v > 1:
print "Looking for registered Players on Server id %d." % id
instance.readUsersFromMurmur( verbose=v )
elif v:
print "This server is not running, can't sync players."
signals.pre_delete.disconnect( Mumble.pre_delete_listener, sender=Mumble )
for srvid in unseen_ids:
mm = Mumble.objects.get( srvid=srvid )
if v:
print 'Found stale Mumble instance "%s".' % mm.name
mm.delete()
signals.pre_delete.connect( Mumble.pre_delete_listener, sender=Mumble )
meta.save(run_detection=True, verbosity=v)
print "Successfully finished Servers and Players detection."
print "To add more servers, run this command again."

80
pyweb/mumble/models.py

@ -168,6 +168,86 @@ class MumbleServer( models.Model ):
prettyversion = property( lambda self: '.'.join( map( str, self.version[:3] ) ),
doc="Pretty-Printed version" )
def save( self, run_detection=True, verbosity=0, *args, **kwargs ):
ret = models.Model.save( self, *args, **kwargs )
if not run_detection:
return ret
servIDs = self.ctl.getAllServers()
unseen_ids = [rec["srvid"] for rec in Mumble.objects.values( "srvid" )]
for id in servIDs:
if id in unseen_ids:
unseen_ids.remove(id)
if verbosity > 1:
print "Checking Murmur instance with id %d." % id
# first check that the server has not yet been inserted into the DB
try:
instance = Mumble.objects.get( server=self, srvid=id )
except Mumble.DoesNotExist:
if verbosity:
print "Found new Murmur instance %d on bus '%s'... " % ( id, dbusName )
# now create a model for the record set (configureFromMurmur will save() it).
instance = Mumble( server=self, srvid=id )
else:
if verbosity:
print "Syncing Murmur instance %d: '%s'... " % ( instance.id, instance.name )
try:
instance.configureFromMurmur()
except DatabaseError, err:
try:
# Find instances with the same address/port
dup = Mumble.objects.get( addr=instance.addr, port=instance.port )
except Mumble.DoesNotExist:
# None exist - this must've been something else.
if verbosity:
print "Server ID / Name: %d / %s" % ( instance.srvid, instance.name )
raise err
else:
if verbosity:
print "ERROR: There is already another server instance registered"
print " on the same address and port."
print " -------------"
print " New Server ID:", instance.srvid,
print " New Server Name:", instance.name
print " Address:", instance.addr
print " Port:", instance.port
print " Connection string:", instance.server.dbus
print " -------------"
print " Duplicate Server ID:", dup.srvid,
print "Duplicate Server Name:", dup.name
print " Address:", dup.addr
print " Port:", dup.port
print " Connection string:", dup.server.dbus
raise err
except Exception, err:
if verbosity:
print "Server ID / Name: %d / %s" % ( instance.srvid, instance.name )
raise err
# Now search for players on this server that have not yet been registered
if instance.booted:
if verbosity > 1:
print "Looking for registered Players on Server id %d." % id
instance.readUsersFromMurmur( verbose=verbosity )
elif verbosity:
print "This server is not running, can't sync players."
signals.pre_delete.disconnect( Mumble.pre_delete_listener, sender=Mumble )
for srvid in unseen_ids:
mm = Mumble.objects.get( srvid=srvid )
if verbosity:
print 'Found stale Mumble instance "%s".' % mm.name
mm.delete()
signals.pre_delete.connect( Mumble.pre_delete_listener, sender=Mumble )
return ret
class Mumble( models.Model ):
""" Represents a Murmur server instance.

Loading…
Cancel
Save