Skip to content

Commit 6cd27b9

Browse files
Use glob pattern matching for exclusion
Signed-off-by: Wonjae Park <[email protected]>
1 parent ad34489 commit 6cd27b9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/fosslight_source/cli.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import platform
99
import warnings
1010
import logging
11+
import glob
1112
from datetime import datetime
1213
import fosslight_util.constant as constant
1314
from fosslight_util.set_log import init_log
@@ -261,7 +262,7 @@ def create_report_file(
261262
return scan_item
262263

263264

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:
265266
"""
266267
Merge scanner results and spdx parsing result.
267268
:param scancode_result: list of scancode results in SourceItem.
@@ -289,13 +290,18 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
289290
item = scancode_result[i]
290291
item_path = item.source_name_or_path
291292

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
295301
):
296-
item.set_oss_item()
297-
else:
298302
del scancode_result[i]
303+
else:
304+
item.set_oss_item()
299305

300306
return scancode_result
301307

@@ -348,7 +354,8 @@ def run_scanners(
348354
success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
349355
write_json_file, num_cores, True,
350356
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)
352359
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
353360
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores,
354361
path_to_exclude)

0 commit comments

Comments
 (0)