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.
@@ -157,21 +158,26 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
157158 else :
158159 output_path = os .path .abspath (output_path )
159160
161+ if not output_files :
162+ # If -o does not contains file name, set default name
163+ while len (output_files ) < len (output_extensions ):
164+ output_files .append (None )
165+ for i , output_extension in enumerate (output_extensions ):
166+ if output_files [i ] is None or output_files [i ] == "" :
167+ if output_extension == _json_ext :
168+ output_files [i ] = f"fosslight_opossum_src_{ _start_time } "
169+ else :
170+ output_files [i ] = f"fosslight_report_src_{ _start_time } "
171+
160172 if not correct_filepath :
161173 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-
169174 cover = CoverItem (tool_name = _PKG_NAME ,
170175 start_time = _start_time ,
171176 input_path = path_to_scan ,
172177 exclude_path = path_to_exclude )
173178 files_count , removed_files_count = count_files (path_to_scan , path_to_exclude )
174179 cover .comment = f"Total number of files / removed files: { files_count } / { removed_files_count } "
180+
175181 if len (merged_result ) == 0 :
176182 if files_count < 1 :
177183 cover .comment += "(No file detected.)"
@@ -190,7 +196,7 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
190196 extended_header = MERGED_HEADER
191197
192198 if need_license :
193- if selected_scanner == 'scancode' or output_extension == _json_ext :
199+ if selected_scanner == 'scancode' :
194200 sheet_list ["scancode_reference" ] = get_license_list_to_print (license_list )
195201 elif selected_scanner == 'scanoss' :
196202 sheet_list ["scanoss_reference" ] = get_scanoss_extra_info (scanoss_result )
@@ -206,17 +212,19 @@ def create_report_file(_start_time, merged_result, license_list, scanoss_result,
206212 sheet_list = correct_list
207213 logger .info ("Success to correct with yaml." )
208214
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 } ' )
215+ combined_paths_and_files = [os .path .join (output_path , file ) for file in output_files ]
216+ results = []
217+ for combined_path_and_file , output_extension in zip (combined_paths_and_files , output_extensions ):
218+ if need_license and output_extension == _json_ext and "scanoss_reference" in sheet_list :
219+ del sheet_list ["scanoss_reference" ]
220+ results .append (write_output_file (combined_path_and_file , output_extension , sheet_list , extended_header , "" , cover ))
221+ for success , msg , result_file in results :
222+ if success :
223+ logger .info (f"Output file: { result_file } " )
224+ if cover :
225+ logger .info (f'{ cover .comment } ' )
216226 else :
217- logger .warning (f"{ writing_msg } " )
218- else :
219- logger .error (f"Fail to generate result file. msg:({ writing_msg } )" )
227+ logger .error (f"Fail to generate result file { result_file } . msg:({ msg } )" )
220228
221229
222230def merge_results (scancode_result = [], scanoss_result = [], spdx_downloads = {}):
@@ -246,7 +254,7 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
246254
247255
248256def 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 = "" ,
257+ print_matched_text = False , formats = [] , time_out = 120 , correct_mode = True , correct_filepath = "" ,
250258 selected_scanner = 'all' , path_to_exclude = []):
251259 """
252260 Run Scancode and scanoss.py for the given path.
@@ -273,27 +281,29 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
273281 spdx_downloads = {}
274282 result_log = {}
275283
276- success , msg , output_path , output_file , output_extension = check_output_format (output_file_name , format )
284+ success , msg , output_path , output_files , output_extensions = check_output_formats (output_file_name , formats )
285+
277286 logger , result_log = init_log (os .path .join (output_path , f"fosslight_log_src_{ start_time } .txt" ),
278287 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 :
288+
289+ if '.xlsx' not in output_extensions and print_matched_text :
280290 logger .warning ("-m option is only available for excel." )
281291 print_matched_text = False
292+
282293 if success :
283294 if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '' :
284295 success , result_log [RESULT_KEY ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
285296 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 )
297+ print_matched_text , formats , called_by_cli ,
298+ time_out , correct_mode , correct_filepath )
289299 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 )
300+ scanoss_result = run_scanoss_py (path_to_scan , output_file_name , formats , True , write_json_file , num_cores ,
301+ path_to_exclude )
292302 if selected_scanner in SCANNER_TYPE :
293303 spdx_downloads = get_spdx_downloads (path_to_scan , path_to_exclude )
294304 merged_result = merge_results (scancode_result , scanoss_result , spdx_downloads )
295305 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 ,
306+ print_matched_text , output_path , output_files , output_extensions , correct_mode ,
297307 correct_filepath , path_to_scan , path_to_exclude )
298308 else :
299309 print_help_msg_source_scanner ()
@@ -302,7 +312,6 @@ def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_c
302312 else :
303313 result_log [RESULT_KEY ] = f"Format error. { msg } "
304314 success = False
305-
306315 return success , result_log .get (RESULT_KEY , "" ), merged_result , license_list , scanoss_result
307316
308317
0 commit comments