|
1 | | - |
2 | 1 | # |
3 | 2 | # Copyright (c) nexB Inc. and others. |
4 | 3 | # SPDX-License-Identifier: Apache-2.0 |
|
73 | 72 | UNKNOWN_ERROR = 'Unknown extraction error' |
74 | 73 |
|
75 | 74 |
|
| 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 | + |
76 | 93 | def get_7z_errors(stdout, stderr): |
77 | 94 | """ |
78 | 95 | Return error messages extracted from a 7zip command output `stdout` and |
@@ -160,18 +177,6 @@ def is_rar(location): |
160 | 177 | return T.filetype_file.lower().startswith('rar archive') |
161 | 178 |
|
162 | 179 |
|
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 | | - |
175 | 180 | def extract(location, target_dir, arch_type='*', file_by_file=on_mac, skip_symlinks=True): |
176 | 181 | """ |
177 | 182 | Extract all files from a 7zip-supported archive file at location in the |
|
0 commit comments