|
13 | 13 | from shutil import rmtree as rmdir |
14 | 14 | from datetime import datetime |
15 | 15 | from fosslight_binary import binary_analysis |
16 | | -from fosslight_source.cli import run_all_scanners as source_analysis |
17 | | -from fosslight_source.cli import create_report_file |
18 | 16 | from fosslight_dependency.run_dependency_scanner import run_dependency_scanner |
19 | 17 | from fosslight_util.download import cli_download_and_extract |
20 | 18 | from ._get_input import get_input_mode |
|
26 | 24 | from .common import (copy_file, call_analysis_api, |
27 | 25 | overwrite_excel, extract_name_from_link) |
28 | 26 | from fosslight_util.write_excel import merge_excels |
| 27 | +import subprocess |
| 28 | +fosslight_source_installed = True |
| 29 | +try: |
| 30 | + from fosslight_source.cli import run_all_scanners as source_analysis |
| 31 | + from fosslight_source.cli import create_report_file |
| 32 | +except ModuleNotFoundError: |
| 33 | + fosslight_source_installed = False |
29 | 34 |
|
30 | 35 | OUTPUT_EXCEL_PREFIX = "FOSSLight-Report_" |
31 | 36 | OUTPUT_JSON_PREFIX = "Opossum_input_" |
@@ -128,14 +133,24 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False, |
128 | 133 |
|
129 | 134 | if run_src: |
130 | 135 | try: |
131 | | - success, result = call_analysis_api(src_path, "Source Analysis", |
132 | | - -1, source_analysis, |
133 | | - abs_path, |
134 | | - os.path.join(_output_dir, output_files["SRC"]), |
135 | | - False, num_cores, True) |
136 | | - if success: |
137 | | - sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result[2]] |
138 | | - create_report_file(0, result[2], result[3], 'all', True, _output_dir, output_files["SRC"], "") |
| 136 | + if fosslight_source_installed: |
| 137 | + src_output = os.path.join(_output_dir, output_files["SRC"]) |
| 138 | + success, result = call_analysis_api(src_path, "Source Analysis", |
| 139 | + -1, source_analysis, |
| 140 | + abs_path, |
| 141 | + src_output, |
| 142 | + False, num_cores, True) |
| 143 | + if success: |
| 144 | + sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result[2]] |
| 145 | + create_report_file(0, result[2], result[3], 'all', True, _output_dir, output_files["SRC"], "") |
| 146 | + else: # Run fosslight_source by using docker image |
| 147 | + src_output = os.path.join("output", output_files["SRC"]) |
| 148 | + output_rel_path = os.path.relpath(abs_path, os.getcwd()) |
| 149 | + command = f"docker run -it -v {_output_dir}:/app/output "\ |
| 150 | + f"fosslight -p {output_rel_path} -o {src_output}.xlsx" |
| 151 | + command_result = subprocess.run(command.split(' '), stdout=subprocess.PIPE, text=True) |
| 152 | + logger.info(f"Source Analysis Result:{command_result.stdout}") |
| 153 | + |
139 | 154 | except Exception as ex: |
140 | 155 | logger.warning(f"Failed to run source analysis: {ex}") |
141 | 156 |
|
|
0 commit comments