diff --git a/src/fosslight_source/cli.py b/src/fosslight_source/cli.py index 72164e4..6417d40 100755 --- a/src/fosslight_source/cli.py +++ b/src/fosslight_source/cli.py @@ -404,8 +404,10 @@ def run_scanners( excluded_files) excluded_files = set(excluded_files) if excluded_files else set() if selected_scanner in ['scanoss', 'all']: - scanoss_result, api_limit_exceed = run_scanoss_py(path_to_scan, output_file_name, formats, True, - num_cores, excluded_path_with_default_exclusion, excluded_files) + scanoss_result, api_limit_exceed = run_scanoss_py(path_to_scan, output_path, formats, True, num_cores, + excluded_path_with_default_exclusion, excluded_files, + write_json_file) + if selected_scanner in SCANNER_TYPE: run_kb = True if selected_scanner in ['kb', 'all'] else False spdx_downloads, manifest_licenses = metadata_collector(path_to_scan, excluded_files) diff --git a/src/fosslight_source/run_scanoss.py b/src/fosslight_source/run_scanoss.py index 53d094a..6327e8a 100755 --- a/src/fosslight_source/run_scanoss.py +++ b/src/fosslight_source/run_scanoss.py @@ -8,8 +8,8 @@ import warnings import logging import json +from typing import Tuple import fosslight_util.constant as constant -from fosslight_util.output_format import check_output_formats_v2 # , write_output_file from ._parsing_scanoss_file import parsing_scan_result # scanoss from ._parsing_scanoss_file import parsing_extra_info # scanoss from scanoss.scanner import Scanner, ScanType @@ -19,7 +19,6 @@ logger = logging.getLogger(constant.LOGGER_NAME) warnings.filterwarnings("ignore", category=FutureWarning) _PKG_NAME = "fosslight_source" -SCANOSS_RESULT_FILE = "scanner_output.wfp" SCANOSS_OUTPUT_FILE = "scanoss_raw_result.json" @@ -27,9 +26,10 @@ def get_scanoss_extra_info(scanned_result: dict) -> list: return parsing_extra_info(scanned_result) -def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list = [], +def run_scanoss_py(path_to_scan: str, output_path: str = "", format: list = [], called_by_cli: bool = False, num_threads: int = -1, - path_to_exclude: list = [], excluded_files: set = None) -> list: + path_to_exclude: list = [], excluded_files: set = None, + write_json_file: bool = False) -> Tuple[list, bool]: """ Run scanoss.py for the given path. @@ -40,7 +40,6 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list = :param write_json_file: if requested, keep the raw files. :return scanoss_file_list: list of ScanItem (scanned result by files). """ - success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, format) scanoss_file_list = [] api_limit_exceed = False @@ -49,10 +48,10 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list = except Exception as error: logger.warning(f"{error}. Skipping scan with scanoss.") logger.warning("Please install scanoss and dataclasses before run fosslight_source with scanoss option.") - return scanoss_file_list + return scanoss_file_list, api_limit_exceed output_json_file = os.path.join(output_path, SCANOSS_OUTPUT_FILE) - if os.path.exists(output_json_file): # remove scanner_output.wfp file if exist + if os.path.exists(output_json_file): os.remove(output_json_file) try: @@ -82,6 +81,10 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list = st_python = json.load(st_json) scanoss_file_list = parsing_scan_result(st_python, excluded_files) + if not write_json_file: + if os.path.isfile(output_json_file): + os.remove(output_json_file) + except Exception as error: logger.debug(f"SCANOSS Parsing {path_to_scan}: {error}")