Skip to content

Commit 32ff721

Browse files
Fix match method
Signed-off-by: Wonjae Park <j.wonjae.park@gmail.com>
1 parent 1db2763 commit 32ff721

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/fosslight_source/cli.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import warnings
1010
import logging
1111
import glob
12+
import fnmatch
1213
from datetime import datetime
1314
import fosslight_util.constant as constant
1415
from fosslight_util.set_log import init_log
@@ -286,22 +287,25 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
286287
new_result_item.download_location = download_location
287288
scancode_result.append(new_result_item)
288289

289-
for i in range(len(scancode_result) - 1, -1, -1):
290-
item = scancode_result[i]
291-
item_path = item.source_name_or_path
292-
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
301-
):
302-
del scancode_result[i]
303-
else:
304-
item.set_oss_item()
290+
# normalize for windows
291+
normalized_patterns = [os.path.normpath(pattern).replace("\\", "/") for pattern in path_to_exclude]
292+
293+
# cnt = 0
294+
if path_to_exclude:
295+
for i in range(len(scancode_result) - 1, -1, -1): # Iterate from last to first
296+
item_path = scancode_result[i].source_name_or_path # Assuming SourceItem has 'file_path' attribute
297+
if any(
298+
glob.fnmatch.fnmatch(item_path, f"{pattern}") or # file name
299+
glob.fnmatch.fnmatch(item_path, f"*/{pattern}") or # file name in sub directory
300+
glob.fnmatch.fnmatch(item_path, f"*{pattern}/*") # directory name
301+
for pattern in normalized_patterns
302+
):
303+
# cnt += 1
304+
# print(cnt, "EXCLUDED:", item_path)
305+
del scancode_result[i] # Delete matching item
306+
307+
for item in scancode_result:
308+
item.set_oss_item()
305309

306310
return scancode_result
307311

0 commit comments

Comments
 (0)