From 3519f341d474b09f7c0660724e4f6b970e8a6a7c Mon Sep 17 00:00:00 2001 From: bendikro Date: Tue, 5 Nov 2019 01:48:17 +0100 Subject: [PATCH] [GTK] Fix showing correct error on libtorrent import error The exception string "No module named libtorrent" was changed to "No module named 'libtorrent'" in python 3.3, which results in a "unknown Import Error" message being displayed instead of the message meant for libtorrent import error. Change to raising LibtorrentImportError in _libtorrent.py and catch this error to display libtorrent specific import errors. --- deluge/_libtorrent.py | 9 +++++++-- deluge/error.py | 4 ++++ deluge/ui/gtk3/gtkui.py | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/deluge/_libtorrent.py b/deluge/_libtorrent.py index f155feedb..0020184e5 100644 --- a/deluge/_libtorrent.py +++ b/deluge/_libtorrent.py @@ -18,16 +18,21 @@ Example: from __future__ import unicode_literals from deluge.common import VersionSplit, get_version +from deluge.error import LibtorrentImportError try: import deluge.libtorrent as lt except ImportError: - import libtorrent as lt + try: + import libtorrent as lt + except ImportError as ex: + raise LibtorrentImportError('No libtorrent library found: %s' % (ex)) + REQUIRED_VERSION = '1.1.2.0' LT_VERSION = lt.__version__ if VersionSplit(LT_VERSION) < VersionSplit(REQUIRED_VERSION): - raise ImportError( + raise LibtorrentImportError( 'Deluge %s requires libtorrent >= %s' % (get_version(), REQUIRED_VERSION) ) diff --git a/deluge/error.py b/deluge/error.py index 8705fdfe6..46e8e0cf1 100644 --- a/deluge/error.py +++ b/deluge/error.py @@ -94,3 +94,7 @@ class AuthenticationRequired(_UsernameBasedPasstroughError): class AuthManagerError(_UsernameBasedPasstroughError): pass + + +class LibtorrentImportError(ImportError): + pass diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index d93bd2e9a..47e889c6e 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -45,7 +45,7 @@ from deluge.common import ( windows_check, ) from deluge.configmanager import ConfigManager, get_config_dir -from deluge.error import DaemonRunningError +from deluge.error import DaemonRunningError, LibtorrentImportError from deluge.i18n import I18N_DOMAIN, set_language, setup_translation from deluge.ui.client import client from deluge.ui.hostlist import LOCALHOST @@ -313,8 +313,8 @@ class GtkUI(object): 'A Deluge daemon (deluged) is already running.\n' 'To use Standalone mode, stop local daemon and restart Deluge.' ) - except ImportError as ex: - if 'No module named libtorrent' in str(ex): + except LibtorrentImportError as ex: + if 'libtorrent library not found' in str(ex): err_msg = _( 'Only Thin Client mode is available because libtorrent is not installed.\n' 'To use Standalone mode, please install libtorrent package.' @@ -322,9 +322,17 @@ class GtkUI(object): else: log.exception(ex) err_msg = _( - 'Only Thin Client mode is available due to unknown Import Error.\n' + 'Only Thin Client mode is available due to libtorrent import error: %s\n' 'To use Standalone mode, please see logs for error details.' + % (str(ex)) ) + + except ImportError as ex: + log.exception(ex) + err_msg = _( + 'Only Thin Client mode is available due to unknown Import Error.\n' + 'To use Standalone mode, please see logs for error details.' + ) except Exception as ex: log.exception(ex) err_msg = _(