Merge branch 'master' of deluge-torrent.org:/deluge
This commit is contained in:
commit
db46a97263
|
@ -243,12 +243,13 @@ class PluginEnabledEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a plugin is enabled in the Core.
|
Emitted when a plugin is enabled in the Core.
|
||||||
"""
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, plugin_name):
|
||||||
self._args = [name]
|
self._args = [plugin_name]
|
||||||
|
|
||||||
class PluginDisabledEvent(DelugeEvent):
|
class PluginDisabledEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a plugin is disabled in the Core.
|
Emitted when a plugin is disabled in the Core.
|
||||||
"""
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, plugin_name):
|
||||||
self._args = [name]
|
self._args = [plugin_name]
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,8 @@ MAX_NUM_ATTEMPTS = 10
|
||||||
|
|
||||||
class AutoaddOptionsChangedEvent(DelugeEvent):
|
class AutoaddOptionsChangedEvent(DelugeEvent):
|
||||||
"""Emitted when the options for the plugin are changed."""
|
"""Emitted when the options for the plugin are changed."""
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def CheckInput(cond, message):
|
def CheckInput(cond, message):
|
||||||
if not cond:
|
if not cond:
|
||||||
|
|
|
@ -334,7 +334,7 @@ class GtkUI(GtkPluginBase):
|
||||||
def on_show_prefs(self):
|
def on_show_prefs(self):
|
||||||
client.autoadd.get_config().addCallback(self.cb_get_config)
|
client.autoadd.get_config().addCallback(self.cb_get_config)
|
||||||
|
|
||||||
def on_options_changed_event(self, event):
|
def on_options_changed_event(self):
|
||||||
client.autoadd.get_config().addCallback(self.cb_get_config)
|
client.autoadd.get_config().addCallback(self.cb_get_config)
|
||||||
|
|
||||||
def cb_get_config(self, config):
|
def cb_get_config(self, config):
|
||||||
|
|
|
@ -64,19 +64,15 @@ class ExecuteCommandAddedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a new command is added.
|
Emitted when a new command is added.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('command_id', 'event', 'command')
|
|
||||||
def __init__(self, command_id, event, command):
|
def __init__(self, command_id, event, command):
|
||||||
self.command_id = command_id
|
self._args = [command_id, event, command]
|
||||||
self.event = event
|
|
||||||
self.command = command
|
|
||||||
|
|
||||||
class ExecuteCommandRemovedEvent(DelugeEvent):
|
class ExecuteCommandRemovedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a command is removed.
|
Emitted when a command is removed.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('command_id',)
|
|
||||||
def __init__(self, command_id):
|
def __init__(self, command_id):
|
||||||
self.command_id = command_id
|
self._args = [command_id]
|
||||||
|
|
||||||
class Core(CorePluginBase):
|
class Core(CorePluginBase):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
|
@ -86,17 +82,17 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
# Go through the commands list and register event handlers
|
# Go through the commands list and register event handlers
|
||||||
for command in self.config["commands"]:
|
for command in self.config["commands"]:
|
||||||
event_name = command[EXECUTE_EVENT]
|
event = command[EXECUTE_EVENT]
|
||||||
if event_name in self.registered_events:
|
if event in self.registered_events:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def create_event_handler(event_name):
|
def create_event_handler(event):
|
||||||
def event_handler(event):
|
def event_handler(torrent_id):
|
||||||
self.execute_commands(event.torrent_id, event_name)
|
self.execute_commands(torrent_id, event)
|
||||||
return event_handler
|
return event_handler
|
||||||
event_handler = create_event_handler(event_name)
|
event_handler = create_event_handler(event)
|
||||||
event_manager.register_event_handler(EVENT_MAP[event_name], event_handler)
|
event_manager.register_event_handler(EVENT_MAP[event], event_handler)
|
||||||
self.registered_events[event_name] = event_handler
|
self.registered_events[event] = event_handler
|
||||||
|
|
||||||
log.debug("Execute core plugin enabled!")
|
log.debug("Execute core plugin enabled!")
|
||||||
|
|
||||||
|
|
|
@ -161,13 +161,13 @@ class ExecutePreferences(object):
|
||||||
command = widget.get_text()
|
command = widget.get_text()
|
||||||
client.execute.save_command(command_id, event, command)
|
client.execute.save_command(command_id, event, command)
|
||||||
|
|
||||||
def on_command_added_event(self, event):
|
def on_command_added_event(self, command_id, event, command):
|
||||||
log.debug("Adding command %s: %s", event.event, event.command)
|
log.debug("Adding command %s: %s", event, command)
|
||||||
self.add_command(event.command_id, event.event, event.command)
|
self.add_command(command_id, event, command)
|
||||||
|
|
||||||
def on_command_removed_event(self, event):
|
def on_command_removed_event(self, command_id):
|
||||||
log.debug("Removing command %s", event.command_id)
|
log.debug("Removing command %s", command_id)
|
||||||
self.remove_command(event.command_id)
|
self.remove_command(command_id)
|
||||||
|
|
||||||
class GtkUI(GtkPluginBase):
|
class GtkUI(GtkPluginBase):
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,14 @@ class Core(CorePluginBase):
|
||||||
def update(self):
|
def update(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _on_torrent_finished(self, event):
|
def _on_torrent_finished(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
This is called when a torrent finishes. We need to check to see if there
|
This is called when a torrent finishes. We need to check to see if there
|
||||||
are any files to extract.
|
are any files to extract.
|
||||||
"""
|
"""
|
||||||
# Get the save path
|
# Get the save path
|
||||||
save_path = component.get("TorrentManager")[event.torrent_id].get_status(["save_path"])["save_path"]
|
save_path = component.get("TorrentManager")[torrent_id].get_status(["save_path"])["save_path"]
|
||||||
files = component.get("TorrentManager")[event.torrent_id].get_files()
|
files = component.get("TorrentManager")[torrent_id].get_files()
|
||||||
for f in files:
|
for f in files:
|
||||||
ext = os.path.splitext(f["path"])
|
ext = os.path.splitext(f["path"])
|
||||||
if ext[1] in (".gz", ".bz2", ".lzma"):
|
if ext[1] in (".gz", ".bz2", ".lzma"):
|
||||||
|
@ -104,7 +104,7 @@ class Core(CorePluginBase):
|
||||||
# Get the destination path
|
# Get the destination path
|
||||||
dest = self.config["extract_path"]
|
dest = self.config["extract_path"]
|
||||||
if self.config["use_name_folder"]:
|
if self.config["use_name_folder"]:
|
||||||
name = component.get("TorrentManager")[event.torrent_id].get_status(["name"])["name"]
|
name = component.get("TorrentManager")[torrent_id].get_status(["name"])["name"]
|
||||||
dest = os.path.join(dest, name)
|
dest = os.path.join(dest, name)
|
||||||
|
|
||||||
# Create the destination folder if it doesn't exist
|
# Create the destination folder if it doesn't exist
|
||||||
|
@ -126,8 +126,8 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
# Run the command and add some callbacks
|
# Run the command and add some callbacks
|
||||||
d = getProcessValue(cmd[0], cmd[1].split() + [str(fp)], {}, str(dest))
|
d = getProcessValue(cmd[0], cmd[1].split() + [str(fp)], {}, str(dest))
|
||||||
d.addCallback(on_extract_success, event.torrent_id)
|
d.addCallback(on_extract_success, torrent_id)
|
||||||
d.addErrback(on_extract_failed, event.torrent_id)
|
d.addErrback(on_extract_failed, torrent_id)
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def set_config(self, config):
|
def set_config(self, config):
|
||||||
|
|
|
@ -55,14 +55,12 @@ class LowDiskSpaceEvent(DelugeEvent):
|
||||||
"""Triggered when the available space for a specific path is getting
|
"""Triggered when the available space for a specific path is getting
|
||||||
too low.
|
too low.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('percents_dict',)
|
|
||||||
|
|
||||||
def __init__(self, percents_dict):
|
def __init__(self, percents_dict):
|
||||||
"""
|
"""
|
||||||
:param percents: dictionary of path keys with their respecive
|
:param percents: dictionary of path keys with their respecive
|
||||||
occupation percentages.
|
occupation percentages.
|
||||||
"""
|
"""
|
||||||
self.percents_dict = percents_dict
|
self._args = [percents_dict]
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
|
@ -174,25 +172,25 @@ class Core(CorePluginBase):
|
||||||
free_percent = free_blocks * 100 / total_blocks
|
free_percent = free_blocks * 100 / total_blocks
|
||||||
return free_percent
|
return free_percent
|
||||||
|
|
||||||
def __custom_email_notification(self, event):
|
def __custom_email_notification(self, ocupied_percents):
|
||||||
|
|
||||||
subject = _("Low Disk Space Warning")
|
subject = _("Low Disk Space Warning")
|
||||||
message = _("You're running low on disk space:\n")
|
message = _("You're running low on disk space:\n")
|
||||||
|
|
||||||
for path, ocupied_percent in event.percents_dict.iteritems():
|
for path, ocupied_percent in ocupied_percents.iteritems():
|
||||||
message += _(' %s%% ocupation in %s\n') % (ocupied_percent, path)
|
message += _(' %s%% ocupation in %s\n') % (ocupied_percent, path)
|
||||||
# "\"%s\"%% space occupation on %s") % (ocupied_percent, path)
|
# "\"%s\"%% space occupation on %s") % (ocupied_percent, path)
|
||||||
return subject, message
|
return subject, message
|
||||||
|
|
||||||
def __on_plugin_enabled(self, event):
|
def __on_plugin_enabled(self, plugin_name):
|
||||||
if event.plugin_name == 'Notifications':
|
if plugin_name == 'Notifications':
|
||||||
component.get("CorePlugin.Notifications"). \
|
component.get("CorePlugin.Notifications"). \
|
||||||
register_custom_email_notification(
|
register_custom_email_notification(
|
||||||
"LowDiskSpaceEvent", self.__custom_email_notification
|
"LowDiskSpaceEvent", self.__custom_email_notification
|
||||||
)
|
)
|
||||||
|
|
||||||
def __on_plugin_disabled(self, event):
|
def __on_plugin_disabled(self, plugin_name):
|
||||||
if event.plugin_name == 'Notifications':
|
if plugin_name == 'Notifications':
|
||||||
component.get("CorePlugin.Notifications"). \
|
component.get("CorePlugin.Notifications"). \
|
||||||
deregister_custom_email_notification("LowDiskSpaceEvent")
|
deregister_custom_email_notification("LowDiskSpaceEvent")
|
||||||
|
|
||||||
|
|
|
@ -134,22 +134,22 @@ class GtkUI(GtkPluginBase):
|
||||||
self.glade.get_widget('enabled').set_active(config['enabled'])
|
self.glade.get_widget('enabled').set_active(config['enabled'])
|
||||||
self.glade.get_widget('percent').set_value(config['percent'])
|
self.glade.get_widget('percent').set_value(config['percent'])
|
||||||
|
|
||||||
def __custom_popup_notification(self, event):
|
def __custom_popup_notification(self, ocupied_percents):
|
||||||
title = _("Low Free Space")
|
title = _("Low Free Space")
|
||||||
message = ''
|
message = ''
|
||||||
for path, percent in event.percents_dict.iteritems():
|
for path, percent in ocupied_percents.iteritems():
|
||||||
message += '%s%% %s\n' % (percent, path)
|
message += '%s%% %s\n' % (percent, path)
|
||||||
message += '\n'
|
message += '\n'
|
||||||
return title, message
|
return title, message
|
||||||
|
|
||||||
def __custom_blink_notification(self, event):
|
def __custom_blink_notification(self, ocupied_percents):
|
||||||
return True # Yes, do blink
|
return True # Yes, do blink
|
||||||
|
|
||||||
def __custom_sound_notification(self, event):
|
def __custom_sound_notification(self, ocupied_percents):
|
||||||
return '' # Use default sound
|
return '' # Use default sound
|
||||||
|
|
||||||
def __on_plugin_enabled(self, event):
|
def __on_plugin_enabled(self, plugin_name):
|
||||||
if event.plugin_name == 'Notifications':
|
if plugin_name == 'Notifications':
|
||||||
notifications = component.get("GtkPlugin.Notifications")
|
notifications = component.get("GtkPlugin.Notifications")
|
||||||
notifications.register_custom_popup_notification(
|
notifications.register_custom_popup_notification(
|
||||||
"LowDiskSpaceEvent", self.__custom_popup_notification
|
"LowDiskSpaceEvent", self.__custom_popup_notification
|
||||||
|
@ -161,7 +161,7 @@ class GtkUI(GtkPluginBase):
|
||||||
"LowDiskSpaceEvent", self.__custom_sound_notification
|
"LowDiskSpaceEvent", self.__custom_sound_notification
|
||||||
)
|
)
|
||||||
|
|
||||||
def __on_plugin_disabled(self, event):
|
def __on_plugin_disabled(self, plugin_name):
|
||||||
pass
|
pass
|
||||||
# if plugin_name == 'Notifications':
|
# if plugin_name == 'Notifications':
|
||||||
# notifications = component.get("GtkPlugin.Notifications")
|
# notifications = component.get("GtkPlugin.Notifications")
|
||||||
|
|
|
@ -133,20 +133,20 @@ class Core(CorePluginBase):
|
||||||
return dict( [(label, 0) for label in self.labels.keys()])
|
return dict( [(label, 0) for label in self.labels.keys()])
|
||||||
|
|
||||||
## Plugin hooks ##
|
## Plugin hooks ##
|
||||||
def post_torrent_add(self, event):
|
def post_torrent_add(self, torrent_id, from_state):
|
||||||
log.debug("post_torrent_add")
|
log.debug("post_torrent_add")
|
||||||
torrent = self.torrents[event.torrent_id]
|
torrent = self.torrents[torrent_id]
|
||||||
|
|
||||||
for label_id, options in self.labels.iteritems():
|
for label_id, options in self.labels.iteritems():
|
||||||
if options["auto_add"]:
|
if options["auto_add"]:
|
||||||
if self._has_auto_match(torrent, options):
|
if self._has_auto_match(torrent, options):
|
||||||
self.set_torrent(event.torrent_id, label_id)
|
self.set_torrent(torrent_id, label_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
def post_torrent_remove(self, event):
|
def post_torrent_remove(self, torrent_id):
|
||||||
log.debug("post_torrent_remove")
|
log.debug("post_torrent_remove")
|
||||||
if event.torrent_id in self.torrent_labels:
|
if torrent_id in self.torrent_labels:
|
||||||
del self.torrent_labels[event.torrent_id]
|
del self.torrent_labels[torrent_id]
|
||||||
|
|
||||||
## Utils ##
|
## Utils ##
|
||||||
def clean_config(self):
|
def clean_config(self):
|
||||||
|
|
|
@ -188,9 +188,9 @@ Subject: %(subject)s
|
||||||
return _("Notification email sent.")
|
return _("Notification email sent.")
|
||||||
|
|
||||||
|
|
||||||
def _on_torrent_finished_event(self, event):
|
def _on_torrent_finished_event(self, torrent_id):
|
||||||
log.debug("Handler for TorrentFinishedEvent called for CORE")
|
log.debug("Handler for TorrentFinishedEvent called for CORE")
|
||||||
torrent = component.get("TorrentManager")[event.torrent_id]
|
torrent = component.get("TorrentManager")[torrent_id]
|
||||||
torrent_status = torrent.get_status({})
|
torrent_status = torrent.get_status({})
|
||||||
# Email
|
# Email
|
||||||
subject = _("Finished Torrent \"%(name)s\"") % torrent_status
|
subject = _("Finished Torrent \"%(name)s\"") % torrent_status
|
||||||
|
|
|
@ -76,12 +76,11 @@ class SchedulerEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a schedule state changes.
|
Emitted when a schedule state changes.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('colour',)
|
|
||||||
def __init__(self, colour):
|
def __init__(self, colour):
|
||||||
"""
|
"""
|
||||||
:param colour: str, the current scheduler state
|
:param colour: str, the current scheduler state
|
||||||
"""
|
"""
|
||||||
self.colour = colour
|
self._args = [colour]
|
||||||
|
|
||||||
class Core(CorePluginBase):
|
class Core(CorePluginBase):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
|
@ -120,8 +119,8 @@ class Core(CorePluginBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def on_config_value_changed(self, event):
|
def on_config_value_changed(self, key, value):
|
||||||
if event.key in CONTROLLED_SETTINGS:
|
if key in CONTROLLED_SETTINGS:
|
||||||
self.do_schedule(False)
|
self.do_schedule(False)
|
||||||
|
|
||||||
def __apply_set_functions(self):
|
def __apply_set_functions(self):
|
||||||
|
|
|
@ -203,9 +203,9 @@ class GtkUI(GtkPluginBase):
|
||||||
|
|
||||||
client.scheduler.get_config().addCallback(on_get_config)
|
client.scheduler.get_config().addCallback(on_get_config)
|
||||||
|
|
||||||
def on_scheduler_event(self, event):
|
def on_scheduler_event(self, state):
|
||||||
def on_state_deferred(s):
|
def on_state_deferred(s):
|
||||||
self.status_item.set_image_from_file(get_resource(event.colour.lower() + ".png"))
|
self.status_item.set_image_from_file(get_resource(state.lower() + ".png"))
|
||||||
|
|
||||||
self.state_deferred.addCallback(on_state_deferred)
|
self.state_deferred.addCallback(on_state_deferred)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue