Initial import of ConfigManager.
This commit is contained in:
parent
c5156df280
commit
8f796738d5
|
@ -0,0 +1,57 @@
|
||||||
|
#
|
||||||
|
# configmanager.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# 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)
|
|
@ -40,7 +40,7 @@ DBusGMainLoop(set_as_default=True)
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
import deluge.libtorrent as lt
|
import deluge.libtorrent as lt
|
||||||
from deluge.config import Config
|
from deluge.configmanager import ConfigManager
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.core.torrentmanager import TorrentManager
|
from deluge.core.torrentmanager import TorrentManager
|
||||||
from deluge.core.pluginmanager import PluginManager
|
from deluge.core.pluginmanager import PluginManager
|
||||||
|
@ -81,7 +81,7 @@ class Core(dbus.service.Object):
|
||||||
dbus.service.Object.__init__(self, bus_name, path)
|
dbus.service.Object.__init__(self, bus_name, path)
|
||||||
|
|
||||||
# Get config
|
# Get config
|
||||||
self.config = Config("core.conf", DEFAULT_PREFS)
|
self.config = ConfigManager("core.conf", DEFAULT_PREFS)
|
||||||
|
|
||||||
# Create the client fingerprint
|
# Create the client fingerprint
|
||||||
version = []
|
version = []
|
||||||
|
|
|
@ -40,7 +40,7 @@ import os
|
||||||
import deluge.libtorrent as lt
|
import deluge.libtorrent as lt
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.config import Config
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.core.torrent import Torrent
|
from deluge.core.torrent import Torrent
|
||||||
from deluge.log import LOG as log
|
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"""
|
"""Add a torrent to the manager and returns it's torrent_id"""
|
||||||
log.info("Adding torrent: %s", filename)
|
log.info("Adding torrent: %s", filename)
|
||||||
# Get the core config
|
# Get the core config
|
||||||
config = Config("core.conf")
|
config = ConfigManager("core.conf")
|
||||||
|
|
||||||
# Make sure 'filename' is a python string
|
# Make sure 'filename' is a python string
|
||||||
filename = str(filename)
|
filename = str(filename)
|
||||||
|
|
|
@ -36,7 +36,7 @@ pygtk.require('2.0')
|
||||||
import gtk, gtk.glade
|
import gtk, gtk.glade
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
from deluge.config import Config
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.common
|
import deluge.common
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class AddTorrentDialog:
|
||||||
self.chooser.add_filter(file_filter)
|
self.chooser.add_filter(file_filter)
|
||||||
|
|
||||||
# Load the 'default_load_path' from the config
|
# 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:
|
if self.config.get("default_load_path") is not None:
|
||||||
self.chooser.set_current_folder(
|
self.chooser.set_current_folder(
|
||||||
self.config.get("default_load_path"))
|
self.config.get("default_load_path"))
|
||||||
|
|
|
@ -41,7 +41,7 @@ import pkg_resources
|
||||||
from mainwindow import MainWindow
|
from mainwindow import MainWindow
|
||||||
from signals import Signals
|
from signals import Signals
|
||||||
from pluginmanager import PluginManager
|
from pluginmanager import PluginManager
|
||||||
from deluge.config import Config
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
|
@ -76,7 +76,7 @@ class GtkUI:
|
||||||
"deluge", "i18n"))
|
"deluge", "i18n"))
|
||||||
|
|
||||||
# Make sure gtkui.conf has at least the defaults set
|
# Make sure gtkui.conf has at least the defaults set
|
||||||
config = Config("gtkui.conf", DEFAULT_PREFS)
|
config = ConfigManager("gtkui.conf", DEFAULT_PREFS)
|
||||||
del config
|
del config
|
||||||
|
|
||||||
# Initialize the main window
|
# Initialize the main window
|
||||||
|
|
|
@ -39,7 +39,7 @@ import pkg_resources
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.ui.functions as functions
|
import deluge.ui.functions as functions
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.config import Config
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
class Preferences:
|
class Preferences:
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
|
@ -85,7 +85,7 @@ class Preferences:
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
self.core_config = functions.get_config(self.core)
|
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
|
# Update the preferences dialog to reflect current config settings
|
||||||
|
|
||||||
## Downloads tab ##
|
## Downloads tab ##
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
# 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.
|
||||||
|
|
||||||
from deluge.config import Config
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ DEFAULT_PREFS = {
|
||||||
class UI:
|
class UI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
log.debug("UI init..")
|
log.debug("UI init..")
|
||||||
self.config = Config("ui.conf", DEFAULT_PREFS)
|
self.config = ConfigManager("ui.conf", DEFAULT_PREFS)
|
||||||
|
|
||||||
if self.config["selected_ui"] == "gtk":
|
if self.config["selected_ui"] == "gtk":
|
||||||
log.info("Starting GtkUI..")
|
log.info("Starting GtkUI..")
|
||||||
|
|
Loading…
Reference in New Issue