3939
4040def main ():
4141 global logger
42- success = True
4342 _result_log = {}
4443
4544 path_to_scan = os .getcwd ()
@@ -50,8 +49,6 @@ def main():
5049 selected_scanner = ""
5150 correct_mode = True
5251
53- license_list = []
54- scanoss_result = []
5552 time_out = 120
5653 core = - 1
5754
@@ -101,39 +98,11 @@ def main():
10198 timer .setDaemon (True )
10299 timer .start ()
103100
104- _start_time = datetime .now ().strftime ('%y%m%d_%H%M' )
105- success , msg , output_path , output_file , output_extension = check_output_format (output_file_name , format )
106- if output_extension != '.xlsx' and output_extension != "" and print_matched_text :
107- logger .warning ("-m option is only available for excel." )
108- print_matched_text = False
109- if not success :
110- logger .error (f"Format error. { msg } " )
111- sys .exit (1 )
112- logger , _result_log = init_log (os .path .join (output_path , f"fosslight_log_src_{ _start_time } .txt" ),
113- True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_scan )
114-
115101 if os .path .isdir (path_to_scan ):
116- scancode_result = []
117- scanoss_result = []
118- merged_result = []
119- spdx_downloads = {}
120- success = True
121-
122- if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '' :
123- success , _result_log ["Scan Result" ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
124- write_json_file , core , True ,
125- print_matched_text , format , True ,
126- time_out , correct_mode ,
127- correct_filepath )
128- if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '' :
129- scanoss_result = run_scanoss_py (path_to_scan , output_file_name , format , True , write_json_file )
130- if selected_scanner not in SCANNER_TYPE :
131- print_help_msg_source_scanner ()
132- sys .exit (1 )
133- spdx_downloads = get_spdx_downloads (path_to_scan )
134- merged_result = merge_results (scancode_result , scanoss_result , spdx_downloads )
135- create_report_file (_start_time , merged_result , license_list , scanoss_result , selected_scanner , print_matched_text ,
136- output_path , output_file , output_extension , correct_mode , correct_filepath , path_to_scan )
102+ result = []
103+ result = run_scanners (path_to_scan , output_file_name , write_json_file , core , True ,
104+ print_matched_text , format , time_out , correct_mode , correct_filepath , selected_scanner )
105+ _result_log ["Scan Result" ] = result [1 ]
137106
138107 try :
139108 logger .info (yaml .safe_dump (_result_log , allow_unicode = True , sort_keys = True ))
@@ -249,5 +218,61 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}):
249218 return scancode_result
250219
251220
221+ def run_scanners (path_to_scan , output_file_name = "" , _write_json_file = False , num_cores = - 1 , called_by_cli = True ,
222+ print_matched_text = False , format = "" , time_out = 120 , correct_mode = True , correct_filepath = "" ,
223+ selected_scanner = 'all' ):
224+ """
225+ Run Scancode and scanoss.py for the given path.
226+
227+ :param path_to_scan: path of sourcecode to scan.
228+ :param output_file_name: path or file name (with path) for the output.
229+ :param _write_json_file: if requested, keep the raw files.
230+ :param num_cores: number of cores used for scancode scanning.
231+ :param called_by_cli: if not called by cli, initialize logger.
232+ :param print_matched_text: if requested, output matched text (only for scancode).
233+ :param format: output format (excel, csv, opossum).
234+ :return success: success or failure of scancode.
235+ :return _result_log["Scan Result"]:
236+ :return merged_result: merged scan result of scancode and scanoss.
237+ :return license_list: matched text.(only for scancode)
238+ """
239+ global logger
240+
241+ _start_time = datetime .now ().strftime ('%y%m%d_%H%M' )
242+ scancode_result = []
243+ scanoss_result = []
244+ merged_result = []
245+ spdx_downloads = {}
246+
247+ success , msg , output_path , output_file , output_extension = check_output_format (output_file_name , format )
248+ if output_extension != '.xlsx' and output_extension != "" and print_matched_text :
249+ logger .warning ("-m option is only available for excel." )
250+ print_matched_text = False
251+ if not success :
252+ logger .error (f"Format error. { msg } " )
253+ sys .exit (1 )
254+ logger , _result_log = init_log (os .path .join (output_path , f"fosslight_log_src_{ _start_time } .txt" ),
255+ True , logging .INFO , logging .DEBUG , _PKG_NAME , path_to_scan )
256+
257+ if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '' :
258+ success , _result_log ["Scan Result" ], scancode_result , license_list = run_scan (path_to_scan , output_file_name ,
259+ _write_json_file , num_cores , True ,
260+ print_matched_text , format , called_by_cli ,
261+ time_out , correct_mode , correct_filepath )
262+ if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '' :
263+ scanoss_result = run_scanoss_py (path_to_scan , output_file_name , format , True , _write_json_file )
264+ if selected_scanner not in SCANNER_TYPE :
265+ print_help_msg_source_scanner ()
266+ sys .exit (1 )
267+
268+ spdx_downloads = get_spdx_downloads (path_to_scan )
269+ merged_result = merge_results (scancode_result , scanoss_result , spdx_downloads )
270+
271+ create_report_file (_start_time , merged_result , license_list , scanoss_result , selected_scanner , print_matched_text ,
272+ output_path , output_file , output_extension , correct_mode , correct_filepath , path_to_scan )
273+
274+ return success , _result_log ["Scan Result" ], merged_result , license_list , scanoss_result
275+
276+
252277if __name__ == '__main__' :
253278 main ()
0 commit comments