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):
"""Set the 'key' with 'value'."""
# Sets the "key" with "value" in the config dict
if self.config[key] != value:
oldtype, newtype = type(self.config[key]), type(value)
if oldtype != newtype:
try:
value = oldtype(value)
except ValueError:
log.warning("Type '%s' invalid for '%s'", newtype, key)
return
if self.config[key] == value:
return
oldtype, newtype = type(self.config[key]), type(value)
log.debug("Setting '%s' to %s of %s", key, value, oldtype)
# 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
if value is not None and oldtype != newtype:
try:
gobject.idle_add(self.set_functions[key], key, value)
except KeyError:
pass
try:
gobject.idle_add(self._change_callback, key, value)
except:
pass
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)
# 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):
"""Get the value of 'key'. If it is an invalid key then get() will