55import os
66import sys
77import logging
8- import platform
98from datetime import datetime
109from pathlib import Path
1110from yaml import safe_dump
2019logger = logging .getLogger (LOGGER_NAME )
2120
2221
23- def check_extension_and_format (file , format ):
24- if (file .endswith ((".yaml" , ".yml" )) and format == "yaml" ):
25- logger .error (f"File extension is not matched with input format({ format } )" )
26- sys .exit (1 )
27-
28-
2922def convert_report (base_path , output_name , format , need_log_file = True ):
3023 oss_yaml_files = []
3124 file_option_on = False
32- convert_yml_mode = False
3325 output_report = ""
3426 now = datetime .now ().strftime ('%Y%m%d_%H-%M-%S' )
35- is_window = platform .system () == "Windows"
3627
3728 success , msg , output_path , output_name , output_extension = check_output_format (output_name , format , CUSTOMIZED_FORMAT_FOR_PRECHECKER )
3829
@@ -56,30 +47,22 @@ def convert_report(base_path, output_name, format, need_log_file=True):
5647
5748 if os .path .isdir (base_path ):
5849 oss_yaml_files = find_sbom_yaml_files (base_path )
59- if oss_yaml_files :
60- convert_yml_mode = True
6150 else :
6251 if base_path != "" :
6352 files_to_convert = base_path .split ("," )
53+ file_option_on = True
6454 for file in files_to_convert :
65- check_extension_and_format (file , format )
6655 if file .endswith ((".yaml" , ".yml" )):
67- convert_yml_mode = True
68- file_option_on = True
6956 oss_yaml_files .append (file )
7057 else :
7158 logger .error ("Not support file name or extension" )
7259 sys .exit (1 )
7360
74- if not convert_yml_mode :
75- if is_window :
76- convert_yml_mode = True
77- else :
78- logger .info ("fosslight_prechecker: can't convert anything" )
79- logger .info ("Try 'fosslight_prechecker -h for more information" )
80-
81- if convert_yml_mode :
61+ if oss_yaml_files :
8262 convert_yml_to_excel (oss_yaml_files , output_report , file_option_on , base_path )
63+ else :
64+ logger .info ("fosslight_prechecker: can't convert anything" )
65+ logger .info ("Try 'fosslight_prechecker -h for more information" )
8366
8467 try :
8568 _str_final_result_log = safe_dump (_result_log , allow_unicode = True , sort_keys = True )
0 commit comments