From 78b78ce8b3bbc24e04814c17da5796ce62835c7a Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 10 Dec 2007 10:49:42 +0000 Subject: [PATCH] Use deluge.component for core components. --- deluge/common.py | 4 ++++ deluge/core/alertmanager.py | 16 ++++++++++++++-- deluge/core/core.py | 6 ++++-- deluge/core/pluginmanager.py | 5 ++++- deluge/core/signalmanager.py | 7 ++++++- deluge/core/torrentmanager.py | 24 +++++++++++++++--------- deluge/ui/gtkui/connectionmanager.py | 2 +- deluge/ui/gtkui/dbusinterface.py | 2 +- deluge/ui/gtkui/gtkui.py | 2 +- deluge/ui/gtkui/mainwindow.py | 2 +- deluge/ui/gtkui/menubar.py | 2 +- deluge/ui/gtkui/pluginmanager.py | 2 +- deluge/ui/gtkui/preferences.py | 2 +- deluge/ui/gtkui/queuedtorrents.py | 2 +- deluge/ui/gtkui/removetorrentdialog.py | 2 +- deluge/ui/gtkui/sidebar.py | 2 +- deluge/ui/gtkui/signals.py | 2 +- deluge/ui/gtkui/statusbar.py | 2 +- deluge/ui/gtkui/systemtray.py | 2 +- deluge/ui/gtkui/toolbar.py | 2 +- deluge/ui/gtkui/torrentdetails.py | 2 +- deluge/ui/gtkui/torrentview.py | 2 +- 22 files changed, 63 insertions(+), 31 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index e437cf298..52dba9414 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -101,6 +101,10 @@ def get_logo(size): return gtk.gdk.pixbuf_new_from_file_at_size(get_pixmap("deluge.svg"), \ size, size) +def open_file(path): + """Opens a file or folder.""" + os.popen("xdg-open %s" % path) + ## Formatting text functions def fsize(fsize_b): diff --git a/deluge/core/alertmanager.py b/deluge/core/alertmanager.py index 4df546005..4d1be6e03 100644 --- a/deluge/core/alertmanager.py +++ b/deluge/core/alertmanager.py @@ -35,19 +35,31 @@ import gobject +import deluge.component as component import deluge.libtorrent as lt from deluge.log import LOG as log -class AlertManager: +class AlertManager(component.Component): def __init__(self, session): log.debug("AlertManager initialized..") + component.Component.__init__(self, "AlertManager") self.session = session self.session.set_severity_level(lt.alert.severity_levels.info) # handlers is a dictionary of lists {"alert_type": [handler1,h2,..]} self.handlers = {} + + def start(self): # Handle the alerts every 50 milliseconds - gobject.timeout_add(50, self.handle_alerts) + self.timer = gobject.timeout_add(50, self.handle_alerts) + def stop(self): + gobject.source_remove(self.timer) + + def shutdown(self): + self.stop() + del self.session + del self.handlers + def register_handler(self, alert_type, handler): """Registers a function that will be called when 'alert_type' is pop'd in handle_alerts. The handler function should look like: diff --git a/deluge/core/core.py b/deluge/core/core.py index 0fa3591f6..9cfbc24f9 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -48,6 +48,7 @@ import threading import deluge.libtorrent as lt from deluge.configmanager import ConfigManager import deluge.common +import deluge.component as component from deluge.core.torrentmanager import TorrentManager from deluge.core.pluginmanager import PluginManager from deluge.core.alertmanager import AlertManager @@ -213,6 +214,8 @@ class Core( self.alerts.register_handler("torrent_paused_alert", self._on_alert_torrent_paused) + component.start() + t = threading.Thread(target=self.serve_forever) t.setDaemon(True) t.start() @@ -224,8 +227,7 @@ class Core( def _shutdown(self): """This is called by a thread from shutdown()""" log.info("Shutting down core..") - self.plugins.shutdown() - self.torrents.shutdown() + component.shutdown() # Make sure the config file has been saved self.config.save() del self.config diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index c4b3e97da..b57877754 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -34,13 +34,16 @@ """PluginManager for Core""" import deluge.pluginmanagerbase +import deluge.component as component from deluge.log import LOG as log -class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): +class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, + component.Component): """PluginManager handles the loading of plugins and provides plugins with functions to access parts of the core.""" def __init__(self, core): + component.Component.__init__(self, "PluginManager") self.core = core # Set up the hooks dictionary self.hooks = { diff --git a/deluge/core/signalmanager.py b/deluge/core/signalmanager.py index d632f9c52..ed13be23f 100644 --- a/deluge/core/signalmanager.py +++ b/deluge/core/signalmanager.py @@ -33,12 +33,17 @@ import xmlrpclib +import deluge.component as component from deluge.log import LOG as log -class SignalManager: +class SignalManager(component.Component): def __init__(self): + component.Component.__init__(self, "SignalManager") self.clients = {} + def shutdown(self): + del self.clients + def deregister_client(self, address): """Deregisters a client""" log.debug("Deregistering %s as a signal reciever..", address) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index a1d4476f1..26fe9aed7 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -42,6 +42,7 @@ import gobject import deluge.libtorrent as lt import deluge.common +import deluge.component as component from deluge.configmanager import ConfigManager from deluge.core.torrent import Torrent from deluge.log import LOG as log @@ -61,12 +62,13 @@ class TorrentManagerState: def __init__(self): self.torrents = [] -class TorrentManager: +class TorrentManager(component.Component): """TorrentManager contains a list of torrents in the current libtorrent session. This object is also responsible for saving the state of the session for use on restart.""" def __init__(self, session, alerts): + component.Component.__init__(self, "TorrentManager") log.debug("TorrentManager init..") # Set the libtorrent session self.session = session @@ -79,11 +81,6 @@ class TorrentManager: self.max_uploads = -1 # Create the torrents dict { torrent_id: Torrent } self.torrents = {} - # Try to load the state from file - self.load_state() - - # Save the state every 5 minutes - self.save_state_timer = gobject.timeout_add(300000, self.save_state) # Register set functions self.config.register_set_function("max_connections_per_torrent", @@ -103,9 +100,15 @@ class TorrentManager: self.alerts.register_handler("tracker_alert", self.on_alert_tracker) self.alerts.register_handler("tracker_warning_alert", self.on_alert_tracker_warning) - - def shutdown(self): - log.debug("TorrentManager shutting down..") + + def start(self): + # Try to load the state from file + self.load_state() + + # Save the state every 5 minutes + self.save_state_timer = gobject.timeout_add(300000, self.save_state) + + def stop(self): # Save state on shutdown self.save_state() # Pause all torrents and save the .fastresume files @@ -113,6 +116,9 @@ class TorrentManager: for key in self.torrents.keys(): self.write_fastresume(key) + def shutdown(self): + self.stop() + def __getitem__(self, torrent_id): """Return the Torrent with torrent_id""" return self.torrents[torrent_id] diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index 17ca1a1e3..bad92d6cc 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -37,7 +37,7 @@ import gobject import socket import os -import deluge.ui.component as component +import deluge.component as component import deluge.xmlrpclib as xmlrpclib import deluge.common import deluge.ui.client as client diff --git a/deluge/ui/gtkui/dbusinterface.py b/deluge/ui/gtkui/dbusinterface.py index d4699f526..ff44a70c1 100644 --- a/deluge/ui/gtkui/dbusinterface.py +++ b/deluge/ui/gtkui/dbusinterface.py @@ -45,7 +45,7 @@ elif dbus.version >= (0,80,0): from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client import deluge.common from deluge.log import LOG as log diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index 6b1fe4d1b..48ccd6ffa 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -38,7 +38,7 @@ import gettext import locale import pkg_resources -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client from mainwindow import MainWindow from menubar import MenuBar diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index df95d0df1..912f240d1 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -38,7 +38,7 @@ import gobject import pkg_resources import deluge.ui.client as client -import deluge.ui.component as component +import deluge.component as component from deluge.configmanager import ConfigManager import deluge.common diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index bb7c42ed8..49d572c57 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -36,7 +36,7 @@ pygtk.require('2.0') import gtk, gtk.glade import pkg_resources -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client from deluge.log import LOG as log diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 48148df53..41bf263b0 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.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. -import deluge.ui.component as component +import deluge.component as component import deluge.pluginmanagerbase import deluge.ui.client as client from deluge.configmanager import ConfigManager diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 44d5e581c..192fc75de 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -36,7 +36,7 @@ pygtk.require('2.0') import gtk, gtk.glade import pkg_resources -import deluge.ui.component as component +import deluge.component as component from deluge.log import LOG as log import deluge.ui.client as client import deluge.common diff --git a/deluge/ui/gtkui/queuedtorrents.py b/deluge/ui/gtkui/queuedtorrents.py index 9ea4efe3b..eac987d9c 100644 --- a/deluge/ui/gtkui/queuedtorrents.py +++ b/deluge/ui/gtkui/queuedtorrents.py @@ -36,7 +36,7 @@ import os.path import gtk, gtk.glade import pkg_resources -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client import deluge.common from deluge.configmanager import ConfigManager diff --git a/deluge/ui/gtkui/removetorrentdialog.py b/deluge/ui/gtkui/removetorrentdialog.py index 839985daa..b9de23bed 100644 --- a/deluge/ui/gtkui/removetorrentdialog.py +++ b/deluge/ui/gtkui/removetorrentdialog.py @@ -36,7 +36,7 @@ import pkg_resources import deluge.common import deluge.ui.client as client -import deluge.ui.component as component +import deluge.component as component from deluge.log import LOG as log class RemoveTorrentDialog: diff --git a/deluge/ui/gtkui/sidebar.py b/deluge/ui/gtkui/sidebar.py index 9f0b37391..3e67c1d53 100644 --- a/deluge/ui/gtkui/sidebar.py +++ b/deluge/ui/gtkui/sidebar.py @@ -34,7 +34,7 @@ import gtk import gtk.glade -import deluge.ui.component as component +import deluge.component as component import deluge.common from deluge.log import LOG as log diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index 9f8b948f3..aaed607a3 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.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. -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client from deluge.ui.signalreceiver import SignalReceiver from deluge.log import LOG as log diff --git a/deluge/ui/gtkui/statusbar.py b/deluge/ui/gtkui/statusbar.py index 30378b0d4..945d0c00f 100644 --- a/deluge/ui/gtkui/statusbar.py +++ b/deluge/ui/gtkui/statusbar.py @@ -33,7 +33,7 @@ import gtk -import deluge.ui.component as component +import deluge.component as component import deluge.common import deluge.ui.client as client from deluge.log import LOG as log diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index 326fd149f..e93e0a91c 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -34,7 +34,7 @@ import gtk import pkg_resources -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client import deluge.common from deluge.configmanager import ConfigManager diff --git a/deluge/ui/gtkui/toolbar.py b/deluge/ui/gtkui/toolbar.py index 7dd7c858e..e776de875 100644 --- a/deluge/ui/gtkui/toolbar.py +++ b/deluge/ui/gtkui/toolbar.py @@ -36,7 +36,7 @@ pygtk.require('2.0') import gtk, gtk.glade import gobject -import deluge.ui.component as component +import deluge.component as component from deluge.log import LOG as log from deluge.common import TORRENT_STATE import deluge.ui.client as client diff --git a/deluge/ui/gtkui/torrentdetails.py b/deluge/ui/gtkui/torrentdetails.py index be985887a..580cf360f 100644 --- a/deluge/ui/gtkui/torrentdetails.py +++ b/deluge/ui/gtkui/torrentdetails.py @@ -38,7 +38,7 @@ pygtk.require('2.0') import gtk, gtk.glade import gettext -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client import deluge.common from deluge.log import LOG as log diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 170c5c2b7..77360b09a 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -40,7 +40,7 @@ import gettext import gobject import deluge.common -import deluge.ui.component as component +import deluge.component as component import deluge.ui.client as client from deluge.log import LOG as log import deluge.ui.gtkui.listview as listview