diff --git a/deluge/configmanager.py b/deluge/configmanager.py new file mode 100644 index 000000000..aed3ad10e --- /dev/null +++ b/deluge/configmanager.py @@ -0,0 +1,57 @@ +# +# configmanager.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# Deluge is free software. +# +# You may redistribute it and/or modify it under the terms of the +# GNU General Public License, as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# deluge is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with deluge. If not, write to: +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. + +from deluge.log import LOG as log +from deluge.config import Config + +class _ConfigManager: + def __init__(self): + log.debug("ConfigManager started..") + self.config_files = {} + + def __del__(self): + del self.config_files + + 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 + if config_file not in self.config_files.keys(): + self.config_files[config_file] = Config(config_file, defaults) + + return self.config_files[config_file] + +# Singleton functions +_configmanager = _ConfigManager() + +def ConfigManager(config, defaults=None): + return _configmanager.get_config(config, defaults) diff --git a/deluge/core/core.py b/deluge/core/core.py index 4f89cceb2..d5d4fae48 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -40,7 +40,7 @@ DBusGMainLoop(set_as_default=True) import gobject import deluge.libtorrent as lt -from deluge.config import Config +from deluge.configmanager import ConfigManager import deluge.common from deluge.core.torrentmanager import TorrentManager from deluge.core.pluginmanager import PluginManager @@ -81,8 +81,8 @@ class Core(dbus.service.Object): dbus.service.Object.__init__(self, bus_name, path) # Get config - self.config = Config("core.conf", DEFAULT_PREFS) - + self.config = ConfigManager("core.conf", DEFAULT_PREFS) + # Create the client fingerprint version = [] for value in deluge.common.get_version().split("."): diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 017959589..464a941be 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -40,7 +40,7 @@ import os import deluge.libtorrent as lt import deluge.common -from deluge.config import Config +from deluge.configmanager import ConfigManager from deluge.core.torrent import Torrent from deluge.log import LOG as log @@ -85,7 +85,7 @@ class TorrentManager: """Add a torrent to the manager and returns it's torrent_id""" log.info("Adding torrent: %s", filename) # Get the core config - config = Config("core.conf") + config = ConfigManager("core.conf") # Make sure 'filename' is a python string filename = str(filename) diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 8d48a69e8..9966e58da 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -36,7 +36,7 @@ pygtk.require('2.0') import gtk, gtk.glade import gettext -from deluge.config import Config +from deluge.configmanager import ConfigManager from deluge.log import LOG as log import deluge.common @@ -64,7 +64,7 @@ class AddTorrentDialog: self.chooser.add_filter(file_filter) # Load the 'default_load_path' from the config - self.config = Config("gtkui.conf") + self.config = ConfigManager("gtkui.conf") if self.config.get("default_load_path") is not None: self.chooser.set_current_folder( self.config.get("default_load_path")) diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index 6ff7badb6..fb29503aa 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -41,7 +41,7 @@ import pkg_resources from mainwindow import MainWindow from signals import Signals from pluginmanager import PluginManager -from deluge.config import Config +from deluge.configmanager import ConfigManager from deluge.log import LOG as log DEFAULT_PREFS = { @@ -76,7 +76,7 @@ class GtkUI: "deluge", "i18n")) # Make sure gtkui.conf has at least the defaults set - config = Config("gtkui.conf", DEFAULT_PREFS) + config = ConfigManager("gtkui.conf", DEFAULT_PREFS) del config # Initialize the main window diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index d12586248..1625b8b49 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -39,7 +39,7 @@ import pkg_resources from deluge.log import LOG as log import deluge.ui.functions as functions import deluge.common -from deluge.config import Config +from deluge.configmanager import ConfigManager class Preferences: def __init__(self, window): @@ -85,7 +85,7 @@ class Preferences: def show(self): self.core_config = functions.get_config(self.core) - self.gtkui_config = Config("gtkui.conf") + self.gtkui_config = ConfigManager("gtkui.conf") # Update the preferences dialog to reflect current config settings ## Downloads tab ## diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py index e13b15d1f..6706c6a68 100644 --- a/deluge/ui/ui.py +++ b/deluge/ui/ui.py @@ -31,7 +31,7 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. -from deluge.config import Config +from deluge.configmanager import ConfigManager from deluge.log import LOG as log @@ -42,7 +42,7 @@ DEFAULT_PREFS = { class UI: def __init__(self): log.debug("UI init..") - self.config = Config("ui.conf", DEFAULT_PREFS) + self.config = ConfigManager("ui.conf", DEFAULT_PREFS) if self.config["selected_ui"] == "gtk": log.info("Starting GtkUI..")