Skip to content

Commit b13566e

Browse files
Use glob pattern matching for exclusion
Signed-off-by: Wonjae Park <j.wonjae.park@gmail.com>
1 parent f52aa50 commit b13566e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/fosslight_source/cli.py

+14-7
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
@@ -258,7 +259,7 @@ def create_report_file(
258259
return scan_item
259260

260261

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:
262263
"""
263264
Merge scanner results and spdx parsing result.
264265
:param scancode_result: list of scancode results in SourceItem.
@@ -286,13 +287,18 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
286287
item = scancode_result[i]
287288
item_path = item.source_name_or_path
288289

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
292298
):
293-
item.set_oss_item()
294-
else:
295299
del scancode_result[i]
300+
else:
301+
item.set_oss_item()
296302

297303
return scancode_result
298304

@@ -345,7 +351,8 @@ def run_scanners(
345351
success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
346352
write_json_file, num_cores, True,
347353
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)
349356
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
350357
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores,
351358
path_to_exclude)

0 commit comments

Comments
 (0)