|
10 | 10 |
|
11 | 11 | logger = logging.getLogger(LOGGER_NAME) |
12 | 12 |
|
| 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 | + |
13 | 35 |
|
14 | 36 | def convert_yml_to_excel(oss_yaml_files, output_file, file_option_on, base_path): |
15 | | - items_to_print = [] |
16 | 37 | sheet_list = {} |
| 38 | + header = {} |
17 | 39 |
|
18 | 40 | for yaml_file in oss_yaml_files: |
19 | 41 | try: |
20 | 42 | if os.path.isfile(yaml_file): |
| 43 | + items_to_print = [] |
| 44 | + |
21 | 45 | logger.info(f"Read data from : {yaml_file}") |
22 | 46 |
|
23 | 47 | if file_option_on: |
24 | 48 | base_path = os.path.dirname(yaml_file) |
25 | 49 | oss_items, _ = parsing_yml(yaml_file, base_path) |
26 | 50 | for item in oss_items: |
27 | 51 | 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 |
28 | 61 | except Exception as ex: |
29 | 62 | logger.error(f"Read yaml file: {ex}") |
30 | 63 |
|
31 | 64 | 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) |
34 | 66 | if success: |
35 | 67 | if result_file: |
36 | 68 | logger.warning(f"Output: {result_file}") |
|
0 commit comments