44# SPDX-License-Identifier: GPL-3.0-only
55import os
66import sys
7- import re
87import logging
98import platform
109from datetime import datetime
1413from fosslight_util .set_log import init_log
1514from fosslight_util .output_format import check_output_format
1615from fosslight_util .parsing_yaml import find_sbom_yaml_files
17- from ._parsing_excel import convert_excel_to_yaml , convert_yml_to_excel
16+ from ._parsing_excel import convert_yml_to_excel
1817
19- CUSTOMIZED_FORMAT_FOR_PRECHECKER = {'yaml' : '.yaml' , ' excel' : '.xlsx' }
18+ CUSTOMIZED_FORMAT_FOR_PRECHECKER = {'excel' : '.xlsx' }
2019_PKG_NAME = "fosslight_prechecker"
2120logger = logging .getLogger (LOGGER_NAME )
2221
2322
24- def find_report_file (path_to_find ):
25- file_to_find = ["FOSSLight-Report.xlsx" , "OSS-Report.xlsx" ]
26-
27- try :
28- for file in file_to_find :
29- file_with_path = os .path .join (path_to_find , file )
30- if os .path .isfile (file_with_path ):
31- return file
32- for root , dirs , files in os .walk (path_to_find ):
33- for file in files :
34- file_name = file .lower ()
35- p = re .compile (r"[\s\S]*OSS[\s\S]*-Report[\s\S]*.xlsx" , re .I )
36- if p .search (file_name ):
37- return os .path .join (root , file )
38- except Exception as error :
39- logger .debug ("Find report:" + str (error ))
40- return ""
41-
42-
4323def check_extension_and_format (file , format ):
44- if (file .endswith ((".yaml" , ".yml" )) and format == "yaml" ) or \
45- (file .endswith (".xlsx" ) and format == "excel" ):
24+ if (file .endswith ((".yaml" , ".yml" )) and format == "yaml" ):
4625 logger .error (f"File extension is not matched with input format({ format } )" )
4726 sys .exit (1 )
4827
4928
50- def convert_report (base_path , output_name , format , need_log_file = True , sheet_names = "" ):
29+ def convert_report (base_path , output_name , format , need_log_file = True ):
5130 oss_yaml_files = []
52- oss_report_files = "" # TODO: Change to list type for multiple Report files
5331 file_option_on = False
5432 convert_yml_mode = False
55- convert_excel_mode = False
5633 output_report = ""
57- output_yaml = ""
5834 now = datetime .now ().strftime ('%Y%m%d_%H-%M-%S' )
5935 is_window = platform .system () == "Windows"
6036
@@ -72,10 +48,8 @@ def convert_report(base_path, output_name, format, need_log_file=True, sheet_nam
7248 pass
7349 if output_name != "" :
7450 output_report = os .path .join (output_path , output_name )
75- output_yaml = os .path .join (output_path , output_name )
7651 else :
7752 output_report = os .path .join (os .path .abspath (output_path ), f"FOSSLight-Report_{ now } " )
78- output_yaml = os .path .join (os .path .abspath (output_path ), f"fosslight-sbom-info_{ now } " )
7953 else :
8054 logger .error (f"Format error - { msg } " )
8155 sys .exit (1 )
@@ -89,33 +63,24 @@ def convert_report(base_path, output_name, format, need_log_file=True, sheet_nam
8963 files_to_convert = base_path .split ("," )
9064 for file in files_to_convert :
9165 check_extension_and_format (file , format )
92- if file .endswith (".xlsx" ):
93- convert_excel_mode = True
94- oss_report_files = file
95- elif file .endswith ((".yaml" , ".yml" )):
66+ if file .endswith ((".yaml" , ".yml" )):
9667 convert_yml_mode = True
9768 file_option_on = True
9869 oss_yaml_files .append (file )
9970 else :
10071 logger .error ("Not support file name or extension" )
10172 sys .exit (1 )
10273
103- if not convert_yml_mode and not convert_excel_mode :
74+ if not convert_yml_mode :
10475 if is_window :
10576 convert_yml_mode = True
106- oss_report_files = find_report_file (base_path )
107- if oss_report_files != "" :
108- convert_excel_mode = True
10977 else :
11078 logger .info ("fosslight_prechecker: can't convert anything" )
11179 logger .info ("Try 'fosslight_prechecker -h for more information" )
11280
11381 if convert_yml_mode :
11482 convert_yml_to_excel (oss_yaml_files , output_report , file_option_on , base_path )
11583
116- if convert_excel_mode :
117- convert_excel_to_yaml (oss_report_files , output_yaml , sheet_names )
118-
11984 try :
12085 _str_final_result_log = safe_dump (_result_log , allow_unicode = True , sort_keys = True )
12186 logger .info (_str_final_result_log )
0 commit comments