[Core] Support new libtorrent 1.1 alert and status attributes

* Keep deprecated lt attribute support for the interim.
This commit is contained in:
Calum Lind 2016-11-02 19:17:00 +00:00
commit 23ba57313a
2 changed files with 26 additions and 7 deletions

View file

@ -623,15 +623,20 @@ class Torrent(object):
session_paused = component.get("Core").session.is_paused() session_paused = component.get("Core").session.is_paused()
old_state = self.state old_state = self.state
self.set_status_message() self.set_status_message()
try:
status_error = status.errc
except AttributeError:
# Deprecated in libtorrent 1.1
status_error = status.error
if self.forced_error: if self.forced_error:
self.state = "Error" self.state = "Error"
self.set_status_message(self.forced_error.error_message) self.set_status_message(self.forced_error.error_message)
elif status.error: elif status_error:
self.state = "Error" self.state = "Error"
# auto-manage status will be reverted upon resuming. # auto-manage status will be reverted upon resuming.
self.handle.auto_managed(False) 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: elif self.moving_storage:
self.state = "Moving" self.state = "Moving"
elif not session_paused and status.paused and status.auto_managed: elif not session_paused and status.paused and status.auto_managed:
@ -646,7 +651,7 @@ class Torrent(object):
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
log.debug("State from lt was: %s | Session is paused: %s\nTorrent state set from '%s' to '%s' (%s)", 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: if self.forced_error:
log.debug("Torrent Error state message: %s", self.forced_error.error_message) log.debug("Torrent Error state message: %s", self.forced_error.error_message)

View file

@ -1062,7 +1062,11 @@ class TorrentManager(component.Component):
def on_alert_tracker_error(self, alert): def on_alert_tracker_error(self, alert):
"""Alert handler for libtorrent tracker_error_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 # 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'). # cannot be replaced by a.e.message because the code is included in the string (for non-'-1').
if not error_message: if not error_message:
@ -1083,7 +1087,12 @@ class TorrentManager(component.Component):
torrent = self.torrents[torrent_id] torrent = self.torrents[torrent_id]
except (RuntimeError, KeyError): except (RuntimeError, KeyError):
return 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.set_move_completed(False)
torrent.moving_storage = False torrent.moving_storage = False
torrent.update_state() torrent.update_state()
@ -1196,7 +1205,12 @@ class TorrentManager(component.Component):
""" """
log.debug("on_alert_file_renamed") 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: try:
torrent_id = str(alert.handle.info_hash()) torrent_id = str(alert.handle.info_hash())
torrent = self.torrents[torrent_id] torrent = self.torrents[torrent_id]
@ -1210,7 +1224,7 @@ class TorrentManager(component.Component):
break break
else: else:
# This is just a regular file rename so send the signal # 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,)) self.save_resume_data((torrent_id,))
def on_alert_metadata_received(self, alert): def on_alert_metadata_received(self, alert):