diff --git a/src/fosslight_source/cli.py b/src/fosslight_source/cli.py index ab59898..849638a 100755 --- a/src/fosslight_source/cli.py +++ b/src/fosslight_source/cli.py @@ -8,6 +8,7 @@ import platform import warnings import logging +import glob from datetime import datetime import fosslight_util.constant as constant from fosslight_util.set_log import init_log @@ -261,7 +262,7 @@ def create_report_file( return scan_item -def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}) -> list: +def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}, path_to_exclude=[]) -> list: """ Merge scanner results and spdx parsing result. :param scancode_result: list of scancode results in SourceItem. @@ -285,6 +286,23 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do new_result_item.download_location = download_location scancode_result.append(new_result_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() @@ -339,13 +357,14 @@ def run_scanners( success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name, write_json_file, num_cores, True, print_matched_text, formats, called_by_cli, - time_out, correct_mode, correct_filepath) + time_out, correct_mode, correct_filepath, + path_to_exclude) if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '': scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores, path_to_exclude) if selected_scanner in SCANNER_TYPE: spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude) - merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads) + merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads, path_to_exclude) scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner, print_matched_text, output_path, output_files, output_extensions, correct_mode, correct_filepath, path_to_scan, path_to_exclude, formats) diff --git a/src/fosslight_source/run_scanoss.py b/src/fosslight_source/run_scanoss.py index 32eab8a..fac3136 100755 --- a/src/fosslight_source/run_scanoss.py +++ b/src/fosslight_source/run_scanoss.py @@ -110,6 +110,9 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list = try: if write_json_file: + destination_file = os.path.join(output_path, SCANOSS_RESULT_FILE) + if os.path.exists(destination_file): + os.remove(destination_file) shutil.move(SCANOSS_RESULT_FILE, output_path) else: os.remove(output_json_file)