mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 16:08:40 +00:00
Remove the plugin hooks from the Core.. These are replaced by Events
This commit is contained in:
parent
7533c4bb88
commit
930c479718
5 changed files with 28 additions and 91 deletions
|
@ -246,9 +246,6 @@ class Core(component.Component):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.error("There was an error adding the torrent file %s", filename)
|
log.error("There was an error adding the torrent file %s", filename)
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
else:
|
|
||||||
# Run the plugin hooks for 'post_torrent_add'
|
|
||||||
self.pluginmanager.run_post_torrent_add(torrent_id)
|
|
||||||
|
|
||||||
@export()
|
@export()
|
||||||
def add_torrent_url(self, url, options):
|
def add_torrent_url(self, url, options):
|
||||||
|
@ -286,17 +283,11 @@ class Core(component.Component):
|
||||||
|
|
||||||
torrent_id = self.torrentmanager.add(magnet=uri, options=option)
|
torrent_id = self.torrentmanager.add(magnet=uri, options=option)
|
||||||
|
|
||||||
# Run the plugin hooks for 'post_torrent_add'
|
|
||||||
self.pluginmanager.run_post_torrent_add(torrent_id)
|
|
||||||
|
|
||||||
|
|
||||||
@export()
|
@export()
|
||||||
def remove_torrent(self, torrent_ids, remove_data):
|
def remove_torrent(self, torrent_ids, remove_data):
|
||||||
log.debug("Removing torrent %s from the core.", torrent_ids)
|
log.debug("Removing torrent %s from the core.", torrent_ids)
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
if self.torrentmanager.remove(torrent_id, remove_data):
|
self.torrentmanager.remove(torrent_id, remove_data)
|
||||||
# Run the plugin hooks for 'post_torrent_remove'
|
|
||||||
self.pluginmanager.run_post_torrent_remove(torrent_id)
|
|
||||||
|
|
||||||
@export()
|
@export()
|
||||||
def get_stats(self):
|
def get_stats(self):
|
||||||
|
|
|
@ -39,13 +39,6 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
||||||
|
|
||||||
def __init__(self, core):
|
def __init__(self, core):
|
||||||
component.Component.__init__(self, "CorePluginManager")
|
component.Component.__init__(self, "CorePluginManager")
|
||||||
self.core = core
|
|
||||||
# Set up the hooks dictionary
|
|
||||||
self.hooks = {
|
|
||||||
"post_torrent_add": [],
|
|
||||||
"post_torrent_remove": [],
|
|
||||||
"post_session_load": []
|
|
||||||
}
|
|
||||||
|
|
||||||
self.status_fields = {}
|
self.status_fields = {}
|
||||||
|
|
||||||
|
@ -66,15 +59,22 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
||||||
|
|
||||||
def update_plugins(self):
|
def update_plugins(self):
|
||||||
for plugin in self.plugins.keys():
|
for plugin in self.plugins.keys():
|
||||||
|
if hasattr(self.plugins[plugin], "update"):
|
||||||
try:
|
try:
|
||||||
self.plugins[plugin].update()
|
self.plugins[plugin].update()
|
||||||
except AttributeError:
|
except Exception, e:
|
||||||
# We don't care if this doesn't work
|
log.exception(e)
|
||||||
pass
|
|
||||||
|
|
||||||
def get_core(self):
|
def get_status(self, torrent_id, fields):
|
||||||
"""Returns a reference to the core"""
|
"""Return the value of status fields for the selected torrent_id."""
|
||||||
return self.core
|
status = {}
|
||||||
|
for field in fields:
|
||||||
|
try:
|
||||||
|
status[field] = self.status_fields[field](torrent_id)
|
||||||
|
except KeyError:
|
||||||
|
log.warning("Status field %s is not registered with the\
|
||||||
|
PluginManager.", field)
|
||||||
|
return status
|
||||||
|
|
||||||
def register_status_field(self, field, function):
|
def register_status_field(self, field, function):
|
||||||
"""Register a new status field. This can be used in the same way the
|
"""Register a new status field. This can be used in the same way the
|
||||||
|
@ -89,61 +89,3 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
||||||
del self.status_fields[field]
|
del self.status_fields[field]
|
||||||
except:
|
except:
|
||||||
log.warning("Unable to deregister status field %s", field)
|
log.warning("Unable to deregister status field %s", field)
|
||||||
|
|
||||||
def get_status(self, torrent_id, fields):
|
|
||||||
"""Return the value of status fields for the selected torrent_id."""
|
|
||||||
status = {}
|
|
||||||
for field in fields:
|
|
||||||
try:
|
|
||||||
status[field] = self.status_fields[field](torrent_id)
|
|
||||||
except KeyError:
|
|
||||||
log.warning("Status field %s is not registered with the\
|
|
||||||
PluginManager.", field)
|
|
||||||
return status
|
|
||||||
|
|
||||||
def register_hook(self, hook, function):
|
|
||||||
"""Register a hook function with the plugin manager"""
|
|
||||||
try:
|
|
||||||
self.hooks[hook].append(function)
|
|
||||||
except KeyError:
|
|
||||||
log.warning("Plugin attempting to register invalid hook.")
|
|
||||||
|
|
||||||
def deregister_hook(self, hook, function):
|
|
||||||
"""Deregisters a hook function"""
|
|
||||||
try:
|
|
||||||
self.hooks[hook].remove(function)
|
|
||||||
except:
|
|
||||||
log.warning("Unable to deregister hook %s", hook)
|
|
||||||
|
|
||||||
def run_post_torrent_add(self, torrent_id):
|
|
||||||
"""This hook is run after a torrent has been added to the session."""
|
|
||||||
log.debug("run_post_torrent_add")
|
|
||||||
for function in self.hooks["post_torrent_add"]:
|
|
||||||
function(torrent_id)
|
|
||||||
|
|
||||||
def run_post_torrent_remove(self, torrent_id):
|
|
||||||
"""This hook is run after a torrent has been removed from the session.
|
|
||||||
"""
|
|
||||||
log.debug("run_post_torrent_remove")
|
|
||||||
for function in self.hooks["post_torrent_remove"]:
|
|
||||||
function(torrent_id)
|
|
||||||
|
|
||||||
def run_post_session_load(self):
|
|
||||||
"""This hook is run after all the torrents have been loaded into the
|
|
||||||
session from the saved state. It is called prior to resuming the
|
|
||||||
torrents and they all will have a 'Paused' state."""
|
|
||||||
log.debug("run_post_session_load")
|
|
||||||
for function in self.hooks["post_session_load"]:
|
|
||||||
function()
|
|
||||||
|
|
||||||
def get_torrent_list(self):
|
|
||||||
"""Returns a list of torrent_id's in the current session."""
|
|
||||||
return component.get("TorrentManager").get_torrent_list()
|
|
||||||
|
|
||||||
def block_ip_range(self, range):
|
|
||||||
"""Blocks the ip range in the core"""
|
|
||||||
return self.core.export_block_ip_range(range)
|
|
||||||
|
|
||||||
def reset_ip_filter(self):
|
|
||||||
"""Resets the ip filter"""
|
|
||||||
return self.core.export_reset_ip_filter()
|
|
||||||
|
|
|
@ -497,8 +497,7 @@ class TorrentManager(component.Component):
|
||||||
log.error("Torrent state file is either corrupt or incompatible!")
|
log.error("Torrent state file is either corrupt or incompatible!")
|
||||||
break
|
break
|
||||||
|
|
||||||
# Run the post_session_load plugin hooks
|
component.get("EventManager").emit(SessionStartedEvent())
|
||||||
self.plugins.run_post_session_load()
|
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
"""Save the state of the TorrentManager to the torrents.state file"""
|
"""Save the state of the TorrentManager to the torrents.state file"""
|
||||||
|
|
|
@ -140,6 +140,13 @@ class NewVersionAvailableEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
self._args = [new_release]
|
self._args = [new_release]
|
||||||
|
|
||||||
|
class SessionStartedEvent(DelugeEvent):
|
||||||
|
"""
|
||||||
|
Emitted when a session has started. This typically only happens once when
|
||||||
|
the daemon is initially started.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class SessionPausedEvent(DelugeEvent):
|
class SessionPausedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when the session has been paused.
|
Emitted when the session has been paused.
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Core(CorePluginBase):
|
||||||
self.plugin.register_status_field("label", self._status_get_label)
|
self.plugin.register_status_field("label", self._status_get_label)
|
||||||
|
|
||||||
#__init__
|
#__init__
|
||||||
core = self.plugin.get_core()
|
core = component.get("Core")
|
||||||
self.config = ConfigManager("label.conf", defaults=CONFIG_DEFAULTS)
|
self.config = ConfigManager("label.conf", defaults=CONFIG_DEFAULTS)
|
||||||
self.core_cfg = ConfigManager("core.conf")
|
self.core_cfg = ConfigManager("core.conf")
|
||||||
#self.set_config_defaults()
|
#self.set_config_defaults()
|
||||||
|
@ -99,9 +99,9 @@ class Core(CorePluginBase):
|
||||||
self.torrent_labels = self.config["torrent_labels"]
|
self.torrent_labels = self.config["torrent_labels"]
|
||||||
|
|
||||||
self.clean_initial_config()
|
self.clean_initial_config()
|
||||||
#todo: register to torrent_added event.
|
|
||||||
self.plugin.register_hook("post_torrent_add", self.post_torrent_add)
|
component.get("EventManager").register_event_handler("TorrentAddedEvent", self.post_torrent_add)
|
||||||
self.plugin.register_hook("post_torrent_remove", self.post_torrent_remove)
|
component.get("EventManager").register_event_handler("TorrentRemovedEvent", self.post_torrent_remove)
|
||||||
|
|
||||||
#register tree:
|
#register tree:
|
||||||
component.get("FilterManager").register_tree_field("label", self.init_filter_dict)
|
component.get("FilterManager").register_tree_field("label", self.init_filter_dict)
|
||||||
|
@ -110,8 +110,6 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
self.plugin.deregister_status_field("label")
|
self.plugin.deregister_status_field("label")
|
||||||
self.plugin.deregister_hook("post_torrent_add", self.post_torrent_add)
|
|
||||||
self.plugin.deregister_hook("post_torrent_remove", self.post_torrent_remove)
|
|
||||||
component.get("FilterManager").deregister_tree_field("label")
|
component.get("FilterManager").deregister_tree_field("label")
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue