Use deluge.component for core components.

This commit is contained in:
Andrew Resch 2007-12-10 10:49:42 +00:00
parent 559fcdf51c
commit 78b78ce8b3
22 changed files with 63 additions and 31 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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

View File

@ -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 = {

View File

@ -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)

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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