88import platform
99import warnings
1010import logging
11+ import glob
1112from datetime import datetime
1213import fosslight_util .constant as constant
1314from fosslight_util .set_log import init_log
@@ -261,7 +262,7 @@ def create_report_file(
261262 return scan_item
262263
263264
264- def merge_results (scancode_result : list = [], scanoss_result : list = [], spdx_downloads : dict = {}, path_to_exclude = []) -> list :
265+ def merge_results (scancode_result : list = [], scanoss_result : list = [], spdx_downloads : dict = {}, path_to_exclude = []) -> list :
265266 """
266267 Merge scanner results and spdx parsing result.
267268 :param scancode_result: list of scancode results in SourceItem.
@@ -285,14 +286,24 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
285286 new_result_item .download_location = download_location
286287 scancode_result .append (new_result_item )
287288
289+ # normalize for windows
290+ normalized_patterns = [os .path .normpath (pattern ).replace ("\\ " , "/" ) for pattern in path_to_exclude ]
291+
292+ # cnt = 0
293+ if path_to_exclude :
294+ for i in range (len (scancode_result ) - 1 , - 1 , - 1 ): # Iterate from last to first
295+ item_path = scancode_result [i ].source_name_or_path # Assuming SourceItem has 'file_path' attribute
296+ if any (
297+ glob .fnmatch .fnmatch (item_path , f"{ pattern } " ) or # file name
298+ glob .fnmatch .fnmatch (item_path , f"*/{ pattern } " ) or # file name in sub directory
299+ glob .fnmatch .fnmatch (item_path , f"*{ pattern } /*" ) # directory name
300+ for pattern in normalized_patterns
301+ ):
302+ # cnt += 1
303+ # print(cnt, "EXCLUDED:", item_path)
304+ del scancode_result [i ] # Delete matching item
305+
288306 for item in scancode_result :
289- item_path = item .source_name_or_path
290- if any (
291- excluded in item_path and
292- (item_path == excluded or item_path .startswith (f"{ excluded } { os .sep } " ))
293- for excluded in path_to_exclude
294- ):
295- continue
296307 item .set_oss_item ()
297308
298309 return scancode_result
@@ -346,7 +357,8 @@ def run_scanners(
346357 success , result_log [RESULT_KEY ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
347358 write_json_file , num_cores , True ,
348359 print_matched_text , formats , called_by_cli ,
349- time_out , correct_mode , correct_filepath )
360+ time_out , correct_mode , correct_filepath ,
361+ path_to_exclude )
350362 if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '' :
351363 scanoss_result = run_scanoss_py (path_to_scan , output_file_name , formats , True , write_json_file , num_cores ,
352364 path_to_exclude )
0 commit comments