From cc155d94732e0b16356e2f5a5566385a11200503 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 22 Sep 2007 03:14:23 +0000 Subject: [PATCH] ConfigManager now tries to save configs every 5 minutes. Added close() to ConfigManager to explicitly close and save a config. --- deluge/config.py | 4 +--- deluge/configmanager.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/deluge/config.py b/deluge/config.py index cdb3a29d9..187b2ffe1 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -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 diff --git a/deluge/configmanager.py b/deluge/configmanager.py index 543492f36..aaf87fa00 100644 --- a/deluge/configmanager.py +++ b/deluge/configmanager.py @@ -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)