44# SPDX-License-Identifier: GPL-3.0-only
55import logging
66import os
7+ import sys
78import yaml
89from fosslight_util .constant import LOGGER_NAME
910from fosslight_util .parsing_yaml import find_all_oss_pkg_files , parsing_yml
10- from fosslight_util .write_excel import write_result_to_excel , write_result_to_csv
11+ from fosslight_util .write_excel import write_result_to_excel
1112from fosslight_util .write_yaml import create_yaml_with_ossitem
1213from fosslight_util .read_excel import read_oss_report
1314
@@ -21,8 +22,6 @@ def convert_yml_to_excel(oss_pkg_files, output_file, file_option_on, base_path,
2122
2223 if not file_option_on :
2324 oss_pkg_files = find_all_oss_pkg_files (base_path , oss_pkg_files )
24- else :
25- oss_pkg_files = [pkg_file for pkg_file in oss_pkg_files if pkg_file .endswith (('.yaml' , '.yml' ))]
2625
2726 for oss_pkg_file in oss_pkg_files :
2827 try :
@@ -37,20 +36,19 @@ def convert_yml_to_excel(oss_pkg_files, output_file, file_option_on, base_path,
3736 except Exception as ex :
3837 logger .error (f"Read yaml file: { ex } " )
3938
40- if not window :
41- try :
42- sheet_list ["SRC_FL_Reuse" ] = items_to_print
43- write_result_to_csv (f"{ output_file } .csv" , sheet_list , True )
44- logger .warning (f"Output: { output_file } _SRC_FL_Reuse.csv" )
45- except Exception as ex :
46- logger .error (f"Write .xlsx file : { ex } " )
4739 if items_to_print and len (items_to_print ) > 0 :
4840 try :
4941 sheet_list ["SRC_FL_Reuse" ] = items_to_print
50- write_result_to_excel (f"{ output_file } .xlsx" , sheet_list )
51- logger .warning (f"Output: { output_file } .xlsx" )
42+ success = write_result_to_excel (f"{ output_file } .xlsx" , sheet_list )
43+ if success :
44+ logger .warning (f"Output: { output_file } .xlsx" )
45+ else :
46+ logger .error (f"Can't write excel file : { output_file } " )
47+ sys .exit (1 )
5248 except Exception as ex :
53- logger .error (f"Write .csv file : { ex } " )
49+ logger .error (f"Error to write excel file : { ex } " )
50+ else :
51+ logger .warning ("There is no item to convert to Excel" )
5452
5553
5654def convert_excel_to_yaml (oss_report_to_read , output_file , sheet_names = "" ):
@@ -64,14 +62,26 @@ def convert_excel_to_yaml(oss_report_to_read, output_file, sheet_names=""):
6462 yaml_dict = create_yaml_with_ossitem (item , yaml_dict )
6563 if yaml_dict :
6664 output_file = output_file if output_file .endswith (_file_extension ) else output_file + _file_extension
67- write_yaml_file (output_file , yaml_dict )
68- logger .warning (f"Output: { output_file } " )
65+ success = write_yaml_file (output_file , yaml_dict )
66+ if success :
67+ logger .warning (f"Output: { output_file } " )
68+ else :
69+ logger .error (f"Can't write yaml file : { output_file } " )
70+ sys .exit (1 )
6971 except Exception as error :
7072 logger .error (f"Convert yaml: { error } " )
7173 else :
7274 logger .error (f"Can't find a file: { oss_report_to_read } " )
7375
7476
7577def write_yaml_file (output_file , json_output ):
76- with open (output_file , 'w' ) as f :
77- yaml .dump (json_output , f , sort_keys = False )
78+ success = True
79+ error_msg = ""
80+
81+ try :
82+ with open (output_file , 'w' ) as f :
83+ yaml .dump (json_output , f , sort_keys = False )
84+ except Exception as ex :
85+ error_msg = str (ex )
86+ success = False
87+ return success , error_msg
0 commit comments