diff --git a/src/extractcode/libarchive2.py b/src/extractcode/libarchive2.py index 70ab4f5..cedc4f2 100644 --- a/src/extractcode/libarchive2.py +++ b/src/extractcode/libarchive2.py @@ -24,6 +24,7 @@ import mmap import os +import ctypes.util from ctypes import c_char_p, c_wchar_p from ctypes import c_int, c_longlong from ctypes import c_size_t, c_ssize_t @@ -85,6 +86,7 @@ # keys for plugin-provided locations EXTRACTCODE_LIBARCHIVE_LIBDIR = 'extractcode.libarchive.libdir' EXTRACTCODE_LIBARCHIVE_DLL = 'extractcode.libarchive.dll' +_LIBRARY_NAME = 'libarchive' def load_lib(): @@ -96,11 +98,17 @@ def load_lib(): dll = get_location(EXTRACTCODE_LIBARCHIVE_DLL) libdir = get_location(EXTRACTCODE_LIBARCHIVE_LIBDIR) if not (dll and libdir) or not os.path.isfile(dll) or not os.path.isdir(libdir): - raise Exception( - 'CRITICAL: libarchive DLL is not installed. ' - 'Unable to continue: you need to install a valid extractcode-libarchive ' - 'plugin with a valid libarchive DLL available.' - ) + filepath = ctypes.util.find_library(_LIBRARY_NAME) + libarchive = ctypes.cdll.LoadLibrary(filepath) + if not libarchive: + raise ImportError( + 'CRITICAL: libarchive DLL is not installed. ' + 'Unable to continue: you need to install a valid extractcode-libarchive ' + 'plugin with a valid libarchive DLL available ' + 'or to have "libarchive" library installed in your system.' + ) + logger.warning('Cannot to use plugin for libarchive, defaulting to system library at ' + filepath) + return libarchive return command.load_shared_library(dll, libdir) diff --git a/src/extractcode/sevenzip.py b/src/extractcode/sevenzip.py index 777b5ed..8639bdc 100644 --- a/src/extractcode/sevenzip.py +++ b/src/extractcode/sevenzip.py @@ -24,6 +24,7 @@ import os import pprint import re +from shutil import which import attr @@ -80,11 +81,16 @@ def get_bin_locations(): cmd_loc = get_location(EXTRACTCODE_7ZIP_EXE) libdir = get_location(EXTRACTCODE_7ZIP_LIBDIR) if not (cmd_loc and libdir) or not os.path.isfile(cmd_loc) or not os.path.isdir(libdir): - raise Exception( - 'CRITICAL: 7zip executable is not installed. ' - 'Unable to continue: you need to install a valid extractcode-7z ' - 'plugin with a valid executable available.' - ) + sevenzip = which('7z') + if not sevenzip: + raise ImportError( + 'CRITICAL: 7zip executable is not installed. ' + 'Unable to continue: you need to install a valid extractcode-7z ' + 'plugin with a valid executable available ' + 'or install p7zip in your system, so that a "7z" program is available on your PATH' + ) + logger.warning('Cannot to use plugin for libarchive, defaulting to system binary at ' + sevenzip) + return '', sevenzip return libdir, cmd_loc