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