31
31
# this exception statement from your version. If you delete this exception
32
32
# statement from all source files in the program, then also delete it here.
38
37
"""PluginManager for Core"""
39
from twisted.internet import reactor
40
from twisted.internet.task import LoopingCall
42
from deluge.event import PluginEnabledEvent, PluginDisabledEvent
42
43
import deluge.pluginmanagerbase
43
44
import deluge.component as component
44
45
from deluge.log import LOG as log
49
50
functions to access parts of the core."""
51
52
def __init__(self, core):
52
component.Component.__init__(self, "PluginManager")
54
# Set up the hooks dictionary
56
"post_torrent_add": [],
57
"post_torrent_remove": [],
58
"post_session_load": []
53
component.Component.__init__(self, "CorePluginManager")
61
55
self.status_fields = {}
68
62
# Enable plugins that are enabled in the config
69
63
self.enable_plugins()
71
# Set update timer to call update() in plugins every second
72
self.update_timer = gobject.timeout_add(1000, self.update_plugins)
75
66
# Disable all enabled plugins
76
67
self.disable_plugins()
77
# Stop the update timer
78
gobject.source_remove(self.update_timer)
80
69
def shutdown(self):
83
72
def update_plugins(self):
84
73
for plugin in self.plugins.keys():
74
if hasattr(self.plugins[plugin], "update"):
76
self.plugins[plugin].update()
80
def enable_plugin(self, name):
81
if name not in self.plugins:
82
super(PluginManager, self).enable_plugin(name)
83
if name in self.plugins:
84
component.get("EventManager").emit(PluginEnabledEvent(name))
86
def disable_plugin(self, name):
87
if name in self.plugins:
88
super(PluginManager, self).disable_plugin(name)
89
if name not in self.plugins:
90
component.get("EventManager").emit(PluginDisabledEvent(name))
92
def get_status(self, torrent_id, fields):
93
"""Return the value of status fields for the selected torrent_id."""
86
self.plugins[plugin].update()
87
except AttributeError:
88
# We don't care if this doesn't work
92
"""Returns a reference to the core"""
97
status[field] = self.status_fields[field](torrent_id)
99
log.warning("Status field %s is not registered with the\
100
PluginManager.", field)
95
103
def register_status_field(self, field, function):
96
104
"""Register a new status field. This can be used in the same way the
105
113
del self.status_fields[field]
107
115
log.warning("Unable to deregister status field %s", field)
109
def get_status(self, torrent_id, fields):
110
"""Return the value of status fields for the selected torrent_id."""
114
status[field] = self.status_fields[field](torrent_id)
116
log.warning("Status field %s is not registered with the\
117
PluginManager.", field)
120
def register_hook(self, hook, function):
121
"""Register a hook function with the plugin manager"""
123
self.hooks[hook].append(function)
125
log.warning("Plugin attempting to register invalid hook.")
127
def deregister_hook(self, hook, function):
128
"""Deregisters a hook function"""
130
self.hooks[hook].remove(function)
132
log.warning("Unable to deregister hook %s", hook)
134
def run_post_torrent_add(self, torrent_id):
135
"""This hook is run after a torrent has been added to the session."""
136
log.debug("run_post_torrent_add")
137
for function in self.hooks["post_torrent_add"]:
140
def run_post_torrent_remove(self, torrent_id):
141
"""This hook is run after a torrent has been removed from the session.
143
log.debug("run_post_torrent_remove")
144
for function in self.hooks["post_torrent_remove"]:
147
def run_post_session_load(self):
148
"""This hook is run after all the torrents have been loaded into the
149
session from the saved state. It is called prior to resuming the
150
torrents and they all will have a 'Paused' state."""
151
log.debug("run_post_session_load")
152
for function in self.hooks["post_session_load"]:
155
def get_torrent_list(self):
156
"""Returns a list of torrent_id's in the current session."""
157
return component.get("TorrentManager").get_torrent_list()
159
def block_ip_range(self, range):
160
"""Blocks the ip range in the core"""
161
return self.core.export_block_ip_range(range)
163
def reset_ip_filter(self):
164
"""Resets the ip filter"""
165
return self.core.export_reset_ip_filter()