2121from fosslight_util .set_log import init_log
2222from fosslight_util .timer_thread import TimerThread
2323import fosslight_util .constant as constant
24- from fosslight_util .output_format import write_output_file , check_output_format
24+ from fosslight_util .output_format import check_output_format
2525from fosslight_reuse ._fosslight_reuse import run_lint as reuse_lint
2626from .common import copy_file , call_analysis_api
27+ from fosslight_util .write_excel import merge_excels
2728
2829OUTPUT_EXCEL_PREFIX = "FOSSLight-Report_"
2930OUTPUT_JSON_PREFIX = "Opossum_input_"
@@ -90,20 +91,25 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
9091 run_src = True , run_bin = True , run_dep = True , run_reuse = True ,
9192 remove_src_data = True , result_log = {}, output_file = "" ,
9293 output_extension = "" , num_cores = - 1 , db_url = "" ):
94+ create_csv = False
95+ final_excel_dir = output_path
96+ success = True
97+ if not remove_src_data :
98+ success , final_excel_dir , result_log = init (output_path )
99+
100+ if output_file == "" :
101+ output_prefix = OUTPUT_EXCEL_PREFIX if output_extension != ".json" else OUTPUT_JSON_PREFIX
102+ output_file = output_prefix + _start_time
103+ create_csv = True
104+
105+ if output_extension == "" :
106+ output_extension = ".xlsx"
107+
93108 try :
94- success = True
95109 sheet_list = {}
96- if not remove_src_data :
97- success , final_excel_dir , result_log = init (output_path )
98- else :
99- final_excel_dir = output_path
100110 final_excel_dir = os .path .abspath (final_excel_dir )
101111 abs_path = os .path .abspath (src_path )
102112
103- if output_file == "" :
104- output_prefix = OUTPUT_EXCEL_PREFIX if output_extension != ".json" else OUTPUT_JSON_PREFIX
105- output_file = output_prefix + _start_time
106-
107113 if success :
108114 output_files = {"SRC" : "FL_Source" ,
109115 "BIN" : "FL_Binary.xlsx" ,
@@ -132,48 +138,43 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
132138 logger .warning (f"Failed to run source analysis:{ ex } " )
133139
134140 if run_bin :
135- success , result_bin = call_analysis_api (src_path , "Binary Analysis" ,
136- 1 , binary_analysis .find_binaries ,
137- abs_path ,
138- os .path .join (_output_dir , output_files ["BIN" ]),
139- "" , db_url )
140- if result_bin :
141- sheet_list ["BIN_FL_Binary" ] = result_bin
141+ success , _ = call_analysis_api (src_path , "Binary Analysis" ,
142+ 1 , binary_analysis .find_binaries ,
143+ abs_path ,
144+ os .path .join (_output_dir , output_files ["BIN" ]),
145+ "" , db_url )
146+ if success :
142147 copy_file (os .path .join (_output_dir , output_files ["BIN_TXT" ]), output_path )
143148
144149 if run_dep :
145- result_list = run_dependency (src_path , os .path .join (_output_dir , output_files ["DEP" ]), dep_arguments )
146- sheet_list ['SRC_FL_Dependency' ] = result_list
147-
148- output_file_without_ext = os .path .join (final_excel_dir , output_file )
149- success , msg , result_file = write_output_file (output_file_without_ext , output_extension , sheet_list )
150-
151- if success :
152- logger .info (f"Writing Output file({ result_file } , Success: { success } " )
153- else :
154- logger .error (f"Fail to generate result file. msg:({ msg } )" )
150+ run_dependency (src_path , os .path .join (_output_dir , output_files ["DEP" ]), dep_arguments )
151+ else :
152+ return
155153
156- result_log ["Result" ] = success
157- if success :
158- file_extension = ".xlsx" if output_extension == "" else output_extension
159- result_log ["Output File" ] = output_file_without_ext + file_extension
160- else :
161- result_log ["Result Message - Merge" ] = msg
162154 except Exception as ex :
163155 logger .error (f"Scanning:{ ex } " )
164156
165157 try :
158+ output_file_without_ext = os .path .join (final_excel_dir , output_file )
159+ final_report = f"{ output_file_without_ext } { output_extension } "
160+ success , output_files = merge_excels (_output_dir , final_report , create_csv )
161+
162+ if success and output_files :
163+ result_log ["Output File" ] = output_files .split ("," )
164+ else :
165+ logger .error (f"Fail to generate a result file. :{ output_files } " )
166+
166167 _str_final_result_log = yaml .safe_dump (result_log , allow_unicode = True , sort_keys = True )
167168 logger .info (_str_final_result_log )
168169 except Exception as ex :
169- logger .warn (f"Error to print final log :{ ex } " )
170+ logger .warning (f"Error to write final report :{ ex } " )
170171
171172 try :
172173 if not keep_raw_data :
173174 logger .debug (f"Remove temporary files: { _output_dir } " )
174175 rmdir (_output_dir )
175176 if remove_src_data :
176- logger .debug (f"Remove Source : { src_path } " )
177+ logger .debug (f"Remove temporary source : { src_path } " )
177178 rmdir (src_path )
178179 except Exception as ex :
179180 logger .debug (f"Error to remove temp files:{ ex } " )
@@ -188,18 +189,18 @@ def download_source(link, out_dir):
188189 temp_src_dir = os .path .join (
189190 _output_dir , SRC_DIR_FROM_LINK_PREFIX + start_time )
190191
191- logger .info ("Link to download :" + link )
192+ logger .info (f "Link to download :{ link } " )
192193 success , msg = cli_download_and_extract (
193194 link , temp_src_dir , _output_dir )
194195
195196 if success :
196- logger .info ("Downloaded Dir:" + temp_src_dir )
197+ logger .info (f "Downloaded Dir:{ temp_src_dir } " )
197198 else :
198199 temp_src_dir = ""
199- logger .error ("Download failed:" + msg )
200+ logger .error (f "Download failed:{ msg } " )
200201 except Exception as ex :
201202 success = False
202- logger .error ("Failed to analyze from link:" + str ( ex ) )
203+ logger .error (f "Failed to analyze from link:{ ex } " )
203204 return success , temp_src_dir
204205
205206
0 commit comments