Skip to content

Commit 65011fe

Browse files
authored
Merge pull request #120 from fosslight/sbom_merge
Add to correct with sbom-info.yaml
2 parents 050a65b + bb42c9a commit 65011fe

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ pyparsing<=3.0.4;python_full_version<"3.6.8"
22
scancode-toolkit==31.2.6
33
XlsxWriter
44
typecode-libmagic
5-
fosslight_util>=1.4.0
5+
fosslight_util>=1.4.24
66
PyYAML
77
wheel

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,8 @@ def main():
4748
print_matched_text = False
4849
format = ""
4950
selected_scanner = ""
51+
correct_mode = True
52+
correct_filepath = os.getcwd()
5053

5154
scanned_result = []
5255
license_list = []
@@ -64,6 +67,8 @@ def main():
6467
parser.add_argument('-s', '--scanner', nargs=1, type=str, required=False, default='all')
6568
parser.add_argument('-t', '--timeout', type=int, required=False, default=120)
6669
parser.add_argument('-c', '--cores', type=int, required=False, default=-1)
70+
parser.add_argument('--no_correction', action='store_true', required=False)
71+
parser.add_argument('--correct_fpath', nargs=1, type=str, required=False)
6772

6873
args = parser.parse_args()
6974

@@ -84,6 +89,10 @@ def main():
8489
format = ''.join(args.format)
8590
if args.scanner:
8691
selected_scanner = ''.join(args.scanner)
92+
if args.no_correction:
93+
correct_mode = False
94+
if args.correct_fpath:
95+
correct_filepath = ''.join(args.correct_fpath)
8796

8897
time_out = args.timeout
8998
core = args.cores
@@ -108,7 +117,8 @@ def main():
108117
success, _result_log["Scan Result"], scanned_result, license_list = run_scan(path_to_scan, output_file_name,
109118
write_json_file, core, True,
110119
print_matched_text, format, True,
111-
time_out)
120+
time_out, correct_mode,
121+
correct_filepath)
112122
elif selected_scanner == 'scanoss':
113123
scanned_result = run_scanoss_py(path_to_scan, output_file_name, format, True, write_json_file)
114124
elif selected_scanner == 'all' or selected_scanner == '':
@@ -120,7 +130,7 @@ def main():
120130
print_help_msg_source_scanner()
121131
sys.exit(1)
122132
create_report_file(_start_time, scanned_result, license_list, selected_scanner, print_matched_text,
123-
output_path, output_file, output_extension)
133+
output_path, output_file, output_extension, correct_mode, correct_filepath, path_to_scan)
124134
try:
125135
logger.info(yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True))
126136
except Exception as ex:
@@ -131,7 +141,8 @@ def main():
131141

132142

133143
def create_report_file(_start_time, scanned_result, license_list, selected_scanner, need_license=False,
134-
output_path="", output_file="", output_extension=""):
144+
output_path="", output_file="", output_extension="", correct_mode=True, correct_filepath="",
145+
path_to_scan=""):
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, path_to_scan, 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: 10 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,20 @@ 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,
106+
path_to_scan, sheet_list)
107+
if not success:
108+
logger.info(f"No correction with yaml: {msg_correct}")
109+
else:
110+
sheet_list = correct_list
111+
logger.info("Success to correct with yaml.")
103112
success_to_write, writing_msg, result_file = write_output_file(output_file_without_ext,
104113
output_extension, sheet_list)
105114
if success_to_write:
106115
logger.info(f"Writing Output file({result_file}, success:{success_to_write}")
107116
else:
108117
logger.error(f"Fail to generate result file. msg:({writing_msg})")
109-
110118
except Exception as ex:
111119
success = False
112120
msg = str(ex)

0 commit comments

Comments
 (0)