Skip to content

Commit 516485d

Browse files
committed
Improve error reporting with missing binaries
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent d151047 commit 516485d

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/extractcode/libarchive2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ def load_lib():
9393
"""
9494
from plugincode.location_provider import get_location
9595

96-
# get paths from plugins
9796
dll = get_location(EXTRACTCODE_LIBARCHIVE_DLL)
9897
libdir = get_location(EXTRACTCODE_LIBARCHIVE_LIBDIR)
98+
if not (dll and libdir) or not os.path.isfile(dll) or not os.path.isdir(libdir):
99+
raise Exception(
100+
'CRITICAL: libarchive DLL is not installed. '
101+
'Unable to continue: you need to install a valid extractcode-libarchive '
102+
'plugin with a valid libarchive DLL available.'
103+
)
99104
return command.load_shared_library(dll, libdir)
105+
100106

101107

102108
def set_env_with_tz():

src/extractcode/sevenzip.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#
32
# Copyright (c) nexB Inc. and others.
43
# SPDX-License-Identifier: Apache-2.0
@@ -73,6 +72,24 @@
7372
UNKNOWN_ERROR = 'Unknown extraction error'
7473

7574

75+
def get_bin_locations():
76+
"""
77+
Return a tuple of (lib_dir, cmd_loc) for 7zip loaded from plugin-provided path.
78+
"""
79+
from plugincode.location_provider import get_location
80+
81+
cmd_loc = get_location(EXTRACTCODE_7ZIP_EXE)
82+
libdir = get_location(EXTRACTCODE_7ZIP_LIBDIR)
83+
if not (cmd_loc and libdir) or not os.path.isfile(cmd_loc) or not os.path.isdir(libdir):
84+
raise Exception(
85+
'CRITICAL: 7zip executable is not installed. '
86+
'Unable to continue: you need to install a valid extractcode-7z '
87+
'plugin with a valid executable available.'
88+
)
89+
90+
return libdir, cmd_loc
91+
92+
7693
def get_7z_errors(stdout, stderr):
7794
"""
7895
Return error messages extracted from a 7zip command output `stdout` and
@@ -160,18 +177,6 @@ def is_rar(location):
160177
return T.filetype_file.lower().startswith('rar archive')
161178

162179

163-
def get_bin_locations():
164-
"""
165-
Return a tuple of (lib_dir, cmd_loc) for 7zip loaded from plugin-provided path.
166-
"""
167-
from plugincode.location_provider import get_location
168-
169-
# get paths from plugins
170-
lib_dir = get_location(EXTRACTCODE_7ZIP_LIBDIR)
171-
cmd_loc = get_location(EXTRACTCODE_7ZIP_EXE)
172-
return lib_dir, cmd_loc
173-
174-
175180
def extract(location, target_dir, arch_type='*', file_by_file=on_mac, skip_symlinks=True):
176181
"""
177182
Extract all files from a 7zip-supported archive file at location in the

0 commit comments

Comments
 (0)