Skip to content

Commit 55b1430

Browse files
committed
Support yaml format of FOSSLight Report
Signed-off-by: Jiyeong Seok <[email protected]>
1 parent 673ae74 commit 55b1430

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

src/fosslight_scanner/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
from shutil import copy
1010
import re
1111
import pandas as pd
12+
import yaml
1213
import fosslight_util.constant as constant
14+
from fosslight_util.parsing_yaml import parsing_yml
15+
from fosslight_util.write_yaml import create_yaml_with_ossitem
1316

1417
logger = logging.getLogger(constant.LOGGER_NAME)
1518

@@ -154,3 +157,30 @@ def overwrite_excel(excel_file_path, oss_name, column_name='OSS Name'):
154157
logger.debug(f"overwrite_sheet {sheet_name}:{ex}")
155158
except Exception as ex:
156159
logger.debug(f"overwrite_excel:{ex}")
160+
161+
162+
def merge_yamls(_output_dir, merge_yaml_files, final_report):
163+
success = True
164+
err_msg = ''
165+
166+
oss_total_list = []
167+
yaml_dict = {}
168+
try:
169+
for mf in merge_yaml_files:
170+
if os.path.exists(os.path.join(_output_dir, mf)):
171+
oss_list, license_list = parsing_yml(os.path.join(_output_dir, mf), _output_dir)
172+
oss_total_list.extend(oss_list)
173+
174+
if oss_total_list != []:
175+
for oi in oss_total_list:
176+
create_yaml_with_ossitem(oi, yaml_dict)
177+
with open(os.path.join(_output_dir, final_report), 'w') as f:
178+
yaml.dump(yaml_dict, f, default_flow_style=False, sort_keys=False)
179+
else:
180+
success = False
181+
err_msg = "Output file is not created as no oss items detected."
182+
except Exception as ex:
183+
err_msg = ex
184+
success = False
185+
186+
return success, err_msg

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from fosslight_util.output_format import check_output_format
2323
from fosslight_reuse._fosslight_reuse import run_lint as reuse_lint
2424
from .common import (copy_file, call_analysis_api,
25-
overwrite_excel, extract_name_from_link)
25+
overwrite_excel, extract_name_from_link,
26+
merge_yamls)
2627
from fosslight_util.write_excel import merge_excels
2728
from ._run_compare import run_compare
2829
import subprocess
@@ -125,10 +126,10 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
125126
abs_path = os.path.abspath(src_path)
126127

127128
if success:
128-
output_files = {"SRC": "FL_Source.xlsx",
129-
"BIN": "FL_Binary.xlsx",
129+
output_files = {"SRC": f"FL_Source{output_extension}",
130+
"BIN": f"FL_Binary{output_extension}",
130131
"BIN_TXT": "FL_Binary.txt",
131-
"DEP": "FL_Dependency.xlsx",
132+
"DEP": f"FL_Dependency{output_extension}",
132133
"REUSE": "FL_Reuse.yaml"}
133134
if run_reuse:
134135
output_reuse = os.path.join(_output_dir, output_files["REUSE"])
@@ -151,7 +152,9 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
151152
False, num_cores, True)
152153
if success:
153154
sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result[2]]
154-
create_report_file(0, result[2], result[3], 'all', True, _output_dir, output_files["SRC"], "")
155+
need_license = True if output_extension == ".xlsx" else False
156+
create_report_file(0, result[2], result[3], 'all', need_license,
157+
_output_dir, output_files["SRC"].split('.')[0], output_extension)
155158
else: # Run fosslight_source by using docker image
156159
src_output = os.path.join("output", output_files["SRC"])
157160
output_rel_path = os.path.relpath(abs_path, os.getcwd())
@@ -186,10 +189,14 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
186189
try:
187190
output_file_without_ext = os.path.join(final_excel_dir, output_file)
188191
final_report = f"{output_file_without_ext}{output_extension}"
189-
if remove_src_data:
190-
overwrite_excel(_output_dir, default_oss_name, "OSS Name")
191-
overwrite_excel(_output_dir, url, "Download Location")
192-
success, err_msg = merge_excels(_output_dir, final_report)
192+
if output_extension == ".xlsx":
193+
if remove_src_data:
194+
overwrite_excel(_output_dir, default_oss_name, "OSS Name")
195+
overwrite_excel(_output_dir, url, "Download Location")
196+
success, err_msg = merge_excels(_output_dir, final_report)
197+
elif output_extension == ".yaml":
198+
merge_yaml_files = [output_files["SRC"], output_files["BIN"], output_files["DEP"]]
199+
success, err_msg = merge_yamls(_output_dir, merge_yaml_files, final_report)
193200

194201
if success:
195202
result_log["Output File"] = final_report

0 commit comments

Comments
 (0)