1313from fosslight_util .constant import LOGGER_NAME
1414from fosslight_util .set_log import init_log
1515from fosslight_util .output_format import check_output_format
16+ from fosslight_util .parsing_yaml import find_sbom_yaml_files
1617from ._parsing_excel import convert_excel_to_yaml , convert_yml_to_excel
1718
1819CUSTOMIZED_FORMAT_FOR_PRECHECKER = {'yaml' : '.yaml' , 'excel' : '.xlsx' }
@@ -39,12 +40,19 @@ def find_report_file(path_to_find):
3940 return ""
4041
4142
43+ def check_extension_and_format (file , format ):
44+ if (file .endswith ((".yaml" , ".yml" )) and format == "yaml" ) or \
45+ (file .endswith (".xlsx" ) and format == "excel" ):
46+ logger .error (f"File extension is not matched with input format({ format } )" )
47+ sys .exit (1 )
48+
49+
4250def convert_report (base_path , output_name , format , need_log_file = True , sheet_names = "" ):
43- oss_pkg_files = ["oss-pkg-info.yml" , "oss-pkg-info.yaml" ]
51+ oss_yaml_files = []
52+ oss_report_files = "" # TODO: Change to list type for multiple Report files
4453 file_option_on = False
4554 convert_yml_mode = False
4655 convert_excel_mode = False
47- report_to_read = ""
4856 output_report = ""
4957 output_yaml = ""
5058 now = datetime .now ().strftime ('%Y%m%d_%H-%M-%S' )
@@ -72,46 +80,45 @@ def convert_report(base_path, output_name, format, need_log_file=True, sheet_nam
7280 logger .error (f"Format error - { msg } " )
7381 sys .exit (1 )
7482
83+ if base_path == "" :
84+ base_path = output_path
85+
7586 if os .path .isdir (base_path ):
76- if output_extension == ".yaml" :
77- logger .error ("Format error - can make only .xlsx file" )
78- sys .exit (1 )
79- convert_yml_mode = True
87+ oss_yaml_files = find_sbom_yaml_files (base_path )
88+ if oss_yaml_files :
89+ convert_yml_mode = True
8090 else :
8191 if base_path != "" :
82- if base_path .endswith (".xlsx" ):
83- if output_extension == '.xlsx' :
84- logger .error ("Format error - can make only .yaml file" )
85- sys .exit (1 )
86- convert_excel_mode = True
87- report_to_read = base_path
88- elif base_path .endswith ((".yaml" , ".yml" )):
89- if output_extension == '.yaml' :
90- logger .error ("Format error - can make only .xlsx file" )
92+ files_to_convert = base_path .split ("," )
93+ for file in files_to_convert :
94+ check_extension_and_format (file , format )
95+ if base_path .endswith (".xlsx" ):
96+ convert_excel_mode = True
97+ oss_report_files = base_path
98+ elif base_path .endswith ((".yaml" , ".yml" )):
99+ convert_yml_mode = True
100+ file_option_on = True
101+ oss_yaml_files .append (file )
102+ else :
103+ logger .error ("Not support file name or extension" )
91104 sys .exit (1 )
92- oss_pkg_files = base_path .split (',' )
93- convert_yml_mode = True
94- file_option_on = True
95- else :
96- logger .error ("Not support file name or extension" )
97- sys .exit (1 )
98105
99106 if not convert_yml_mode and not convert_excel_mode :
100107 if is_window :
101108 convert_yml_mode = True
102109 base_path = os .getcwd ()
103- report_to_read = find_report_file (base_path )
104- if report_to_read != "" :
110+ oss_report_files = find_report_file (base_path )
111+ if oss_report_files != "" :
105112 convert_excel_mode = True
106113 else :
107114 logger .info ("fosslight_prechecker: can't convert anything" )
108115 logger .info ("Try 'fosslight_prechecker -h for more information" )
109116
110117 if convert_yml_mode :
111- convert_yml_to_excel (oss_pkg_files , output_report , file_option_on , base_path , is_window )
118+ convert_yml_to_excel (oss_yaml_files , output_report , file_option_on , base_path )
112119
113120 if convert_excel_mode :
114- convert_excel_to_yaml (report_to_read , output_yaml , sheet_names )
121+ convert_excel_to_yaml (oss_report_files , output_yaml , sheet_names )
115122
116123 try :
117124 _str_final_result_log = safe_dump (_result_log , allow_unicode = True , sort_keys = True )
0 commit comments