4
4
# SPDX-License-Identifier: Apache-2.0
5
5
6
6
import os
7
- import pkg_resources
7
+ import importlib_metadata
8
8
import warnings
9
9
import logging
10
10
import json
16
16
from ._parsing_scanoss_file import parsing_extraInfo # scanoss
17
17
import shutil
18
18
from pathlib import Path
19
+ from scanoss .scanner import Scanner , ScanType
19
20
20
21
logger = logging .getLogger (constant .LOGGER_NAME )
21
22
warnings .filterwarnings ("ignore" , category = FutureWarning )
22
23
_PKG_NAME = "fosslight_source"
23
24
SCANOSS_RESULT_FILE = "scanner_output.wfp"
24
25
SCANOSS_OUTPUT_FILE = "scanoss_raw_result.json"
25
- SCANOSS_COMMAND_PREFIX = "scanoss-py scan --ignore-cert-errors -o "
26
26
27
27
28
28
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
51
51
52
52
scanoss_file_list = []
53
53
try :
54
- pkg_resources . get_distribution ("scanoss" )
54
+ importlib_metadata . distribution ("scanoss" )
55
55
except Exception as error :
56
56
logger .warning (f"{ error } . Skipping scan with scanoss." )
57
57
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
65
65
Path (output_path ).mkdir (parents = True , exist_ok = True )
66
66
output_json_file = os .path .join (output_path , SCANOSS_OUTPUT_FILE )
67
67
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
-
74
68
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
+
76
78
if os .path .isfile (output_json_file ):
77
79
total_files_to_excluded = []
78
80
if path_to_exclude :
0 commit comments