|
8 | 8 | import platform
|
9 | 9 | import warnings
|
10 | 10 | import logging
|
| 11 | +import glob |
11 | 12 | from datetime import datetime
|
12 | 13 | import fosslight_util.constant as constant
|
13 | 14 | from fosslight_util.set_log import init_log
|
@@ -258,7 +259,7 @@ def create_report_file(
|
258 | 259 | return scan_item
|
259 | 260 |
|
260 | 261 |
|
261 |
| -def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}, path_to_exclude =[]) -> list: |
| 262 | +def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}, path_to_exclude=[]) -> list: |
262 | 263 | """
|
263 | 264 | Merge scanner results and spdx parsing result.
|
264 | 265 | :param scancode_result: list of scancode results in SourceItem.
|
@@ -286,13 +287,18 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
|
286 | 287 | item = scancode_result[i]
|
287 | 288 | item_path = item.source_name_or_path
|
288 | 289 |
|
289 |
| - if not any( |
290 |
| - item_path == excluded or item_path.startswith(f"{excluded}{os.sep}") |
291 |
| - for excluded in path_to_exclude |
| 290 | + # normalize for windows |
| 291 | + normalized_patterns = [os.path.normpath(pattern).replace("\\", "/") for pattern in path_to_exclude] |
| 292 | + |
| 293 | + # remove from the scanned list if path is matched with exclude patterns |
| 294 | + if any( |
| 295 | + glob.fnmatch.fnmatch(item_path, f"{pattern}") or # 단독 파일 이름 체크 |
| 296 | + glob.fnmatch.fnmatch(item_path, f"**/{pattern}") # 경로 포함 체크 |
| 297 | + for pattern in normalized_patterns |
292 | 298 | ):
|
293 |
| - item.set_oss_item() |
294 |
| - else: |
295 | 299 | del scancode_result[i]
|
| 300 | + else: |
| 301 | + item.set_oss_item() |
296 | 302 |
|
297 | 303 | return scancode_result
|
298 | 304 |
|
@@ -345,7 +351,8 @@ def run_scanners(
|
345 | 351 | success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
|
346 | 352 | write_json_file, num_cores, True,
|
347 | 353 | print_matched_text, formats, called_by_cli,
|
348 |
| - time_out, correct_mode, correct_filepath) |
| 354 | + time_out, correct_mode, correct_filepath, |
| 355 | + path_to_exclude) |
349 | 356 | if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
|
350 | 357 | scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores,
|
351 | 358 | path_to_exclude)
|
|
0 commit comments