Skip to content

Commit f1288cc

Browse files
committed
Add the option for correction with sbom-info.yaml
Signed-off-by: Jiyeong Seok <[email protected]>
1 parent fb7c3ab commit f1288cc

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/fosslight_source/_help.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
-s <scanner>\t Select which scanner to be run (scancode, scanoss, all)
2929
-j\t\t\t Generate raw result of scanners in json format
3030
-t <float>\t\t Stop scancode scanning if scanning takes longer than a timeout in seconds.
31-
-c <core>\t\t Select the number of cores to be scanned with ScanCode."""
31+
-c <core>\t\t Select the number of cores to be scanned with ScanCode.
32+
--no_correction\t Enter if you don't want to correct OSS information with sbom-info.yaml
33+
--correct_fpath\t Path to the sbom-info.yaml file"""
3234

3335

3436
def print_version(pkg_name):

src/fosslight_source/cli.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ._help import print_version, print_help_msg_source_scanner
1616
from ._license_matched import get_license_list_to_print
1717
from fosslight_util.output_format import check_output_format, write_output_file
18+
from fosslight_util.correct import correct_with_yaml
1819
from .run_scancode import run_scan
1920
from .run_scanoss import run_scanoss_py
2021
from .run_scanoss import get_scanoss_extra_info
@@ -47,6 +48,9 @@ def main():
4748
print_matched_text = False
4849
format = ""
4950
selected_scanner = ""
51+
correct_mode = True
52+
correct_filepath = os.getcwd()
53+
5054

5155
scanned_result = []
5256
license_list = []
@@ -64,6 +68,8 @@ def main():
6468
parser.add_argument('-s', '--scanner', nargs=1, type=str, required=False, default='all')
6569
parser.add_argument('-t', '--timeout', type=int, required=False, default=120)
6670
parser.add_argument('-c', '--cores', type=int, required=False, default=-1)
71+
parser.add_argument('--no_correction', action='store_true', required=False)
72+
parser.add_argument('--correct_fpath', nargs=1, type=str, required=False)
6773

6874
args = parser.parse_args()
6975

@@ -84,6 +90,10 @@ def main():
8490
format = ''.join(args.format)
8591
if args.scanner:
8692
selected_scanner = ''.join(args.scanner)
93+
if args.no_correction:
94+
correct_mode = False
95+
if args.correct_fpath:
96+
correct_filepath = ''.join(args.correct_fpath)
8797

8898
time_out = args.timeout
8999
core = args.cores
@@ -108,7 +118,8 @@ def main():
108118
success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name,
109119
write_json_file, core, True,
110120
print_matched_text, format, True,
111-
time_out)
121+
time_out, correct_mode,
122+
correct_filepath)
112123
elif selected_scanner == 'scanoss':
113124
scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
114125
elif selected_scanner == 'all' or selected_scanner == '':
@@ -120,7 +131,7 @@ def main():
120131
print_help_msg_source_scanner()
121132
sys.exit(1)
122133
create_report_file(_start_time, scanned_result, license_list, selected_scanner, print_matched_text,
123-
output_path, output_file, output_extension)
134+
output_path, output_file, output_extension, correct_mode, correct_filepath)
124135
try:
125136
logger.info(yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True))
126137
except Exception as ex:
@@ -131,7 +142,7 @@ def main():
131142

132143

133144
def create_report_file(_start_time, scanned_result, license_list, selected_scanner, need_license=False,
134-
output_path="", output_file="", output_extension=""):
145+
output_path="", output_file="", output_extension="", correct_mode=True, correct_filepath=""):
135146
"""
136147
Create report files for given scanned result.
137148
@@ -178,6 +189,14 @@ def create_report_file(_start_time, scanned_result, license_list, selected_scann
178189
sheet_list["scancode_reference"] = get_license_list_to_print(license_list)
179190
sheet_list["scanoss_reference"] = get_scanoss_extra_info(scanned_result)
180191

192+
if correct_mode:
193+
success, msg_correct, correct_list = correct_with_yaml(correct_filepath, sheet_list)
194+
if not success:
195+
logger.info(f"No correction with yaml: {msg_correct}")
196+
else:
197+
sheet_list = correct_list
198+
logger.info("Success to correct with yaml.")
199+
181200
output_file_without_ext = os.path.join(output_path, output_file)
182201
success_to_write, writing_msg, result_file = write_output_file(output_file_without_ext, output_extension,
183202
sheet_list, extended_header)
@@ -216,7 +235,8 @@ def run_all_scanners(path_to_scan, output_file_name="", _write_json_file=False,
216235
success, _result_log["Scan Result"], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
217236
_write_json_file, num_cores,
218237
True, need_license,
219-
format, called_by_cli, time_out)
238+
format, called_by_cli, time_out,
239+
False, "")
220240
scanoss_result = run_scanoss_py(path_to_scan, output_file_name, format, called_by_cli, _write_json_file)
221241

222242
for file_in_scancode_result in scancode_result:

src/fosslight_source/run_scancode.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ._parsing_scancode_file_item import get_error_from_header
1717
from ._license_matched import get_license_list_to_print
1818
from fosslight_util.output_format import check_output_format, write_output_file
19+
from fosslight_util.correct import correct_with_yaml
1920

2021
logger = logging.getLogger(constant.LOGGER_NAME)
2122
warnings.filterwarnings("ignore", category=FutureWarning)
@@ -24,7 +25,7 @@
2425

2526
def run_scan(path_to_scan, output_file_name="",
2627
_write_json_file=False, num_cores=-1, return_results=False, need_license=False, format="",
27-
called_by_cli=False, time_out=120):
28+
called_by_cli=False, time_out=120, correct_mode=True, correct_filepath=""):
2829
if not called_by_cli:
2930
global logger
3031

@@ -100,13 +101,19 @@ def run_scan(path_to_scan, output_file_name="",
100101

101102
output_file_without_ext = os.path.join(output_path, output_file)
102103
if not called_by_cli:
104+
if correct_mode:
105+
success, msg_correct, correct_list = correct_with_yaml(correct_filepath, sheet_list)
106+
if not success:
107+
logger.info(f"No correction with yaml: {msg_correct}")
108+
else:
109+
sheet_list = correct_list
110+
logger.info("Success to correct with yaml.")
103111
success_to_write, writing_msg, result_file = write_output_file(output_file_without_ext,
104112
output_extension, sheet_list)
105113
if success_to_write:
106114
logger.info(f"Writing Output file({result_file}, success:{success_to_write}")
107115
else:
108116
logger.error(f"Fail to generate result file. msg:({writing_msg})")
109-
110117
except Exception as ex:
111118
success = False
112119
msg = str(ex)

0 commit comments

Comments
 (0)