summaryrefslogtreecommitdiffstats
path: root/tools/hdv/redfish/excel_2_yaml.py
diff options
context:
space:
mode:
authorchenliangyjy <chenliangyjy@chinamobile.com>2020-03-11 17:36:10 +0800
committerchenliangyjy <chenliangyjy@chinamobile.com>2020-03-13 15:46:21 +0800
commit74b31a2b17e18740dafcf883c2d2ddef37a6504c (patch)
tree7c540dc9c3541861c051400b512a3c783034908a /tools/hdv/redfish/excel_2_yaml.py
parent10d5e51457478e1024f3f61b2678d0f69adf16a1 (diff)
introduce hdv implementation by redfish support yaml and excel
Signed-off-by: chenliangyjy <chenliangyjy@chinamobile.com> Change-Id: I2c5bfbc23e603418f99946c0ad6417b0589496b0
Diffstat (limited to 'tools/hdv/redfish/excel_2_yaml.py')
-rw-r--r--tools/hdv/redfish/excel_2_yaml.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/hdv/redfish/excel_2_yaml.py b/tools/hdv/redfish/excel_2_yaml.py
new file mode 100644
index 0000000..3bda3d5
--- /dev/null
+++ b/tools/hdv/redfish/excel_2_yaml.py
@@ -0,0 +1,61 @@
+##############################################################################
+# Copyright (c) 2020 China Mobile Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+'''
+excel 2 yaml tools
+convert excel config to yaml format config: depends.yaml and cases.yaml.
+'''
+import os
+import yaml
+from openpyxl.reader.excel import load_workbook
+#pylint: disable=E0611
+from log_utils import LOGGER
+
+
+def load_sheet(excel_file, sheet_index, start_col, end_col):
+ '''
+ load sheet
+ '''
+ if not os.path.exists(excel_file):
+ LOGGER.error("excel file not existing")
+ return None
+ input_file = load_workbook(excel_file)
+ input_ws = input_file[input_file.sheetnames[sheet_index]]
+ cell_key = []
+ rows_list = []
+ for i in range(start_col, end_col):
+ cell_key.append(input_ws.cell(row=1, column=i).value)
+ row = 2
+ while input_ws.cell(row=row, column=1).value:
+ cell_value = []
+ for i in range(start_col, end_col):
+ value = input_ws.cell(row=row, column=i).value
+ if isinstance(value, str):
+ value = value.strip().replace('\n', '')
+ cell_value.append(value)
+ cell_dict = dict(zip(cell_key, cell_value))
+ row += 1
+ rows_list.append(cell_dict)
+
+ LOGGER.info(rows_list)
+ return rows_list
+
+def create_yaml(id_dict, yaml_file):
+ '''
+ create yaml
+ '''
+ with open(yaml_file, 'w') as y_file:
+ yaml.dump(id_dict, y_file, explicit_start=True)
+
+
+DEPEND_FILE_NAME = "./conf/depends.yaml"
+LOGGER.info("create %s ", DEPEND_FILE_NAME)
+create_yaml(load_sheet("./conf/cases.xlsx", 1, 1, 5), DEPEND_FILE_NAME)
+
+CASE_FILE_NAME = "./conf/cases.yaml"
+create_yaml(load_sheet("./conf/cases.xlsx", 0, 1, 10), CASE_FILE_NAME)