Skip to content

Commit

Permalink
Fix match method
Browse files Browse the repository at this point in the history
Signed-off-by: Wonjae Park <[email protected]>
  • Loading branch information
JustinWonjaePark committed Dec 11, 2024
1 parent 1db2763 commit 32ff721
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/fosslight_source/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings
import logging
import glob
import fnmatch
from datetime import datetime
import fosslight_util.constant as constant
from fosslight_util.set_log import init_log
Expand Down Expand Up @@ -286,22 +287,25 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
new_result_item.download_location = download_location
scancode_result.append(new_result_item)

for i in range(len(scancode_result) - 1, -1, -1):
item = scancode_result[i]
item_path = item.source_name_or_path

# normalize for windows
normalized_patterns = [os.path.normpath(pattern).replace("\\", "/") for pattern in path_to_exclude]

# remove from the scanned list if path is matched with exclude patterns
if any(
glob.fnmatch.fnmatch(item_path, f"{pattern}") or # 단독 파일 이름 체크
glob.fnmatch.fnmatch(item_path, f"**/{pattern}") # 경로 포함 체크
for pattern in normalized_patterns
):
del scancode_result[i]
else:
item.set_oss_item()
# normalize for windows
normalized_patterns = [os.path.normpath(pattern).replace("\\", "/") for pattern in path_to_exclude]

# cnt = 0
if path_to_exclude:
for i in range(len(scancode_result) - 1, -1, -1): # Iterate from last to first
item_path = scancode_result[i].source_name_or_path # Assuming SourceItem has 'file_path' attribute
if any(
glob.fnmatch.fnmatch(item_path, f"{pattern}") or # file name
glob.fnmatch.fnmatch(item_path, f"*/{pattern}") or # file name in sub directory
glob.fnmatch.fnmatch(item_path, f"*{pattern}/*") # directory name
for pattern in normalized_patterns
):
# cnt += 1
# print(cnt, "EXCLUDED:", item_path)
del scancode_result[i] # Delete matching item

for item in scancode_result:
item.set_oss_item()

return scancode_result

Expand Down

0 comments on commit 32ff721

Please sign in to comment.