Skip to content

Commit

Permalink
Support yaml format of FOSSLight Report
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyeong Seok <jiyeong.seok@lge.com>
  • Loading branch information
dd-jy committed Jul 28, 2022
1 parent 673ae74 commit 55b1430
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
30 changes: 30 additions & 0 deletions src/fosslight_scanner/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from shutil import copy
import re
import pandas as pd
import yaml
import fosslight_util.constant as constant
from fosslight_util.parsing_yaml import parsing_yml
from fosslight_util.write_yaml import create_yaml_with_ossitem

logger = logging.getLogger(constant.LOGGER_NAME)

Expand Down Expand Up @@ -154,3 +157,30 @@ def overwrite_excel(excel_file_path, oss_name, column_name='OSS Name'):
logger.debug(f"overwrite_sheet {sheet_name}:{ex}")
except Exception as ex:
logger.debug(f"overwrite_excel:{ex}")


def merge_yamls(_output_dir, merge_yaml_files, final_report):
success = True
err_msg = ''

oss_total_list = []
yaml_dict = {}
try:
for mf in merge_yaml_files:
if os.path.exists(os.path.join(_output_dir, mf)):
oss_list, license_list = parsing_yml(os.path.join(_output_dir, mf), _output_dir)
oss_total_list.extend(oss_list)

if oss_total_list != []:
for oi in oss_total_list:
create_yaml_with_ossitem(oi, yaml_dict)
with open(os.path.join(_output_dir, final_report), 'w') as f:
yaml.dump(yaml_dict, f, default_flow_style=False, sort_keys=False)
else:
success = False
err_msg = "Output file is not created as no oss items detected."
except Exception as ex:
err_msg = ex
success = False

return success, err_msg
25 changes: 16 additions & 9 deletions src/fosslight_scanner/fosslight_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from fosslight_util.output_format import check_output_format
from fosslight_reuse._fosslight_reuse import run_lint as reuse_lint
from .common import (copy_file, call_analysis_api,
overwrite_excel, extract_name_from_link)
overwrite_excel, extract_name_from_link,
merge_yamls)
from fosslight_util.write_excel import merge_excels
from ._run_compare import run_compare
import subprocess
Expand Down Expand Up @@ -125,10 +126,10 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
abs_path = os.path.abspath(src_path)

if success:
output_files = {"SRC": "FL_Source.xlsx",
"BIN": "FL_Binary.xlsx",
output_files = {"SRC": f"FL_Source{output_extension}",
"BIN": f"FL_Binary{output_extension}",
"BIN_TXT": "FL_Binary.txt",
"DEP": "FL_Dependency.xlsx",
"DEP": f"FL_Dependency{output_extension}",
"REUSE": "FL_Reuse.yaml"}
if run_reuse:
output_reuse = os.path.join(_output_dir, output_files["REUSE"])
Expand All @@ -151,7 +152,9 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
False, num_cores, True)
if success:
sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result[2]]
create_report_file(0, result[2], result[3], 'all', True, _output_dir, output_files["SRC"], "")
need_license = True if output_extension == ".xlsx" else False
create_report_file(0, result[2], result[3], 'all', need_license,
_output_dir, output_files["SRC"].split('.')[0], output_extension)
else: # Run fosslight_source by using docker image
src_output = os.path.join("output", output_files["SRC"])
output_rel_path = os.path.relpath(abs_path, os.getcwd())
Expand Down Expand Up @@ -186,10 +189,14 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
try:
output_file_without_ext = os.path.join(final_excel_dir, output_file)
final_report = f"{output_file_without_ext}{output_extension}"
if remove_src_data:
overwrite_excel(_output_dir, default_oss_name, "OSS Name")
overwrite_excel(_output_dir, url, "Download Location")
success, err_msg = merge_excels(_output_dir, final_report)
if output_extension == ".xlsx":
if remove_src_data:
overwrite_excel(_output_dir, default_oss_name, "OSS Name")
overwrite_excel(_output_dir, url, "Download Location")
success, err_msg = merge_excels(_output_dir, final_report)
elif output_extension == ".yaml":
merge_yaml_files = [output_files["SRC"], output_files["BIN"], output_files["DEP"]]
success, err_msg = merge_yamls(_output_dir, merge_yaml_files, final_report)

if success:
result_log["Output File"] = final_report
Expand Down

0 comments on commit 55b1430

Please sign in to comment.