1313from fosslight_util .timer_thread import TimerThread
1414from ._help import print_version , print_help_msg_source_scanner
1515from ._license_matched import get_license_list_to_print
16- from fosslight_util .output_format import check_output_format , write_output_file
16+ from fosslight_util .output_format import check_output_formats , write_output_file
1717from fosslight_util .correct import correct_with_yaml
1818from .run_scancode import run_scan
1919from .run_scanoss import run_scanoss_py
@@ -48,7 +48,7 @@ def main():
4848 write_json_file = False
4949 output_file_name = ""
5050 print_matched_text = False
51- format = ""
51+ formats = ""
5252 selected_scanner = ""
5353 correct_mode = True
5454
@@ -62,7 +62,7 @@ def main():
6262 parser .add_argument ('-j' , '--json' , action = 'store_true' , required = False )
6363 parser .add_argument ('-o' , '--output' , nargs = 1 , type = str , required = False , default = "" )
6464 parser .add_argument ('-m' , '--matched' , action = 'store_true' , required = False )
65- parser .add_argument ('-f' , '--format ' , nargs = 1 , type = str , required = False )
65+ parser .add_argument ('-f' , '--formats ' , nargs = '*' , type = str , required = False )
6666 parser .add_argument ('-s' , '--scanner' , nargs = 1 , type = str , required = False , default = 'all' )
6767 parser .add_argument ('-t' , '--timeout' , type = int , required = False , default = 120 )
6868 parser .add_argument ('-c' , '--cores' , type = int , required = False , default = - 1 )
@@ -87,8 +87,8 @@ def main():
8787 output_file_name = '' .join (args .output )
8888 if args .matched :
8989 print_matched_text = True
90- if args .format :
91- format = '' . join (args .format )
90+ if args .formats :
91+ formats = list (args .formats )
9292 if args .scanner :
9393 selected_scanner = '' .join (args .scanner )
9494 if args .no_correction :
@@ -107,8 +107,9 @@ def main():
107107 if os .path .isdir (path_to_scan ):
108108 result = []
109109 result = run_scanners (path_to_scan , output_file_name , write_json_file , core , True ,
110- print_matched_text , format , time_out , correct_mode , correct_filepath ,
110+ print_matched_text , formats , time_out , correct_mode , correct_filepath ,
111111 selected_scanner , path_to_exclude )
112+
112113 _result_log ["Scan Result" ] = result [1 ]
113114
114115 try :
@@ -138,7 +139,7 @@ def count_files(path_to_scan, path_to_exclude):
138139
139140
140141def create_report_file (_start_time , merged_result , license_list , scanoss_result , selected_scanner , need_license = False ,
141- output_path = "" , output_file = "" , output_extension = "" , correct_mode = True , correct_filepath = "" ,
142+ output_path = "" , output_files = [], output_extensions = [] , correct_mode = True , correct_filepath = "" ,
142143 path_to_scan = "" , path_to_exclude = []):
143144 """
144145 Create report files for given scanned result.
@@ -156,22 +157,30 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
156157 output_path = os .getcwd ()
157158 else :
158159 output_path = os .path .abspath (output_path )
160+
161+ if output_files and output_files [0 ]:
162+ # If -o contains file name, set all output file name and dont' use default name
163+ output_files = [output_files [0 ] for _ in range (len (output_extensions ))]
164+ else :
165+ # If -o does not contains file name, set default name
166+ while len (output_files ) < len (output_extensions ):
167+ output_files .append (None )
168+ for i , output_extension in enumerate (output_extensions ):
169+ if output_files [i ] is None or output_files [i ] == "" :
170+ if output_extension == _json_ext :
171+ output_files [i ] = f"fosslight_opossum_src_{ _start_time } "
172+ else :
173+ output_files [i ] = f"fosslight_report_src_{ _start_time } "
159174
160175 if not correct_filepath :
161176 correct_filepath = path_to_scan
162-
163- if output_file == "" :
164- if output_extension == _json_ext :
165- output_file = f"fosslight_opossum_src_{ _start_time } "
166- else :
167- output_file = f"fosslight_report_src_{ _start_time } "
168-
169177 cover = CoverItem (tool_name = _PKG_NAME ,
170178 start_time = _start_time ,
171179 input_path = path_to_scan ,
172180 exclude_path = path_to_exclude )
173181 files_count , removed_files_count = count_files (path_to_scan , path_to_exclude )
174182 cover .comment = f"Total number of files / removed files: { files_count } / { removed_files_count } "
183+
175184 if len (merged_result ) == 0 :
176185 if files_count < 1 :
177186 cover .comment += "(No file detected.)"
@@ -190,7 +199,7 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
190199 extended_header = MERGED_HEADER
191200
192201 if need_license :
193- if selected_scanner == 'scancode' or output_extension == _json_ext :
202+ if selected_scanner == 'scancode' :
194203 sheet_list ["scancode_reference" ] = get_license_list_to_print (license_list )
195204 elif selected_scanner == 'scanoss' :
196205 sheet_list ["scanoss_reference" ] = get_scanoss_extra_info (scanoss_result )
@@ -206,17 +215,23 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
206215 sheet_list = correct_list
207216 logger .info ("Success to correct with yaml." )
208217
209- output_file_without_ext = os .path .join (output_path , output_file )
210- success_to_write , writing_msg , result_file = write_output_file (output_file_without_ext , output_extension ,
211- sheet_list , extended_header , "" , cover )
212- if success_to_write :
213- if result_file :
214- logger .info (f"Output file:{ result_file } " )
215- logger .info (f'{ cover .comment } ' )
218+ combined_paths_and_files = [os .path .join (output_path , file ) for file in output_files ]
219+ results = []
220+ for combined_path_and_file , output_extension in zip (combined_paths_and_files , output_extensions ):
221+ if need_license :
222+ if output_extension == _json_ext :
223+ sheet_list ["scancode_reference" ] = get_license_list_to_print (license_list )
224+ elif selected_scanner == 'scanoss' :
225+ if "scancode_reference" in sheet_list :
226+ del sheet_list ["scancode_reference" ]
227+ results .append (write_output_file (combined_path_and_file , output_extension , sheet_list , extended_header , "" , cover ))
228+ for success , msg , result_file in results :
229+ if success :
230+ logger .info (f"Output file: { result_file } " )
231+ if cover :
232+ logger .info (f'{ cover .comment } ' )
216233 else :
217- logger .warning (f"{ writing_msg } " )
218- else :
219- logger .error (f"Fail to generate result file. msg:({ writing_msg } )" )
234+ logger .error (f"Fail to generate result file { result_file } . msg:({ msg } )" )
220235
221236
222237def merge_results (scancode_result = [], scanoss_result = [], spdx_downloads = {}):
@@ -246,7 +261,7 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
246261
247262
248263def run_scanners (path_to_scan , output_file_name = "" , write_json_file = False , num_cores = - 1 , called_by_cli = True ,
249- print_matched_text = False , format = "" , time_out = 120 , correct_mode = True , correct_filepath = "" ,
264+ print_matched_text = False , formats = [] , time_out = 120 , correct_mode = True , correct_filepath = "" ,
250265 selected_scanner = 'all' , path_to_exclude = []):
251266 """
252267 Run Scancode and scanoss.py for the given path.
@@ -273,27 +288,28 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
273288 spdx_downloads = {}
274289 result_log = {}
275290
276- success , msg , output_path , output_file , output_extension = check_output_format (output_file_name , format )
291+ success , msg , output_path , output_files , output_extensions = check_output_formats (output_file_name , formats )
292+
277293 logger , result_log = init_log (os .path .join (output_path , f"fosslight_log_src_{ start_time } .txt" ),
278294 True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_scan , path_to_exclude )
279- if output_extension != '.xlsx' and output_extension and print_matched_text :
295+
296+ if '.xlsx' not in output_extensions and print_matched_text :
280297 logger .warning ("-m option is only available for excel." )
281298 print_matched_text = False
299+
282300 if success :
283301 if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '' :
284302 success , result_log [RESULT_KEY ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
285303 write_json_file , num_cores , True ,
286- print_matched_text , format , called_by_cli ,
287- time_out , correct_mode , correct_filepath ,
288- path_to_exclude )
304+ print_matched_text , formats , called_by_cli ,
305+ time_out , correct_mode , correct_filepath )
289306 if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '' :
290- scanoss_result = run_scanoss_py (path_to_scan , output_file_name , format , True ,
291- write_json_file , num_cores , path_to_exclude )
307+ scanoss_result = run_scanoss_py (path_to_scan , output_file_name , formats , True , write_json_file , num_cores , path_to_exclude )
292308 if selected_scanner in SCANNER_TYPE :
293309 spdx_downloads = get_spdx_downloads (path_to_scan , path_to_exclude )
294310 merged_result = merge_results (scancode_result , scanoss_result , spdx_downloads )
295311 create_report_file (start_time , merged_result , license_list , scanoss_result , selected_scanner ,
296- print_matched_text , output_path , output_file , output_extension , correct_mode ,
312+ print_matched_text , output_path , output_files , output_extensions , correct_mode ,
297313 correct_filepath , path_to_scan , path_to_exclude )
298314 else :
299315 print_help_msg_source_scanner ()
@@ -302,7 +318,6 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
302318 else :
303319 result_log [RESULT_KEY ] = f"Format error. { msg } "
304320 success = False
305-
306321 return success , result_log .get (RESULT_KEY , "" ), merged_result , license_list , scanoss_result
307322
308323
0 commit comments