Skip to content

Commit a2b4ad9

Browse files
authored
Merge pull request #79 from fosslight/develop
Add option for time out
2 parents 4cbf660 + 5dad9d4 commit a2b4ad9

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/fosslight_source/_help.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
1616
Options:
1717
Mandatory
18-
-p <source_path>\t\t Path to analyze source
18+
-p <source_path>\t Path to analyze source
1919
2020
Optional
21-
-h\t\t\t\t Print help message
22-
-v\t\t\t\t Print FOSSLight Source Scanner version
23-
-j\t\t\t\t Generate raw result of scanners in json format
24-
-m\t\t\t\t Print additional information for scan result on separate sheets
25-
-o <output_path>\t\t Output path
26-
\t\t\t\t (If you want to generate the specific file name, add the output path with file name.)
27-
-f <format>\t\t\t Output file format (excel, csv, opossum, yaml)
28-
-s <scanner>\t\t Select which scanner to be run (scancode, scanoss, all)"""
21+
-h\t\t\t Print help message
22+
-v\t\t\t Print FOSSLight Source Scanner version
23+
-j\t\t\t Generate raw result of scanners in json format
24+
-m\t\t\t Print additional information for scan result on separate sheets
25+
-o <output_path>\t Output path (Path or file name)
26+
-f <format>\t\t Output file format (excel, csv, opossum, yaml)
27+
-s <scanner>\t Select which scanner to be run (scancode, scanoss, all)
28+
-t <float>\t\t Stop scancode scanning if scanning takes longer than a timeout in seconds."""
2929

3030
_HELP_MESSAGE_CONVERT = """
3131
Usage: fosslight_convert [option1] <arg1> [option2] <arg2>...

src/fosslight_source/cli.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ def main():
5050

5151
scanned_result = []
5252
license_list = []
53+
time_out = 120
5354

5455
try:
55-
opts, args = getopt.getopt(argv, 'hvmjs:p:o:f:')
56+
opts, args = getopt.getopt(argv, 'hvmjs:p:o:f:t:')
5657
for opt, arg in opts:
5758
if opt == "-h":
5859
print_help_msg_source()
@@ -70,6 +71,8 @@ def main():
7071
format = arg
7172
elif opt == "-s":
7273
selected_scanner = arg.lower()
74+
elif opt == "-t":
75+
time_out = arg
7376
except Exception:
7477
print_help_msg_source()
7578

@@ -90,13 +93,15 @@ def main():
9093
if selected_scanner == 'scancode':
9194
success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name,
9295
write_json_file, -1, True,
93-
print_matched_text, format, True)
96+
print_matched_text, format, True,
97+
time_out)
9498
elif selected_scanner == 'scanoss':
9599
scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
96100
elif selected_scanner == 'all' or selected_scanner == '':
97101
success, _result_log["Scan Result"], scanned_result, license_list = run_all_scanners(path_to_scan, output_file_name,
98102
write_json_file, -1,
99-
print_matched_text, format, True)
103+
print_matched_text, format, True,
104+
time_out)
100105
else:
101106
print_help_msg_source()
102107
sys.exit(1)
@@ -167,7 +172,7 @@ def create_report_file(start_time, scanned_result, license_list, selected_scanne
167172

168173

169174
def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False, num_cores=-1,
170-
need_license=False, format="", called_by_cli=True):
175+
need_license=False, format="", called_by_cli=True, time_out=120):
171176
"""
172177
Run Scancode and scanoss.py for the given path.
173178
@@ -192,7 +197,7 @@ def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False,
192197
success, _result_log["Scan Result"], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
193198
_write_json_file, num_cores,
194199
True, need_license,
195-
format, called_by_cli)
200+
format, called_by_cli, time_out)
196201
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, called_by_cli, _write_json_file)
197202

198203
for file_in_scancode_result in scancode_result:

src/fosslight_source/run_scancode.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424

2525
def run_scan(path_to_scan, output_file_name="",
26-
_write_json_file=False, num_cores=-1, return_results=False, need_license=False, format="", called_by_cli=False):
26+
_write_json_file=False, num_cores=-1, return_results=False, need_license=False, format="",
27+
called_by_cli=False, time_out=120):
2728
if not called_by_cli:
2829
global logger
2930

@@ -67,12 +68,14 @@ def run_scan(path_to_scan, output_file_name="",
6768

6869
if os.path.isdir(path_to_scan):
6970
try:
71+
time_out = float(time_out)
7072
rc, results = cli.run_scan(path_to_scan, max_depth=100,
7173
strip_root=True, license=True,
7274
copyright=True, return_results=True,
7375
processes=num_cores,
7476
output_json_pp=output_json_file,
75-
only_findings=True, license_text=True)
77+
only_findings=True, license_text=True,
78+
timeout=time_out)
7679

7780
if not rc:
7881
msg = "Source code analysis failed."

0 commit comments

Comments
 (0)