Skip to content

Commit 32deddd

Browse files
authored
Change SCANOSS from command to library function (#178)
Signed-off-by: yongjunhong <[email protected]>
1 parent 83be68f commit 32deddd

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Diff for: src/fosslight_source/run_scanoss.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
import os
7-
import pkg_resources
7+
import importlib_metadata
88
import warnings
99
import logging
1010
import json
@@ -16,13 +16,13 @@
1616
from ._parsing_scanoss_file import parsing_extraInfo # scanoss
1717
import shutil
1818
from pathlib import Path
19+
from scanoss.scanner import Scanner, ScanType
1920

2021
logger = logging.getLogger(constant.LOGGER_NAME)
2122
warnings.filterwarnings("ignore", category=FutureWarning)
2223
_PKG_NAME = "fosslight_source"
2324
SCANOSS_RESULT_FILE = "scanner_output.wfp"
2425
SCANOSS_OUTPUT_FILE = "scanoss_raw_result.json"
25-
SCANOSS_COMMAND_PREFIX = "scanoss-py scan --ignore-cert-errors -o "
2626

2727

2828
def get_scanoss_extra_info(scanned_result):
@@ -51,7 +51,7 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
5151

5252
scanoss_file_list = []
5353
try:
54-
pkg_resources.get_distribution("scanoss")
54+
importlib_metadata.distribution("scanoss")
5555
except Exception as error:
5656
logger.warning(f"{error}. Skipping scan with scanoss.")
5757
logger.warning("Please install scanoss and dataclasses before run fosslight_source with scanoss option.")
@@ -65,14 +65,16 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
6565
Path(output_path).mkdir(parents=True, exist_ok=True)
6666
output_json_file = os.path.join(output_path, SCANOSS_OUTPUT_FILE)
6767

68-
scan_command = f"{SCANOSS_COMMAND_PREFIX} {output_json_file} {path_to_scan}"
69-
if num_threads > 0:
70-
scan_command += " -T " + str(num_threads)
71-
else:
72-
scan_command += " -T " + "10"
73-
7468
try:
75-
os.system(scan_command)
69+
scanner = Scanner(
70+
ignore_cert_errors=True,
71+
skip_folders=path_to_exclude,
72+
scan_output=output_json_file,
73+
scan_options=ScanType.SCAN_SNIPPETS.value,
74+
nb_threads=num_threads if num_threads > 0 else 10
75+
)
76+
scanner.scan_folder_with_options(scan_dir=path_to_scan)
77+
7678
if os.path.isfile(output_json_file):
7779
total_files_to_excluded = []
7880
if path_to_exclude:

0 commit comments

Comments
 (0)