Skip to content

Commit 5e0b0ca

Browse files
committed
Convert several .yaml file to a report file
1 parent 6dd65b4 commit 5e0b0ca

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/fosslight_oss_pkg/_parsing_excel.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,59 @@
1010

1111
logger = logging.getLogger(LOGGER_NAME)
1212

13+
HEADER_CONTENT = ['ID', 'Source Name or Path', 'OSS Name',
14+
'OSS Version', 'License', 'Download Location',
15+
'Homepage', 'Copyright Text', 'Exclude',
16+
'Comment']
17+
MAX_SHEET_NAME_LEN = 31
18+
19+
20+
def get_sheet_name(yaml_file, sheet_list):
21+
if len(yaml_file) > MAX_SHEET_NAME_LEN:
22+
yaml_file = yaml_file[0:MAX_SHEET_NAME_LEN]
23+
24+
count = 1
25+
while yaml_file in sheet_list:
26+
end_idx = MAX_SHEET_NAME_LEN - 1 - len(str(count))
27+
yaml_file = f"{yaml_file[0:end_idx]}_{count}"
28+
count += 1
29+
if end_idx == 0:
30+
yaml_file = ""
31+
logger.error("Too many duplicated file names")
32+
break
33+
return yaml_file
34+
1335

1436
def convert_yml_to_excel(oss_yaml_files, output_file, file_option_on, base_path):
15-
items_to_print = []
1637
sheet_list = {}
38+
header = {}
1739

1840
for yaml_file in oss_yaml_files:
1941
try:
2042
if os.path.isfile(yaml_file):
43+
items_to_print = []
44+
2145
logger.info(f"Read data from : {yaml_file}")
2246

2347
if file_option_on:
2448
base_path = os.path.dirname(yaml_file)
2549
oss_items, _ = parsing_yml(yaml_file, base_path)
2650
for item in oss_items:
2751
items_to_print.extend(item.get_print_array())
52+
if not base_path.endswith("/"):
53+
base_path += "/"
54+
yaml_file = yaml_file.replace(base_path, '')
55+
yaml_file = yaml_file.replace('/', '_')
56+
57+
yaml_file_sheet = get_sheet_name(yaml_file, sheet_list)
58+
if yaml_file_sheet:
59+
sheet_list[yaml_file_sheet] = items_to_print
60+
header[yaml_file_sheet] = HEADER_CONTENT
2861
except Exception as ex:
2962
logger.error(f"Read yaml file: {ex}")
3063

3164
try:
32-
sheet_list["SRC_FL_Prechecker"] = items_to_print
33-
success, msg, result_file = write_output_file(output_file, '.xlsx', sheet_list)
65+
success, msg, result_file = write_output_file(output_file, '.xlsx', sheet_list, header)
3466
if success:
3567
if result_file:
3668
logger.warning(f"Output: {result_file}")

0 commit comments

Comments
 (0)