|
9 | 9 | import warnings
|
10 | 10 | import logging
|
11 | 11 | import glob
|
| 12 | +import fnmatch |
12 | 13 | from datetime import datetime
|
13 | 14 | import fosslight_util.constant as constant
|
14 | 15 | from fosslight_util.set_log import init_log
|
@@ -286,22 +287,25 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
|
286 | 287 | new_result_item.download_location = download_location
|
287 | 288 | scancode_result.append(new_result_item)
|
288 | 289 |
|
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() |
305 | 309 |
|
306 | 310 | return scancode_result
|
307 | 311 |
|
|
0 commit comments