From e336523df4f83e2b11f8dd957c13c198c29ea0d5 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sat, 13 Feb 2010 11:42:42 +0100 Subject: [PATCH] introduce slicefile parameter to get the CTL stuff independent from django.conf.settings --- pyweb/mumble/MumbleCtlIce.py | 17 ++++++++--------- pyweb/mumble/management/server_detect.py | 13 +++++++++---- pyweb/mumble/mctl.py | 4 ++-- pyweb/mumble/models.py | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pyweb/mumble/MumbleCtlIce.py b/pyweb/mumble/MumbleCtlIce.py index 6e5c988..7503607 100644 --- a/pyweb/mumble/MumbleCtlIce.py +++ b/pyweb/mumble/MumbleCtlIce.py @@ -20,8 +20,6 @@ from PIL import Image from struct import pack, unpack from zlib import compress, decompress -from django.conf import settings - from mctl import MumbleCtlBase from utils import ObjectInfo @@ -44,13 +42,14 @@ def protectDjangoErrPage( func ): return func( *args, **kwargs ); except Ice.Exception, e: raise e; + protection_wrapper.innerfunc = func return protection_wrapper; @protectDjangoErrPage -def MumbleCtlIce( connstring ): +def MumbleCtlIce( connstring, slicefile ): """ Choose the correct Ice handler to use (1.1.8 or 1.2.x), and make sure the Murmur version matches the slice Version. """ @@ -59,19 +58,19 @@ def MumbleCtlIce( connstring ): import Murmur except ImportError: - if not settings.SLICE: + if not slicefile: raise EnvironmentError( "You didn't configure a slice file. Please set the SLICE variable in settings.py." ) - if not exists( settings.SLICE ): - raise EnvironmentError( "The slice file does not exist: '%s' - please check the settings." % settings.SLICE ) + if not exists( slicefile ): + raise EnvironmentError( "The slice file does not exist: '%s' - please check the settings." % slicefile ) - if " " in settings.SLICE: + if " " in slicefile: raise EnvironmentError( "You have a space char in your Slice path. This will confuse Ice, please check." ) - if not settings.SLICE.endswith( ".ice" ): + if not slicefile.endswith( ".ice" ): raise EnvironmentError( "The slice file name MUST end with '.ice'." ) - Ice.loadSlice( settings.SLICE ) + Ice.loadSlice( slicefile ) import Murmur diff --git a/pyweb/mumble/management/server_detect.py b/pyweb/mumble/management/server_detect.py index 9562a07..5c033d5 100644 --- a/pyweb/mumble/management/server_detect.py +++ b/pyweb/mumble/management/server_detect.py @@ -16,8 +16,11 @@ import os -from mumble import models -from mumble.mctl import MumbleCtlBase +from django.conf import settings + +from mumble import models +from mumble.mctl import MumbleCtlBase + def find_in_dicts( keys, conf, default, valueIfNotFound=None ): if not isinstance( keys, tuple ): @@ -66,7 +69,9 @@ def find_existing_instances( **kwargs ): if not dbusName: 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!'; + print 'Be sure to run "python manage.py syncdb" with Murmur running before' + print "trying to use this app! Otherwise, existing Murmur servers won't be" + print 'configurable!'; return False; elif dbusName == "1": dbusName = "net.sourceforge.mumble.murmur"; @@ -74,7 +79,7 @@ def find_existing_instances( **kwargs ): dbusName = "Meta:tcp -h 127.0.0.1 -p 6502"; try: - ctl = MumbleCtlBase.newInstance( dbusName ); + ctl = MumbleCtlBase.newInstance( dbusName, settings.SLICE ); except Exception, instance: if v: print "Unable to connect using name %s. The error was:" % dbusName; diff --git a/pyweb/mumble/mctl.py b/pyweb/mumble/mctl.py index a076ff7..da2fff2 100644 --- a/pyweb/mumble/mctl.py +++ b/pyweb/mumble/mctl.py @@ -95,7 +95,7 @@ class MumbleCtlBase (object): raise NotImplementedError( "mctl::verifyPassword" ); @staticmethod - def newInstance( connstring ): + def newInstance( connstring, slicefile ): """ Create a new CTL object for the given connstring. """ # check cache @@ -112,7 +112,7 @@ class MumbleCtlBase (object): ctl = MumbleCtlDbus( connstring ) else: from MumbleCtlIce import MumbleCtlIce - ctl = MumbleCtlIce( connstring ) + ctl = MumbleCtlIce( connstring, slicefile ) MumbleCtlBase.cache[connstring] = ctl; return ctl; diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 5826b1b..11d5492 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -170,7 +170,7 @@ class Mumble( models.Model ): Only one instance will be created, and reused on subsequent calls. """ if not self._ctl: - self._ctl = MumbleCtlBase.newInstance( self.dbus ); + self._ctl = MumbleCtlBase.newInstance( self.dbus, settings.SLICE ); return self._ctl; ctl = property( getCtl, doc="Get a Control object for this server. The ctl is cached for later reuse." );