Skip to content

Commit aeb6c18

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

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/fosslight_source/cli.py

Lines changed: 13 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
@@ -285,14 +286,19 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
285286
for i in range(len(scancode_result) - 1, -1, -1):
286287
item = scancode_result[i]
287288
item_path = item.source_name_or_path
288-
289-
if not any(
290-
item_path == excluded or item_path.startswith(f"{excluded}{os.sep}")
291-
for excluded in path_to_exclude
289+
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,7 @@ 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, path_to_exclude)
349355
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
350356
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores,
351357
path_to_exclude)

0 commit comments

Comments
 (0)