From 23ba57313ada79e0bab9e33439826dc6926b7199 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 2 Nov 2016 19:17:00 +0000 Subject: [PATCH] [Core] Support new libtorrent 1.1 alert and status attributes * Keep deprecated lt attribute support for the interim. --- deluge/core/torrent.py | 11 ++++++++--- deluge/core/torrentmanager.py | 22 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 8b97abc31..bed757502 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -623,15 +623,20 @@ class Torrent(object): session_paused = component.get("Core").session.is_paused() old_state = self.state self.set_status_message() + try: + status_error = status.errc + except AttributeError: + # Deprecated in libtorrent 1.1 + status_error = status.error if self.forced_error: self.state = "Error" self.set_status_message(self.forced_error.error_message) - elif status.error: + elif status_error: self.state = "Error" # auto-manage status will be reverted upon resuming. self.handle.auto_managed(False) - self.set_status_message(decode_string(status.error)) + self.set_status_message(decode_string(status_error)) elif self.moving_storage: self.state = "Moving" elif not session_paused and status.paused and status.auto_managed: @@ -646,7 +651,7 @@ class Torrent(object): if log.isEnabledFor(logging.DEBUG): log.debug("State from lt was: %s | Session is paused: %s\nTorrent state set from '%s' to '%s' (%s)", - "error" if status.error else status.state, session_paused, old_state, self.state, self.torrent_id) + "error" if status_error else status.state, session_paused, old_state, self.state, self.torrent_id) if self.forced_error: log.debug("Torrent Error state message: %s", self.forced_error.error_message) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 434d51275..e9f77ac91 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -1062,7 +1062,11 @@ class TorrentManager(component.Component): def on_alert_tracker_error(self, alert): """Alert handler for libtorrent tracker_error_alert""" - error_message = decode_string(alert.msg) + try: + error_message = decode_string(alert.error_message) + except AttributeError: + # Deprecated in libtorrent 1.1 + error_message = decode_string(alert.msg) # If alert.msg is empty then it's a '-1' code so fallback to a.e.message. Note that alert.msg # cannot be replaced by a.e.message because the code is included in the string (for non-'-1'). if not error_message: @@ -1083,7 +1087,12 @@ class TorrentManager(component.Component): torrent = self.torrents[torrent_id] except (RuntimeError, KeyError): return - torrent.set_download_location(os.path.normpath(alert.handle.save_path())) + try: + storage_path = os.path.normpath(alert.storage_path) + except AttributeError: + # Deprecated in libtorrent 1.1 + storage_path = os.path.normpath(alert.handle.save_path()) + torrent.set_download_location(storage_path) torrent.set_move_completed(False) torrent.moving_storage = False torrent.update_state() @@ -1196,7 +1205,12 @@ class TorrentManager(component.Component): """ log.debug("on_alert_file_renamed") - log.debug("index: %s name: %s", alert.index, decode_string(alert.name)) + try: + new_name = decode_string(alert.new_name) + except AttributeError: + # Deprecated in libtorrent 1.1 + new_name = decode_string(alert.name) + log.debug("index: %s name: %s", alert.index, new_name) try: torrent_id = str(alert.handle.info_hash()) torrent = self.torrents[torrent_id] @@ -1210,7 +1224,7 @@ class TorrentManager(component.Component): break else: # This is just a regular file rename so send the signal - component.get("EventManager").emit(TorrentFileRenamedEvent(torrent_id, alert.index, alert.name)) + component.get("EventManager").emit(TorrentFileRenamedEvent(torrent_id, alert.index, new_name)) self.save_resume_data((torrent_id,)) def on_alert_metadata_received(self, alert):