From d395bd510fa4f4376dc5237ab2f8d190a920d35d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 19 Feb 2023 16:05:49 +0100 Subject: Adding upstream version 2.1.1. Signed-off-by: Daniel Baumann --- deluge/plugins/AutoAdd/deluge_autoadd/__init__.py | 9 +-- deluge/plugins/AutoAdd/deluge_autoadd/common.py | 3 - deluge/plugins/AutoAdd/deluge_autoadd/core.py | 35 ++++++---- .../plugins/AutoAdd/deluge_autoadd/data/autoadd.js | 79 +++++++++------------- .../AutoAdd/deluge_autoadd/data/autoadd_options.js | 69 +++++++++---------- .../AutoAdd/deluge_autoadd/data/autoadd_options.ui | 20 ------ .../data/autoadd_options/main_tab.js | 14 ++-- .../data/autoadd_options/options_tab.js | 12 ++-- deluge/plugins/AutoAdd/deluge_autoadd/gtkui.py | 10 +-- deluge/plugins/AutoAdd/deluge_autoadd/webui.py | 3 - deluge/plugins/AutoAdd/setup.py | 1 - 11 files changed, 105 insertions(+), 150 deletions(-) (limited to 'deluge/plugins/AutoAdd') diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/__init__.py b/deluge/plugins/AutoAdd/deluge_autoadd/__init__.py index a409cfc..5f5e766 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/__init__.py +++ b/deluge/plugins/AutoAdd/deluge_autoadd/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -12,8 +11,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - from deluge.plugins.init import PluginInitBase @@ -22,7 +19,7 @@ class CorePlugin(PluginInitBase): from .core import Core as _pluginCls self._plugin_cls = _pluginCls - super(CorePlugin, self).__init__(plugin_name) + super().__init__(plugin_name) class Gtk3UIPlugin(PluginInitBase): @@ -30,7 +27,7 @@ class Gtk3UIPlugin(PluginInitBase): from .gtkui import GtkUI as _pluginCls self._plugin_cls = _pluginCls - super(Gtk3UIPlugin, self).__init__(plugin_name) + super().__init__(plugin_name) class WebUIPlugin(PluginInitBase): @@ -38,4 +35,4 @@ class WebUIPlugin(PluginInitBase): from .webui import WebUI as _pluginCls self._plugin_cls = _pluginCls - super(WebUIPlugin, self).__init__(plugin_name) + super().__init__(plugin_name) diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/common.py b/deluge/plugins/AutoAdd/deluge_autoadd/common.py index 9b4b1e7..6a790cb 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/common.py +++ b/deluge/plugins/AutoAdd/deluge_autoadd/common.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Basic plugin template created by: # Copyright (C) 2008 Martijn Voncken @@ -12,8 +11,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import os.path from pkg_resources import resource_filename diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/core.py b/deluge/plugins/AutoAdd/deluge_autoadd/core.py index 79e5327..07ad53a 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/core.py +++ b/deluge/plugins/AutoAdd/deluge_autoadd/core.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # Copyright (C) 2011 Pedro Algarvio @@ -13,22 +12,22 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os import shutil from base64 import b64encode from twisted.internet import reactor +from twisted.internet.defer import maybeDeferred from twisted.internet.task import LoopingCall, deferLater +from twisted.python.failure import Failure import deluge.component as component import deluge.configmanager from deluge._libtorrent import lt from deluge.common import AUTH_LEVEL_ADMIN, is_magnet from deluge.core.rpcserver import export -from deluge.error import AddTorrentError +from deluge.error import AddTorrentError, InvalidTorrentError from deluge.event import DelugeEvent from deluge.plugins.pluginbase import CorePluginBase @@ -150,7 +149,7 @@ class Core(CorePluginBase): try: with open(filename, file_mode) as _file: filedump = _file.read() - except IOError as ex: + except OSError as ex: log.warning('Unable to open %s: %s', filename, ex) raise ex @@ -159,7 +158,10 @@ class Core(CorePluginBase): # Get the info to see if any exceptions are raised if not magnet: - lt.torrent_info(lt.bdecode(filedump)) + decoded_torrent = lt.bdecode(filedump) + if decoded_torrent is None: + raise InvalidTorrentError('Torrent file failed decoding.') + lt.torrent_info(decoded_torrent) return filedump @@ -167,9 +169,9 @@ class Core(CorePluginBase): log.debug('Attempting to open %s for splitting magnets.', filename) magnets = [] try: - with open(filename, 'r') as _file: + with open(filename) as _file: magnets = list(filter(len, _file.read().splitlines())) - except IOError as ex: + except OSError as ex: log.warning('Unable to open %s: %s', filename, ex) if len(magnets) < 2: @@ -194,7 +196,7 @@ class Core(CorePluginBase): try: with open(mname, 'w') as _mfile: _mfile.write(magnet) - except IOError as ex: + except OSError as ex: log.warning('Unable to open %s: %s', mname, ex) return magnets @@ -269,7 +271,7 @@ class Core(CorePluginBase): try: filedump = self.load_torrent(filepath, magnet) - except (IOError, EOFError) as ex: + except (OSError, EOFError, InvalidTorrentError) as ex: # If torrent is invalid, keep track of it so can try again on the next pass. # This catches torrent files that may not be fully saved to disk at load time. log.debug('Torrent is invalid: %s', ex) @@ -325,6 +327,9 @@ class Core(CorePluginBase): os.remove(filepath) def fail_torrent_add(err_msg, filepath, magnet): + if isinstance(err_msg, Failure): + err_msg = err_msg.getErrorMessage() + # torrent handle is invalid and so is the magnet link log.error( 'Cannot Autoadd %s: %s: %s', @@ -337,15 +342,17 @@ class Core(CorePluginBase): try: # The torrent looks good, so lets add it to the session. if magnet: - d = component.get('Core').add_torrent_magnet( - filedump.strip(), options + d = maybeDeferred( + component.get('Core').add_torrent_magnet, + filedump.strip(), + options, ) else: d = component.get('Core').add_torrent_file_async( filename, b64encode(filedump), options ) - d.addCallback(on_torrent_added, filename, filepath) - d.addErrback(fail_torrent_add, filepath, magnet) + d.addCallback(on_torrent_added, filename, filepath) + d.addErrback(fail_torrent_add, filepath, magnet) except AddTorrentError as ex: fail_torrent_add(str(ex), filepath, magnet) diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd.js b/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd.js index 40086b3..e68fce3 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd.js +++ b/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd.js @@ -25,7 +25,7 @@ Deluge.ux.preferences.AutoAddPage = Ext.extend(Ext.Panel, { border: false, watchdirs: {}, - initComponent: function() { + initComponent: function () { Deluge.ux.preferences.AutoAddPage.superclass.initComponent.call(this); var autoAdd = this; @@ -41,23 +41,22 @@ Deluge.ux.preferences.AutoAddPage = Ext.extend(Ext.Panel, { sortable: true, dataIndex: 'enabled', tpl: new Ext.XTemplate('{enabled:this.getCheckbox}', { - getCheckbox: function(checked, selected) { - Deluge.ux.AutoAdd.onClickFunctions[ - selected.id - ] = function() { - if (selected.enabled) { - deluge.client.autoadd.disable_watchdir( - selected.id - ); - checked = false; - } else { - deluge.client.autoadd.enable_watchdir( - selected.id - ); - checked = true; - } - autoAdd.updateWatchDirs(); - }; + getCheckbox: function (checked, selected) { + Deluge.ux.AutoAdd.onClickFunctions[selected.id] = + function () { + if (selected.enabled) { + deluge.client.autoadd.disable_watchdir( + selected.id + ); + checked = false; + } else { + deluge.client.autoadd.enable_watchdir( + selected.id + ); + checked = true; + } + autoAdd.updateWatchDirs(); + }; return ( 'If a .torrent file is added to this directory, it will be added to the session. - False - False True @@ -284,8 +282,6 @@ and it will remain in the same directory. True .added - False - False True @@ -329,8 +325,6 @@ and deleted from the watch folder. True True - False - False True @@ -445,8 +439,6 @@ also delete the .torrent file used to add it. True True - False - False True @@ -534,8 +526,6 @@ also delete the .torrent file used to add it. True True - False - False True @@ -799,8 +789,6 @@ also delete the .torrent file used to add it. True True - False - False adjustment1 1 1 @@ -815,8 +803,6 @@ also delete the .torrent file used to add it. True True - False - False adjustment2 1 1 @@ -833,8 +819,6 @@ also delete the .torrent file used to add it. True True - False - False adjustment3 1 @@ -850,8 +834,6 @@ also delete the .torrent file used to add it. True True - False - False adjustment4 1 @@ -1063,8 +1045,6 @@ also delete the .torrent file used to add it. True True - False - False adjustment5 1 1 diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/main_tab.js b/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/main_tab.js index 79d2600..f685ff2 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/main_tab.js +++ b/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/main_tab.js @@ -19,7 +19,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { id: 'main_tab_panel', title: _('Main'), - initComponent: function() { + initComponent: function () { Deluge.ux.AutoAdd.AutoAddMainPanel.superclass.initComponent.call(this); this.watchFolderFset = new Ext.form.FieldSet({ xtype: 'fieldset', @@ -69,7 +69,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { checked: true, hideLabel: true, listeners: { - check: function(cb, newValue) { + check: function (cb, newValue) { if (newValue) { Ext.getCmp( 'append_extension' @@ -98,7 +98,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { ), hideLabel: true, listeners: { - check: function(cb, newValue) { + check: function (cb, newValue) { if (newValue) { Ext.getCmp( 'append_extension' @@ -141,7 +141,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { ), hideLabel: true, listeners: { - check: function(cb, newValue) { + check: function (cb, newValue) { if (newValue) { Ext.getCmp( 'append_extension' @@ -201,7 +201,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { xtype: 'checkbox', boxLabel: _('Set download folder'), listeners: { - check: function(cb, checked) { + check: function (cb, checked) { Ext.getCmp('download_location').setDisabled( !checked ); @@ -233,7 +233,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { xtype: 'checkbox', boxLabel: _('Set move completed folder'), listeners: { - check: function(cb, checked) { + check: function (cb, checked) { Ext.getCmp('move_completed_path').setDisabled( !checked ); @@ -271,7 +271,7 @@ Deluge.ux.AutoAdd.AutoAddMainPanel = Ext.extend(Ext.Panel, { xtype: 'checkbox', boxLabel: _('Label:'), listeners: { - check: function(cb, checked) { + check: function (cb, checked) { Ext.getCmp('label').setDisabled(!checked); }, }, diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/options_tab.js b/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/options_tab.js index a69490c..4ce030e 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/options_tab.js +++ b/deluge/plugins/AutoAdd/deluge_autoadd/data/autoadd_options/options_tab.js @@ -19,7 +19,7 @@ Deluge.ux.AutoAdd.AutoAddOptionsPanel = Ext.extend(Ext.Panel, { id: 'options_tab_panel', title: _('Options'), - initComponent: function() { + initComponent: function () { Deluge.ux.AutoAdd.AutoAddOptionsPanel.superclass.initComponent.call( this ); @@ -149,7 +149,7 @@ Deluge.ux.AutoAdd.AutoAddOptionsPanel = Ext.extend(Ext.Panel, { hideLabel: true, width: 175, listeners: { - check: function(cb, checked) { + check: function (cb, checked) { Ext.getCmp('stop_ratio').setDisabled( !checked ); @@ -223,7 +223,7 @@ Deluge.ux.AutoAdd.AutoAddOptionsPanel = Ext.extend(Ext.Panel, { this.add([this.ownerFset, this.bandwidthFset, this.queueFset]); }, - _getBandwidthContainer: function(values) { + _getBandwidthContainer: function (values) { return new Ext.Container({ xtype: 'container', layout: 'hbox', @@ -236,7 +236,7 @@ Deluge.ux.AutoAdd.AutoAddOptionsPanel = Ext.extend(Ext.Panel, { boxLabel: _(values.labelCheckbox), width: 175, listeners: { - check: function(cb, checked) { + check: function (cb, checked) { Ext.getCmp(values.idSpinner).setDisabled(!checked); }, }, @@ -257,7 +257,7 @@ Deluge.ux.AutoAdd.AutoAddOptionsPanel = Ext.extend(Ext.Panel, { }); }, - _getQueueContainer: function(values) { + _getQueueContainer: function (values) { return new Ext.Container({ xtype: 'container', layout: 'hbox', @@ -270,7 +270,7 @@ Deluge.ux.AutoAdd.AutoAddOptionsPanel = Ext.extend(Ext.Panel, { boxLabel: _(values.labelCheckbox), width: 175, listeners: { - check: function(cb, checked) { + check: function (cb, checked) { Ext.getCmp(values.nameRadio).setDisabled(!checked); Ext.getCmp('not_' + values.nameRadio).setDisabled( !checked diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/gtkui.py b/deluge/plugins/AutoAdd/deluge_autoadd/gtkui.py index 16f0f7a..80fb9fc 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/gtkui.py +++ b/deluge/plugins/AutoAdd/deluge_autoadd/gtkui.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -12,14 +11,12 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os import gi # isort:skip (Required before Gtk import). -gi.require_version('Gtk', '3.0') # NOQA: E402 +gi.require_version('Gtk', '3.0') # isort:imports-thirdparty from gi.repository import Gtk @@ -41,7 +38,7 @@ class IncompatibleOption(Exception): pass -class OptionsDialog(object): +class OptionsDialog: spin_ids = ['max_download_speed', 'max_upload_speed', 'stop_ratio'] spin_int_ids = ['max_upload_slots', 'max_connections'] chk_ids = [ @@ -327,7 +324,7 @@ class OptionsDialog(object): dialogs.ErrorDialog(_('Incompatible Option'), str(ex), self.dialog).run() def on_error_show(self, result): - d = dialogs.ErrorDialog(_('Error'), result.value.exception_msg, self.dialog) + d = dialogs.ErrorDialog(_('Error'), result.value.message, self.dialog) result.cleanFailure() d.run() @@ -453,7 +450,6 @@ class GtkUI(Gtk3PluginBase): self.treeView = Gtk.TreeView(self.store) self.treeView.connect('cursor-changed', self.on_listitem_activated) self.treeView.connect('row-activated', self.on_edit_button_clicked) - self.treeView.set_rules_hint(True) self.create_columns(self.treeView) sw.add(self.treeView) diff --git a/deluge/plugins/AutoAdd/deluge_autoadd/webui.py b/deluge/plugins/AutoAdd/deluge_autoadd/webui.py index 7f36ba6..d328432 100644 --- a/deluge/plugins/AutoAdd/deluge_autoadd/webui.py +++ b/deluge/plugins/AutoAdd/deluge_autoadd/webui.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # @@ -12,8 +11,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging from deluge.plugins.pluginbase import WebPluginBase diff --git a/deluge/plugins/AutoAdd/setup.py b/deluge/plugins/AutoAdd/setup.py index fcd0183..5a01ee9 100644 --- a/deluge/plugins/AutoAdd/setup.py +++ b/deluge/plugins/AutoAdd/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 GazpachoKing # Copyright (C) 2011 Pedro Algarvio -- cgit v1.2.3