|
35 | 35 | logger = logging.getLogger(constant.LOGGER_NAME) |
36 | 36 | warnings.filterwarnings("ignore", category=FutureWarning) |
37 | 37 | _PKG_NAME = "fosslight_source" |
| 38 | +RESULT_KEY = "Scan Result" |
38 | 39 |
|
39 | 40 |
|
40 | 41 | def main(): |
@@ -218,60 +219,63 @@ def merge_results(scancode_result=[], scanoss_result=[], spdx_downloads={}): |
218 | 219 | return scancode_result |
219 | 220 |
|
220 | 221 |
|
221 | | -def run_scanners(path_to_scan, output_file_name="", _write_json_file=False, num_cores=-1, called_by_cli=True, |
| 222 | +def run_scanners(path_to_scan, output_file_name="", write_json_file=False, num_cores=-1, called_by_cli=True, |
222 | 223 | print_matched_text=False, format="", time_out=120, correct_mode=True, correct_filepath="", |
223 | 224 | selected_scanner='all'): |
224 | 225 | """ |
225 | 226 | Run Scancode and scanoss.py for the given path. |
226 | 227 |
|
227 | 228 | :param path_to_scan: path of sourcecode to scan. |
228 | 229 | :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 write_json_file: if requested, keep the raw files. |
230 | 231 | :param num_cores: number of cores used for scancode scanning. |
231 | 232 | :param called_by_cli: if not called by cli, initialize logger. |
232 | 233 | :param print_matched_text: if requested, output matched text (only for scancode). |
233 | 234 | :param format: output format (excel, csv, opossum). |
234 | 235 | :return success: success or failure of scancode. |
235 | | - :return _result_log["Scan Result"]: |
| 236 | + :return result_log["Scan Result"]: |
236 | 237 | :return merged_result: merged scan result of scancode and scanoss. |
237 | 238 | :return license_list: matched text.(only for scancode) |
238 | 239 | """ |
239 | 240 | global logger |
240 | 241 |
|
241 | | - _start_time = datetime.now().strftime('%y%m%d_%H%M') |
| 242 | + start_time = datetime.now().strftime('%y%m%d_%H%M') |
242 | 243 | scancode_result = [] |
243 | 244 | scanoss_result = [] |
244 | 245 | merged_result = [] |
245 | 246 | spdx_downloads = {} |
| 247 | + result_log = {} |
246 | 248 |
|
247 | 249 | 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: |
| 250 | + logger, result_log = init_log(os.path.join(output_path, f"fosslight_log_src_{start_time}.txt"), |
| 251 | + True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan) |
| 252 | + if output_extension != '.xlsx' and output_extension and print_matched_text: |
249 | 253 | logger.warning("-m option is only available for excel.") |
250 | 254 | 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, |
| 255 | + if success: |
| 256 | + if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '': |
| 257 | + success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name, |
| 258 | + write_json_file, num_cores, True, |
260 | 259 | print_matched_text, format, called_by_cli, |
261 | 260 | 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) |
| 261 | + if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '': |
| 262 | + scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file) |
| 263 | + if selected_scanner in SCANNER_TYPE: |
| 264 | + spdx_downloads = get_spdx_downloads(path_to_scan) |
| 265 | + merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads) |
| 266 | + |
| 267 | + create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner, print_matched_text, |
| 268 | + output_path, output_file, output_extension, correct_mode, correct_filepath, path_to_scan) |
| 269 | + else: |
| 270 | + print_help_msg_source_scanner() |
| 271 | + result_log[RESULT_KEY] = "Unsupported scanner" |
| 272 | + success = False |
| 273 | + else: |
| 274 | + result_log[RESULT_KEY] = f"Format error. {msg}" |
| 275 | + logger.error(f"Format error. {msg}") |
| 276 | + success = False |
273 | 277 |
|
274 | | - return success, _result_log["Scan Result"], merged_result, license_list, scanoss_result |
| 278 | + return success, result_log.get(RESULT_KEY, ""), merged_result, license_list, scanoss_result |
275 | 279 |
|
276 | 280 |
|
277 | 281 | if __name__ == '__main__': |
|
0 commit comments