mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-23 06:39:25 +00:00
Updated to current hg head of mumble-django
This commit is contained in:
@@ -14,9 +14,43 @@
|
||||
* GNU General Public License for more details.
|
||||
"""
|
||||
|
||||
from server_detect import find_existing_instances
|
||||
from django.db.models import signals
|
||||
from mumble import models
|
||||
from shutil import copy, move
|
||||
from os.path import exists, join
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
from django.db.models import signals
|
||||
|
||||
from mumble import models
|
||||
|
||||
from update_schema import update_schema
|
||||
from server_detect import find_existing_instances
|
||||
|
||||
|
||||
if settings.DATABASE_ENGINE == "sqlite3":
|
||||
# Move the DB to the db subdirectory if necessary.
|
||||
oldpath = join( settings.MUMBLE_DJANGO_ROOT, "mumble-django.db3" )
|
||||
if not exists( settings.DATABASE_NAME ) and exists( oldpath ):
|
||||
move( oldpath, settings.DATABASE_NAME )
|
||||
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
tablename = models.Mumble._meta.db_table
|
||||
|
||||
if tablename in connection.introspection.get_table_list(cursor):
|
||||
fields = connection.introspection.get_table_description(cursor, tablename)
|
||||
uptodate = "server_id" in [ entry[0] for entry in fields ]
|
||||
else:
|
||||
# Table doesn't yet exist, so syncdb will create it properly
|
||||
uptodate = True
|
||||
|
||||
if not uptodate:
|
||||
if settings.DATABASE_ENGINE == "sqlite3":
|
||||
# backup the db before the conversion.
|
||||
copy( settings.DATABASE_NAME, settings.DATABASE_NAME+".bak" )
|
||||
signals.post_syncdb.connect( update_schema, sender=models );
|
||||
else:
|
||||
signals.post_syncdb.connect( find_existing_instances, sender=models );
|
||||
|
||||
signals.post_syncdb.connect( find_existing_instances, sender=models );
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* GNU General Public License for more details.
|
||||
"""
|
||||
|
||||
import os, Ice
|
||||
import os
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
@@ -28,8 +28,16 @@ class TestFailed( Exception ):
|
||||
pass;
|
||||
|
||||
class Command( BaseCommand ):
|
||||
help = "Run a few tests on Mumble-Django's setup."
|
||||
|
||||
def handle(self, **options):
|
||||
self.check_slice();
|
||||
try:
|
||||
import Ice
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
self.check_slice();
|
||||
|
||||
self.check_rootdir();
|
||||
self.check_dbase();
|
||||
self.check_sites();
|
||||
@@ -166,10 +174,10 @@ class Command( BaseCommand ):
|
||||
else:
|
||||
for mumble in mm:
|
||||
try:
|
||||
mumble.getCtl();
|
||||
except Ice.Exception, err:
|
||||
mumble.ctl
|
||||
except Exception, err:
|
||||
raise TestFailed(
|
||||
"Connecting to Murmur `%s` (%s) failed: %s" % ( mumble.name, mumble.dbus, err )
|
||||
"Connecting to Murmur `%s` (%s) failed: %s" % ( mumble.name, mumble.server, err )
|
||||
);
|
||||
print "[ OK ]";
|
||||
|
||||
|
||||
56
mumble/management/commands/getslice.py
Normal file
56
mumble/management/commands/getslice.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
* Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
|
||||
*
|
||||
* Mumble-Django is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
"""
|
||||
|
||||
import Ice, IcePy, os, getpass
|
||||
from sys import stderr
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from mumble.models import MumbleServer
|
||||
|
||||
class Command( BaseCommand ):
|
||||
help = "Check if the known servers support getSlice."
|
||||
|
||||
def handle(self, **options):
|
||||
prop = Ice.createProperties([])
|
||||
prop.setProperty("Ice.ImplicitContext", "Shared")
|
||||
|
||||
idd = Ice.InitializationData()
|
||||
idd.properties = prop
|
||||
|
||||
ice = Ice.initialize(idd)
|
||||
|
||||
for serv in MumbleServer.objects.all():
|
||||
print "Probing server at '%s'..." % serv.dbus
|
||||
|
||||
if serv.secret:
|
||||
ice.getImplicitContext().put( "secret", serv.secret.encode("utf-8") )
|
||||
|
||||
prx = ice.stringToProxy( serv.dbus.encode("utf-8") )
|
||||
|
||||
# Try loading the Slice from Murmur directly via its getSlice method.
|
||||
try:
|
||||
slice = IcePy.Operation( 'getSlice',
|
||||
Ice.OperationMode.Idempotent, Ice.OperationMode.Idempotent,
|
||||
True, (), (), (), IcePy._t_string, ()
|
||||
).invoke(prx, ((), None))
|
||||
except TypeError, err:
|
||||
print " Received TypeError:", err
|
||||
print " It seems your version of IcePy is incompatible."
|
||||
except Ice.OperationNotExistException:
|
||||
print " Your version of Murmur does not support getSlice."
|
||||
else:
|
||||
print " Successfully received the slice (length: %d bytes.)" % len(slice)
|
||||
@@ -14,11 +14,12 @@
|
||||
* GNU General Public License for more details.
|
||||
"""
|
||||
|
||||
import os
|
||||
import os, getpass
|
||||
|
||||
from django.db import DatabaseError
|
||||
from django.conf import settings
|
||||
|
||||
from mumble import models
|
||||
from mumble.models import MumbleServer, Mumble
|
||||
from mumble.mctl import MumbleCtlBase
|
||||
|
||||
|
||||
@@ -61,7 +62,7 @@ def find_existing_instances( **kwargs ):
|
||||
print " 2) ICE -- Meta:tcp -h 127.0.0.1 -p 6502"
|
||||
print "Enter 1 or 2 for the defaults above, nothing to skip Server detection,"
|
||||
print "and if the defaults do not fit your needs, enter the correct string."
|
||||
print "Whether to use DBus or ICE will be detected automatically from the"
|
||||
print "Whether to use DBus or Ice will be detected automatically from the"
|
||||
print "string's format."
|
||||
print
|
||||
|
||||
@@ -78,8 +79,10 @@ def find_existing_instances( **kwargs ):
|
||||
elif dbusName == "2":
|
||||
dbusName = "Meta:tcp -h 127.0.0.1 -p 6502";
|
||||
|
||||
icesecret = getpass.getpass("Please enter the Ice secret (if any): ");
|
||||
|
||||
try:
|
||||
ctl = MumbleCtlBase.newInstance( dbusName, settings.SLICE );
|
||||
ctl = MumbleCtlBase.newInstance( dbusName, settings.SLICE, icesecret );
|
||||
except Exception, instance:
|
||||
if v:
|
||||
print "Unable to connect using name %s. The error was:" % dbusName;
|
||||
@@ -92,40 +95,71 @@ def find_existing_instances( **kwargs ):
|
||||
|
||||
servIDs = ctl.getAllServers();
|
||||
|
||||
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 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 = models.Mumble.objects.get( dbus=dbusName, srvid=id );
|
||||
except models.Mumble.DoesNotExist:
|
||||
instance = Mumble.objects.get( server=meta, srvid=id );
|
||||
except Mumble.DoesNotExist:
|
||||
values = {
|
||||
"server": meta,
|
||||
"srvid": id,
|
||||
"dbus": dbusName,
|
||||
}
|
||||
|
||||
if v > 1:
|
||||
print "Found new Murmur instance %d on bus '%s'... " % ( id, dbusName ),
|
||||
if v:
|
||||
print "Found new Murmur instance %d on bus '%s'... " % ( id, dbusName )
|
||||
|
||||
# now create a model for the record set.
|
||||
instance = models.Mumble( **values );
|
||||
instance = Mumble( **values );
|
||||
else:
|
||||
if v > 1:
|
||||
print "Syncing Murmur instance... ",
|
||||
if v:
|
||||
print "Syncing Murmur instance %d: '%s'... " % ( instance.id, instance.name )
|
||||
|
||||
instance.configureFromMurmur();
|
||||
|
||||
if v > 1:
|
||||
print instance.name;
|
||||
|
||||
instance.save( dontConfigureMurmur=True );
|
||||
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 > 1:
|
||||
elif v:
|
||||
print "This server is not running, can't sync players.";
|
||||
|
||||
if v > 1:
|
||||
|
||||
76
mumble/management/update_schema.py
Normal file
76
mumble/management/update_schema.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
* Copyright © 2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
|
||||
*
|
||||
* Mumble-Django is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
"""
|
||||
|
||||
import os
|
||||
from os.path import join
|
||||
|
||||
from django.db import connection, transaction
|
||||
from django.db.models import signals
|
||||
from django.conf import settings
|
||||
|
||||
from mumble import models
|
||||
from mumble.management.server_detect import find_existing_instances
|
||||
|
||||
|
||||
def update_schema( **kwargs ):
|
||||
if "verbosity" in kwargs:
|
||||
v = kwargs['verbosity'];
|
||||
else:
|
||||
v = 1;
|
||||
|
||||
if v:
|
||||
print "Migrating Database schema for Mumble-Django 2.0 now."
|
||||
|
||||
scriptdir = join( settings.CONVERSIONSQL_ROOT, {
|
||||
'postgresql_psycopg2': 'pgsql',
|
||||
'postgresql': 'pgsql',
|
||||
'mysql': 'mysql',
|
||||
'sqlite3': 'sqlite',
|
||||
}[settings.DATABASE_ENGINE] )
|
||||
|
||||
if v > 1:
|
||||
print "Reading migration scripts for %s from '%s'" % ( settings.DATABASE_ENGINE, scriptdir )
|
||||
|
||||
scripts = [ filename for filename in os.listdir( scriptdir ) if filename.endswith( ".sql" ) ]
|
||||
scripts.sort()
|
||||
|
||||
for filename in scripts:
|
||||
cursor = connection.cursor()
|
||||
|
||||
scriptpath = os.path.join( scriptdir, filename )
|
||||
scriptfile = open( scriptpath, "r" )
|
||||
try:
|
||||
if v > 1:
|
||||
print "Running migration script '%s'..." % scriptpath
|
||||
stmt = scriptfile.read()
|
||||
cursor.execute( stmt )
|
||||
|
||||
except IOError, err:
|
||||
print "Error reading file '%s':" % filename
|
||||
print err
|
||||
|
||||
except cursor.db.connection.Error, err:
|
||||
print "Error executing file '%s':" % filename
|
||||
print err
|
||||
|
||||
finally:
|
||||
scriptfile.close()
|
||||
cursor.close()
|
||||
|
||||
if v:
|
||||
print "Database migration finished successfully."
|
||||
|
||||
find_existing_instances( **kwargs )
|
||||
Reference in New Issue
Block a user