Skip to content

Commit 9f3e75b

Browse files
Update SCANOSS version and redirect log (#204)
* change minimum SCANOSS version to 1.18.0 Signed-off-by: Wonjae Park <[email protected]> * Redirect SCANOSS output to log file Signed-off-by: Wonjae Park <[email protected]> * Add comment on info sheet for limit exceed Signed-off-by: Wonjae Park <[email protected]> * Fix flake8 fail Signed-off-by: Wonjae Park <[email protected]> --------- Signed-off-by: Wonjae Park <[email protected]>
1 parent da2fe03 commit 9f3e75b

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pyparsing
2-
scanoss<=1.14.0
2+
scanoss>=1.18.0
33
XlsxWriter
44
fosslight_util>=2.1.10
55
PyYAML

src/fosslight_source/cli.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def create_report_file(
148148
output_path: str = "", output_files: list = [],
149149
output_extensions: list = [], correct_mode: bool = True,
150150
correct_filepath: str = "", path_to_scan: str = "", path_to_exclude: list = [],
151-
formats: list = [], excluded_file_list: list = []
151+
formats: list = [], excluded_file_list: list = [], api_limit_exceed: bool = False
152152
) -> 'ScannerItem':
153153
"""
154154
Create report files for given scanned result.
@@ -212,6 +212,9 @@ def create_report_file(
212212
scan_item.set_cover_comment(f"Total number of files : {files_count}")
213213
scan_item.set_cover_comment(f"Removed files : {removed_files_count}")
214214

215+
if api_limit_exceed:
216+
scan_item.set_cover_comment("(Some of) SCANOSS scan was skipped. (API limits being exceeded)")
217+
215218
if not merged_result:
216219
if files_count < 1:
217220
scan_item.set_cover_comment("(No file detected.)")
@@ -350,14 +353,15 @@ def run_scanners(
350353
print_matched_text, formats, called_by_cli,
351354
time_out, correct_mode, correct_filepath)
352355
if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
353-
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores,
354-
path_to_exclude)
356+
scanoss_result, api_limit_exceed = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file,
357+
num_cores, path_to_exclude)
355358
if selected_scanner in SCANNER_TYPE:
356359
spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
357360
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
358361
scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
359362
print_matched_text, output_path, output_files, output_extensions, correct_mode,
360-
correct_filepath, path_to_scan, path_to_exclude, formats, excluded_file_list)
363+
correct_filepath, path_to_scan, path_to_exclude, formats, excluded_file_list,
364+
api_limit_exceed)
361365
else:
362366
print_help_msg_source_scanner()
363367
result_log[RESULT_KEY] = "Unsupported scanner"

src/fosslight_source/run_scanoss.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import shutil
1818
from pathlib import Path
1919
from scanoss.scanner import Scanner, ScanType
20+
import io
21+
import contextlib
2022

2123
logger = logging.getLogger(constant.LOGGER_NAME)
2224
warnings.filterwarnings("ignore", category=FutureWarning)
@@ -75,7 +77,13 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list =
7577
scan_options=ScanType.SCAN_SNIPPETS.value,
7678
nb_threads=num_threads if num_threads > 0 else 10
7779
)
78-
scanner.scan_folder_with_options(scan_dir=path_to_scan)
80+
81+
output_buffer = io.StringIO()
82+
with contextlib.redirect_stdout(output_buffer), contextlib.redirect_stderr(output_buffer):
83+
scanner.scan_folder_with_options(scan_dir=path_to_scan)
84+
captured_output = output_buffer.getvalue()
85+
api_limit_exceed = "due to service limits being exceeded" in captured_output
86+
logger.debug(f"{captured_output}")
7987

8088
if os.path.isfile(output_json_file):
8189
total_files_to_excluded = []
@@ -117,4 +125,4 @@ def run_scanoss_py(path_to_scan: str, output_file_name: str = "", format: list =
117125
except Exception as error:
118126
logger.debug(f"Moving scanoss raw files failed.: {error}")
119127

120-
return scanoss_file_list
128+
return scanoss_file_list, api_limit_exceed

tests/cli_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
logger, result_item = init_log(os.path.join(output_dir, "fosslight_log_"+_start_time+".txt"))
2727

2828
ret = run_scan(path_to_find_bin, fosslight_report_name, True, -1, True, True, [], False)
29-
ret_scanoss = run_scanoss_py(path_to_find_bin, fosslight_report_name, [], False, True, -1)
29+
ret_scanoss, api_limit_exceed = run_scanoss_py(path_to_find_bin, fosslight_report_name, [], False, True, -1)
3030

3131
logger.warning("[Scan] Result: %s" % (ret[0]))
3232
logger.warning("[Scan] Result_msg: %s" % (ret[1]))

0 commit comments

Comments
 (0)