Author: andar
Revision: 5376
Log:
Fix the set functions so that you are able to register more than one
per config key
Likewise for the config change callbacks
Diff:
Modified: trunk/deluge/config.py
===================================================================
--- trunk/deluge/config.py 2009-06-10 18:11:14 UTC (rev 5375)
+++ trunk/deluge/config.py 2009-06-10 18:15:52 UTC (rev 5376)
@@ -102,7 +102,7 @@
def __init__(self, filename, defaults=None, config_dir=None):
self.__config = {}
self.__set_functions = {}
- self.__change_callback = None
+ self.__change_callbacks = []
# These hold the version numbers and they will be set when loaded
self.__format_version = None
@@ -177,7 +177,10 @@
except KeyError:
pass
try:
- reactor.callLater(0, self.__change_callback, key, value)
+ def do_change_callbacks(key, value):
+ for func in self.__change_callbacks:
+ func(key, value)
+ reactor.callLater(0, do_change_callbacks, key, value)
except:
pass
@@ -225,7 +228,7 @@
>>> config.register_change_callback(cb)
"""
- self.__change_callback = callback
+ self.__change_callbacks.append(callback)
def register_set_function(self, key, function, apply_now=True):
"""
@@ -246,10 +249,14 @@
"""
log.debug("Registering function for %s key..", key)
- self.__set_functions[key] = function
+ if key not in self.__set_functions:
+ self.__set_functions[key] = []
+
+ self.__set_functions[key].append(function)
+
# Run the function now if apply_now is set
if apply_now:
- self.__set_functions[key](key, self.__config[key])
+ function(key, self.__config[key])
return
def apply_all(self):
@@ -269,7 +276,8 @@
"""
log.debug("Calling all set functions..")
for key, value in self.__set_functions.iteritems():
- value(key, self.__config[key])
+ for func in value:
+ func(key, self.__config[key])
def apply_set_functions(self, key):
"""
@@ -280,7 +288,8 @@
"""
log.debug("Calling set functions for key %s..", key)
if key in self.__set_functions:
- self.__set_functions[key](key, self.__config[key])
+ for func in self.__set_functions[key]:
+ func(key, self.__config[key])
def load(self, filename=None):
"""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---