Skip to content

Commit 2ef0fb8

Browse files
7z-sys-provided: let user override paths
let the user override assumed paths via environment. EXTRACTCODE_7Z_PATH is used to determine the path of the 7z executable. If not specified it falls back to previously used probe of distro data. 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 2ef0fb8

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
A ScanCode Toolkit plugin to use pre-installed system binary libraries and utilities.
1+
A ScanCode Toolkit plugin to use pre-installed 7zip executables
2+
===============================================================
3+
4+
the path of 7zip is either determined by distro data or explicitily
5+
taken from ``EXTRACTCODE_7Z_PATH`` environment variable

builtins/extractcode_7z_system_provided/src/extractcode_7z/__init__.py

Lines changed: 24 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,31 @@ 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_7z = environ.get('EXTRACTCODE_7Z_PATH')
28+
if not lib_7z:
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+
else:
47+
lib_dir = path.dirname(lib_7z)
4148

4249
locations = {
4350
'extractcode.sevenzip.libdir': lib_dir,
44-
'extractcode.sevenzip.exe': path.join(lib_dir, '7z'),
51+
'extractcode.sevenzip.exe': lib_7z,
4552
}
4653

4754
return locations

0 commit comments

Comments
 (0)