From 59d8fc9a14ca5aa82bc53c498036ea069cb127a1 Mon Sep 17 00:00:00 2001 From: bendikro Date: Mon, 31 Oct 2016 19:54:10 +0100 Subject: [PATCH] [Lint] Fix pylint warnings --- deluge/core/pluginmanager.py | 2 +- deluge/core/torrent.py | 3 ++- deluge/core/torrentmanager.py | 8 ++++---- deluge/pluginmanagerbase.py | 5 +++-- deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py | 4 ++-- .../Notifications/deluge/plugins/notifications/core.py | 5 ++++- deluge/ui/gtkui/ipcinterface.py | 2 +- deluge/ui/gtkui/listview.py | 2 +- deluge/ui/gtkui/peers_tab.py | 2 +- deluge/ui/gtkui/preferences.py | 10 +++++----- gen_web_gettext.py | 2 +- 11 files changed, 25 insertions(+), 20 deletions(-) diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index 8f82d362f..9c1e530dc 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -46,7 +46,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Compon self.stop() def update_plugins(self): - for plugin in self.plugins.keys(): + for plugin in self.plugins: if hasattr(self.plugins[plugin], "update"): try: self.plugins[plugin].update() diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index bed757502..bbc0ac177 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -1354,7 +1354,8 @@ class Torrent(object): If the key is no longer valid, the dict will be deleted. """ - for key in self.prev_status.keys(): + # Dict will be modified so iterate over generated list + for key in list(self.prev_status): if not self.rpcserver.is_session_valid(key): del self.prev_status[key] diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index e9f77ac91..6f5458f2d 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -921,25 +921,25 @@ class TorrentManager(component.Component): def on_set_max_connections_per_torrent(self, key, value): """Sets the per-torrent connection limit""" log.debug("max_connections_per_torrent set to %s...", value) - for key in self.torrents.keys(): + for key in self.torrents: self.torrents[key].set_max_connections(value) def on_set_max_upload_slots_per_torrent(self, key, value): """Sets the per-torrent upload slot limit""" log.debug("max_upload_slots_per_torrent set to %s...", value) - for key in self.torrents.keys(): + for key in self.torrents: self.torrents[key].set_max_upload_slots(value) def on_set_max_upload_speed_per_torrent(self, key, value): """Sets the per-torrent upload speed limit""" log.debug("max_upload_speed_per_torrent set to %s...", value) - for key in self.torrents.keys(): + for key in self.torrents: self.torrents[key].set_max_upload_speed(value) def on_set_max_download_speed_per_torrent(self, key, value): """Sets the per-torrent download speed limit""" log.debug("max_download_speed_per_torrent set to %s...", value) - for key in self.torrents.keys(): + for key in self.torrents: self.torrents[key].set_max_download_speed(value) # --- Alert handlers --- diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index d600e122f..25f1d6e0d 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -73,8 +73,9 @@ class PluginManagerBase(object): self.enable_plugin(name) def disable_plugins(self): - # Disable all plugins that are enabled - for key in self.plugins.keys(): + """Disable all plugins that are enabled""" + # Dict will be modified so iterate over generated list + for key in list(self.plugins): self.disable_plugin(key) def __getitem__(self, key): diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py index f94588b7c..8902dd018 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py @@ -131,7 +131,7 @@ class Core(CorePluginBase): for w_id, w in self.watchdirs.iteritems(): if options["abspath"] == w["abspath"] and watchdir_id != w_id: raise Exception("Path is already being watched.") - for key in options.keys(): + for key in options: if key not in OPTIONS_AVAILABLE: if key not in [key2 + "_toggle" for key2 in OPTIONS_AVAILABLE.iterkeys()]: raise Exception("autoadd: Invalid options key:%s" % key) @@ -360,7 +360,7 @@ class Core(CorePluginBase): def set_config(self, config): """Sets the config dictionary.""" config = self._make_unicode(config) - for key in config.keys(): + for key in config: self.config[key] = config[key] self.config.save() component.get("EventManager").emit(AutoaddOptionsChangedEvent()) diff --git a/deluge/plugins/Notifications/deluge/plugins/notifications/core.py b/deluge/plugins/Notifications/deluge/plugins/notifications/core.py index 45fe7f2e0..3af5d4b7d 100644 --- a/deluge/plugins/Notifications/deluge/plugins/notifications/core.py +++ b/deluge/plugins/Notifications/deluge/plugins/notifications/core.py @@ -46,6 +46,9 @@ DEFAULT_PREFS = { class CoreNotifications(CustomNotifications): + def __init__(self, plugin_name=None): + CustomNotifications.__init__(self, plugin_name) + def enable(self): CustomNotifications.enable(self) self.register_custom_email_notification('TorrentFinishedEvent', @@ -80,7 +83,7 @@ class CoreNotifications(CustomNotifications): def get_handled_events(self): handled_events = [] - for evt in sorted(known_events.keys()): + for evt in sorted(known_events): if known_events[evt].__module__.startswith('deluge.event'): if evt not in ('TorrentFinishedEvent',): # Skip all un-handled built-in events diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index 0d7a446f6..22eaa7a23 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -28,7 +28,7 @@ from deluge.ui.client import client try: import rencode except ImportError: - import deluge.rencode as rencode + import deluge.rencode as rencode # pylint: disable=ungrouped-imports log = logging.getLogger(__name__) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 4f5ee726f..004560973 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -303,7 +303,7 @@ class ListView(object): def get_state_field_column(self, field): """Returns the column number for the state field""" - for column in self.columns.keys(): + for column in self.columns: if self.columns[column].status_field is None: continue diff --git a/deluge/ui/gtkui/peers_tab.py b/deluge/ui/gtkui/peers_tab.py index e8044c31e..0fbbcc1bd 100644 --- a/deluge/ui/gtkui/peers_tab.py +++ b/deluge/ui/gtkui/peers_tab.py @@ -296,7 +296,7 @@ class PeersTab(Tab): self.peers[peer["ip"]] = row # Now we need to remove any ips that were not in status["peers"] list - for ip in set(self.peers.keys()).difference(new_ips): + for ip in set(self.peers).difference(new_ips): self.liststore.remove(self.peers[ip]) del self.peers[ip] diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 420003721..8557003fb 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -398,7 +398,7 @@ class Preferences(component.Component): core_widgets[self.copy_torrent_files_path_chooser] = ("path_chooser", "torrentfiles_location") # Update the widgets accordingly - for key in core_widgets.keys(): + for key in core_widgets: modifier = core_widgets[key][0] if isinstance(key, str): widget = self.builder.get_object(key) @@ -431,7 +431,7 @@ class Preferences(component.Component): widget.set_text(value, cursor_end=False, default_text=True) if self.is_connected: - for key in core_widgets.keys(): + for key in core_widgets: if isinstance(key, str): widget = self.builder.get_object(key) else: @@ -671,7 +671,7 @@ class Preferences(component.Component): dialog.run() # GtkUI - for key in new_gtkui_config.keys(): + for key in new_gtkui_config: # The values do not match so this needs to be updated if self.gtkui_config[key] != new_gtkui_config[key]: self.gtkui_config[key] = new_gtkui_config[key] @@ -680,7 +680,7 @@ class Preferences(component.Component): if client.connected(): # Only do this if we're connected to a daemon config_to_set = {} - for key in new_core_config.keys(): + for key in new_core_config: # The values do not match so this needs to be updated if self.core_config[key] != new_core_config[key]: config_to_set[key] = new_core_config[key] @@ -806,7 +806,7 @@ class Preferences(component.Component): if dep in dependents: update_dependent_widgets(dep, depwidget.get_active() and sensitive) - for key in dependents.keys(): + for key in dependents: if widget != self.builder.get_object(key): continue update_dependent_widgets(key, value) diff --git a/gen_web_gettext.py b/gen_web_gettext.py index 519edf7bd..69dd91d8e 100755 --- a/gen_web_gettext.py +++ b/gen_web_gettext.py @@ -89,7 +89,7 @@ def create_gettext_js(js_dir): gettext_file = os.path.join(os.path.dirname(js_dir), 'gettext.js') with open(gettext_file, 'w') as fp: fp.write(gettext_tpl) - for key in sorted(strings.keys()): + for key in sorted(strings): if DEBUG: fp.write('\n// %s\n' % ', '.join(['%s:%s' % x for x in strings[key]])) fp.write('''GetText.add('%(key)s','${escape(_("%(key)s"))}')\n''' % locals())