Skip to content

Commit 42a870a

Browse files
7z-sys-provided: let user override paths
let the user override assumed paths via environment. lib_dir is probed first from LD_LIBRARY_PATH. 7z executable is expected at lib_dir/7z but if not existing the PATH variable is probed for the first best match. With this patch it possible to run scancode is buildsystems like YOCTO, which heaviily rely on overriding paths via environment to pick the correct implementation from the build workspace Signed-off-by: Konrad Weihmann <kweihmann@outlook.com>
1 parent 88e6154 commit 42a870a

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

  • builtins/extractcode_7z_system_provided/src/extractcode_7z

builtins/extractcode_7z_system_provided/src/extractcode_7z/__init__.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
import platform
12+
from os import environ
1213
from os import path
14+
from os import pathsep
1315

1416
from plugincode.location_provider import LocationProviderPlugin
1517

@@ -22,26 +24,34 @@ def get_locations(self):
2224
locations of the 7zip exe and shared libraries as installed on various
2325
Linux distros or on FreeBSD.
2426
"""
25-
mainstream_system = platform.system().lower()
26-
if mainstream_system == 'linux':
27-
distribution = platform.linux_distribution()[0].lower()
28-
debian_based_distro = ['ubuntu', 'mint', 'debian']
29-
rpm_based_distro = ['fedora', 'redhat']
30-
31-
if distribution in debian_based_distro:
32-
lib_dir = '/usr/lib/p7zip'
33-
34-
elif distribution in rpm_based_distro:
35-
lib_dir = '/usr/libexec/p7zip'
36-
37-
else:
38-
raise Exception('Unsupported system: {}'.format(distribution))
39-
elif mainstream_system == 'freebsd':
40-
lib_dir = '/usr/local/libexec/p7zip'
27+
lib_dir = environ.get('LD_LIBRARY_PATH')
28+
if not lib_dir:
29+
mainstream_system = platform.system().lower()
30+
if mainstream_system == 'linux':
31+
distribution = platform.linux_distribution()[0].lower()
32+
debian_based_distro = ['ubuntu', 'mint', 'debian']
33+
rpm_based_distro = ['fedora', 'redhat']
34+
35+
if distribution in debian_based_distro:
36+
lib_dir = '/usr/lib/p7zip'
37+
38+
elif distribution in rpm_based_distro:
39+
lib_dir = '/usr/libexec/p7zip'
40+
41+
else:
42+
raise Exception('Unsupported system: {}'.format(distribution))
43+
elif mainstream_system == 'freebsd':
44+
lib_dir = '/usr/local/libexec/p7zip'
45+
lib_7z = path.join(lib_dir, '7z')
46+
if not path.exists(lib_7z):
47+
for element in environ.get('PATH', '').split(pathsep):
48+
if path.exists(path.join(element, '7z')):
49+
lib_7z = path.join(element, '7z')
50+
break
4151

4252
locations = {
4353
'extractcode.sevenzip.libdir': lib_dir,
44-
'extractcode.sevenzip.exe': path.join(lib_dir, '7z'),
54+
'extractcode.sevenzip.exe': lib_7z,
4555
}
4656

4757
return locations

0 commit comments

Comments
 (0)