Skip to content

Commit 93d03e0

Browse files
committed
Merge branch 'main'
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2 parents f358194 + 78994e6 commit 93d03e0

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/extractcode/libarchive2.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import logging
1313
import mmap
1414
import os
15+
import warnings
1516

17+
import ctypes.util
1618
from ctypes import c_char_p, c_wchar_p
1719
from ctypes import c_int, c_longlong
1820
from ctypes import c_size_t, c_ssize_t
@@ -77,6 +79,8 @@
7779

7880
EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR = 'EXTRACTCODE_LIBARCHIVE_PATH'
7981

82+
_LIBRARY_NAME = 'libarchive'
83+
8084

8185
def load_lib():
8286
"""
@@ -95,17 +99,35 @@ def load_lib():
9599
if not dll_loc:
96100
dll_loc = get_location(EXTRACTCODE_LIBARCHIVE_DLL)
97101

102+
# try the standard locations with find_library
103+
if not dll_loc:
104+
libarch_loc = ctypes.util.find_library(_LIBRARY_NAME)
105+
libarchive = ctypes.cdll.LoadLibrary(libarch_loc)
106+
if libarchive:
107+
warnings.warn(
108+
'Using "libarchive" library found in a system location. '
109+
'Install instead a extractcode-libarchive plugin for best support.'
110+
)
111+
return libarchive
112+
98113
# try the PATH
99114
if not dll_loc:
100115
dll = 'libarchive.dll' if on_windows else 'libarchive.so'
101116
dll_loc = command.find_in_path(dll)
117+
if dll_loc:
118+
warnings.warn(
119+
'Using "libarchive" library found in the PATH. '
120+
'Install instead a extractcode-libarchive plugin for best support.'
121+
)
102122

103123
if not dll_loc or not os.path.isfile(dll_loc):
104124
raise Exception(
105125
'CRITICAL: libarchive DLL is not installed. '
106126
'Unable to continue: you need to install a valid extractcode-libarchive '
107127
'plugin with a valid libarchive DLL available. '
108-
f'OR set the {EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR} environment variable.'
128+
f'OR set the {EXTRACTCODE_LIBARCHIVE_PATH_ENVVAR} environment variable. '
129+
'OR install libarchive as a system package. '
130+
'OR ensure libarchive is available in the system PATH.'
109131
)
110132
return command.load_shared_library(dll_loc)
111133

src/extractcode/sevenzip.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10-
from collections import defaultdict
1110
import io
1211
import logging
1312
import os
1413
import pprint
1514
import re
15+
import warnings
16+
17+
from collections import defaultdict
18+
from shlex import quote as shlex_quote
19+
from shutil import which
1620

1721
import attr
1822

@@ -28,8 +32,6 @@
2832
from extractcode import ExtractErrorFailedToExtract
2933
from extractcode import ExtractWarningIncorrectEntry
3034

31-
from shlex import quote as shlex_quote
32-
3335
"""
3436
Low level support for p/7zip-based archive extraction.
3537
"""
@@ -86,12 +88,23 @@ def get_command_location(_cache=[]):
8688
cmd = '7z.exe' if on_windows else '7z'
8789
cmd_loc = command.find_in_path(cmd)
8890

91+
if not cmd_loc:
92+
cmd_loc = which(cmd)
93+
94+
if cmd_loc:
95+
warnings.warn(
96+
'Using "7z" 7zip command found in the PATH. '
97+
'Install instead a extractcode-7z plugin for best support.'
98+
)
99+
89100
if not cmd_loc or not os.path.isfile(cmd_loc):
90101
raise Exception(
91102
'CRITICAL: 7zip executable is not installed. '
92103
'Unable to continue: you need to install a valid extractcode-7z '
93104
'plugin with a valid executable available. '
94-
'OR set the EXTRACTCODE_7ZIP_PATH environment variable.'
105+
f'OR set the {EXTRACTCODE_7ZIP_PATH_ENVVAR} environment variable. '
106+
'OR install 7zip as a system package. '
107+
'OR ensure 7zip is available in the system PATH.'
95108
)
96109
_cache.append(cmd_loc)
97110
return cmd_loc

0 commit comments

Comments
 (0)