[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.
This commit is contained in:
bendikro 2019-11-05 01:48:17 +01:00 committed by Calum Lind
commit 3519f341d4
3 changed files with 23 additions and 6 deletions

View file

@ -18,16 +18,21 @@ Example:
from __future__ import unicode_literals from __future__ import unicode_literals
from deluge.common import VersionSplit, get_version from deluge.common import VersionSplit, get_version
from deluge.error import LibtorrentImportError
try: try:
import deluge.libtorrent as lt import deluge.libtorrent as lt
except ImportError: 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' REQUIRED_VERSION = '1.1.2.0'
LT_VERSION = lt.__version__ LT_VERSION = lt.__version__
if VersionSplit(LT_VERSION) < VersionSplit(REQUIRED_VERSION): if VersionSplit(LT_VERSION) < VersionSplit(REQUIRED_VERSION):
raise ImportError( raise LibtorrentImportError(
'Deluge %s requires libtorrent >= %s' % (get_version(), REQUIRED_VERSION) 'Deluge %s requires libtorrent >= %s' % (get_version(), REQUIRED_VERSION)
) )

View file

@ -94,3 +94,7 @@ class AuthenticationRequired(_UsernameBasedPasstroughError):
class AuthManagerError(_UsernameBasedPasstroughError): class AuthManagerError(_UsernameBasedPasstroughError):
pass pass
class LibtorrentImportError(ImportError):
pass

View file

@ -45,7 +45,7 @@ from deluge.common import (
windows_check, windows_check,
) )
from deluge.configmanager import ConfigManager, get_config_dir 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.i18n import I18N_DOMAIN, set_language, setup_translation
from deluge.ui.client import client from deluge.ui.client import client
from deluge.ui.hostlist import LOCALHOST from deluge.ui.hostlist import LOCALHOST
@ -313,8 +313,8 @@ class GtkUI(object):
'A Deluge daemon (deluged) is already running.\n' 'A Deluge daemon (deluged) is already running.\n'
'To use Standalone mode, stop local daemon and restart Deluge.' 'To use Standalone mode, stop local daemon and restart Deluge.'
) )
except ImportError as ex: except LibtorrentImportError as ex:
if 'No module named libtorrent' in str(ex): if 'libtorrent library not found' in str(ex):
err_msg = _( err_msg = _(
'Only Thin Client mode is available because libtorrent is not installed.\n' 'Only Thin Client mode is available because libtorrent is not installed.\n'
'To use Standalone mode, please install libtorrent package.' 'To use Standalone mode, please install libtorrent package.'
@ -322,9 +322,17 @@ class GtkUI(object):
else: else:
log.exception(ex) log.exception(ex)
err_msg = _( 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.' '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: except Exception as ex:
log.exception(ex) log.exception(ex)
err_msg = _( err_msg = _(