ConfigManager now tries to save configs every 5 minutes.

Added close() to ConfigManager to explicitly close and save a config.
This commit is contained in:
Andrew Resch 2007-09-22 03:14:23 +00:00
parent 1f6798c98a
commit cc155d9473
2 changed files with 20 additions and 3 deletions

View File

@ -112,16 +112,14 @@ class Config:
def set(self, key, value):
"""Set the 'key' with 'value'."""
# Sets the "key" with "value" in the config dict
log.debug("Setting '%s' to %s", key, value)
if self.config[key] != value:
log.debug("Setting '%s' to %s", key, value)
self.config[key] = value
# Run the set_function for this key if any
try:
self.set_functions[key](key, value)
except KeyError:
pass
else:
log.debug("Not set because value is same.")
def get(self, key):
"""Get the value of 'key'. If it is an invalid key then get() will

View File

@ -31,6 +31,8 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import gobject
from deluge.log import LOG as log
from deluge.config import Config
@ -38,11 +40,25 @@ class _ConfigManager:
def __init__(self):
log.debug("ConfigManager started..")
self.config_files = {}
# Set a 5 minute timer to call save()
gobject.timeout_add(300000, self.save)
def __del__(self):
log.debug("ConfigManager stopping..")
del self.config_files
def close(self, config):
"""Closes a config file."""
try:
del self.config_files[config]
except KeyError:
pass
def save(self):
"""Saves all the configs to disk."""
for key in self.config_files.keys():
self.config_files[key].save()
def get_config(self, config_file, defaults=None):
"""Get a reference to the Config object for this filename"""
# Create the config object if not already created
@ -56,3 +72,6 @@ _configmanager = _ConfigManager()
def ConfigManager(config, defaults=None):
return _configmanager.get_config(config, defaults)
def close(config):
return _configmanager.close(config)