From 5dad9d46ddec814db286645f42c533c6023ecac6 Mon Sep 17 00:00:00 2001 From: Soim Kim Date: Sun, 26 Jun 2022 22:49:59 +0900 Subject: [PATCH] Add option for time out --- src/fosslight_source/_help.py | 18 +++++++++--------- src/fosslight_source/cli.py | 15 ++++++++++----- src/fosslight_source/run_scancode.py | 7 +++++-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/fosslight_source/_help.py b/src/fosslight_source/_help.py index 8007d6d..4bc8709 100644 --- a/src/fosslight_source/_help.py +++ b/src/fosslight_source/_help.py @@ -15,17 +15,17 @@ Options: Mandatory - -p \t\t Path to analyze source + -p \t Path to analyze source Optional - -h\t\t\t\t Print help message - -v\t\t\t\t Print FOSSLight Source Scanner version - -j\t\t\t\t Generate raw result of scanners in json format - -m\t\t\t\t Print additional information for scan result on separate sheets - -o \t\t Output path - \t\t\t\t (If you want to generate the specific file name, add the output path with file name.) - -f \t\t\t Output file format (excel, csv, opossum, yaml) - -s \t\t Select which scanner to be run (scancode, scanoss, all)""" + -h\t\t\t Print help message + -v\t\t\t Print FOSSLight Source Scanner version + -j\t\t\t Generate raw result of scanners in json format + -m\t\t\t Print additional information for scan result on separate sheets + -o \t Output path (Path or file name) + -f \t\t Output file format (excel, csv, opossum, yaml) + -s \t Select which scanner to be run (scancode, scanoss, all) + -t \t\t Stop scancode scanning if scanning takes longer than a timeout in seconds.""" _HELP_MESSAGE_CONVERT = """ Usage: fosslight_convert [option1] [option2] ... diff --git a/src/fosslight_source/cli.py b/src/fosslight_source/cli.py index 8b74e71..2f56c13 100755 --- a/src/fosslight_source/cli.py +++ b/src/fosslight_source/cli.py @@ -50,9 +50,10 @@ def main(): scanned_result = [] license_list = [] + time_out = 120 try: - opts, args = getopt.getopt(argv, 'hvmjs:p:o:f:') + opts, args = getopt.getopt(argv, 'hvmjs:p:o:f:t:') for opt, arg in opts: if opt == "-h": print_help_msg_source() @@ -70,6 +71,8 @@ def main(): format = arg elif opt == "-s": selected_scanner = arg.lower() + elif opt == "-t": + time_out = arg except Exception: print_help_msg_source() @@ -90,13 +93,15 @@ def main(): if selected_scanner == 'scancode': success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name, write_json_file, -1, True, - print_matched_text, format, True) + print_matched_text, format, True, + time_out) elif selected_scanner == 'scanoss': scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file) elif selected_scanner == 'all' or selected_scanner == '': success, _result_log["Scan Result"], scanned_result, license_list = run_all_scanners(path_to_scan, output_file_name, write_json_file, -1, - print_matched_text, format, True) + print_matched_text, format, True, + time_out) else: print_help_msg_source() sys.exit(1) @@ -167,7 +172,7 @@ def create_report_file(start_time, scanned_result, license_list, selected_scanne def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False, num_cores=-1, - need_license=False, format="", called_by_cli=True): + need_license=False, format="", called_by_cli=True, time_out=120): """ Run Scancode and scanoss.py for the given path. @@ -192,7 +197,7 @@ def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False, success, _result_log["Scan Result"], scancode_result, license_list = run_scan(path_to_scan, output_file_name, _write_json_file, num_cores, True, need_license, - format, called_by_cli) + format, called_by_cli, time_out) scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, called_by_cli, _write_json_file) for file_in_scancode_result in scancode_result: diff --git a/src/fosslight_source/run_scancode.py b/src/fosslight_source/run_scancode.py index cd4c771..08edf8c 100755 --- a/src/fosslight_source/run_scancode.py +++ b/src/fosslight_source/run_scancode.py @@ -23,7 +23,8 @@ def run_scan(path_to_scan, output_file_name="", - _write_json_file=False, num_cores=-1, return_results=False, need_license=False, format="", called_by_cli=False): + _write_json_file=False, num_cores=-1, return_results=False, need_license=False, format="", + called_by_cli=False, time_out=120): if not called_by_cli: global logger @@ -67,12 +68,14 @@ def run_scan(path_to_scan, output_file_name="", if os.path.isdir(path_to_scan): try: + time_out = float(time_out) rc, results = cli.run_scan(path_to_scan, max_depth=100, strip_root=True, license=True, copyright=True, return_results=True, processes=num_cores, output_json_pp=output_json_file, - only_findings=True, license_text=True) + only_findings=True, license_text=True, + timeout=time_out) if not rc: msg = "Source code analysis failed."