Fix setting None for config value

This commit is contained in:
Andrew Resch 2008-08-14 05:58:58 +00:00
parent bc64bed102
commit c4d620f0b9
1 changed files with 24 additions and 21 deletions

View File

@ -113,29 +113,32 @@ class Config:
def set(self, key, value): def set(self, key, value):
"""Set the 'key' with 'value'.""" """Set the 'key' with 'value'."""
# Sets the "key" with "value" in the config dict # Sets the "key" with "value" in the config dict
if self.config[key] != value: if self.config[key] == value:
oldtype, newtype = type(self.config[key]), type(value) return
if oldtype != newtype:
try: oldtype, newtype = type(self.config[key]), type(value)
value = oldtype(value)
except ValueError:
log.warning("Type '%s' invalid for '%s'", newtype, key)
return
log.debug("Setting '%s' to %s of %s", key, value, oldtype) if value is not None and oldtype != newtype:
# Make a copy of the current config prior to changing it
self.previous_config = self.config.copy()
self.config[key] = value
# Run the set_function for this key if any
try: try:
gobject.idle_add(self.set_functions[key], key, value) value = oldtype(value)
except KeyError: except ValueError:
pass log.warning("Type '%s' invalid for '%s'", newtype, key)
try: return
gobject.idle_add(self._change_callback, key, value)
except: log.debug("Setting '%s' to %s of %s", key, value, oldtype)
pass
# Make a copy of the current config prior to changing it
self.previous_config = self.config.copy()
self.config[key] = value
# Run the set_function for this key if any
try:
gobject.idle_add(self.set_functions[key], key, value)
except KeyError:
pass
try:
gobject.idle_add(self._change_callback, key, value)
except:
pass
def get(self, key): def get(self, key):
"""Get the value of 'key'. If it is an invalid key then get() will """Get the value of 'key'. If it is an invalid key then get() will