mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-18 22:36:51 +00:00
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:
parent
1f6798c98a
commit
cc155d9473
@ -112,16 +112,14 @@ 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
|
||||||
log.debug("Setting '%s' to %s", key, value)
|
|
||||||
if self.config[key] != value:
|
if self.config[key] != value:
|
||||||
|
log.debug("Setting '%s' to %s", key, value)
|
||||||
self.config[key] = value
|
self.config[key] = value
|
||||||
# Run the set_function for this key if any
|
# Run the set_function for this key if any
|
||||||
try:
|
try:
|
||||||
self.set_functions[key](key, value)
|
self.set_functions[key](key, value)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
log.debug("Not set because value is same.")
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
# this exception statement from your version. If you delete this exception
|
# this exception statement from your version. If you delete this exception
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
|
import gobject
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
from deluge.config import Config
|
from deluge.config import Config
|
||||||
|
|
||||||
@ -38,11 +40,25 @@ class _ConfigManager:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
log.debug("ConfigManager started..")
|
log.debug("ConfigManager started..")
|
||||||
self.config_files = {}
|
self.config_files = {}
|
||||||
|
# Set a 5 minute timer to call save()
|
||||||
|
gobject.timeout_add(300000, self.save)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
log.debug("ConfigManager stopping..")
|
log.debug("ConfigManager stopping..")
|
||||||
del self.config_files
|
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):
|
def get_config(self, config_file, defaults=None):
|
||||||
"""Get a reference to the Config object for this filename"""
|
"""Get a reference to the Config object for this filename"""
|
||||||
# Create the config object if not already created
|
# Create the config object if not already created
|
||||||
@ -56,3 +72,6 @@ _configmanager = _ConfigManager()
|
|||||||
|
|
||||||
def ConfigManager(config, defaults=None):
|
def ConfigManager(config, defaults=None):
|
||||||
return _configmanager.get_config(config, defaults)
|
return _configmanager.get_config(config, defaults)
|
||||||
|
|
||||||
|
def close(config):
|
||||||
|
return _configmanager.close(config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user