cpu/stm32/gen_kconfig: use openpyxl package instead of xlrd

This commit is contained in:
Alexandre Abadie 2021-05-01 11:31:56 +02:00
parent d39fd7c773
commit 127d6853c7
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
2 changed files with 14 additions and 9 deletions

View File

@ -9,8 +9,9 @@
import os
import argparse
import datetime
import warnings
import xlrd
from openpyxl import load_workbook
from jinja2 import FileSystemLoader, Environment
@ -19,22 +20,26 @@ RIOTBASE = os.getenv(
"RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../..")))
STM32_KCONFIG_DIR = os.path.join(RIOTBASE, "cpu/stm32/kconfigs")
STM32_VENDOR_DIR = os.path.join(RIOTBASE, "cpu/stm32/include/vendor/cmsis")
MODEL_COLUMN = 1
def parse_sheet(cpu_fam, sheets):
"""Parse the Excel sheet and return a dict."""
models = []
for sheet in sheets:
# Load the content of the xlsx sheet
work_book = xlrd.open_workbook(sheet)
sheet = work_book.sheet_by_name('ProductsList')
# filter warning raised by openpyxl
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
# Load the content of the xlsx sheet
sheet = load_workbook(filename=sheet, data_only=True).active
# Extract models from sheet
for rownum in range(sheet.nrows):
row = sheet.row_values(rownum)
if not row[0].startswith("STM32"):
for idx, row in enumerate(sheet.rows):
# Row index starts at 1
model = str(sheet.cell(row=idx + 1, column=MODEL_COLUMN).value)
if not model.startswith("STM32"):
continue
models.append(row[0].replace("-", "_"))
models.append(model.replace("-", "_"))
return sorted(models)

View File

@ -1,2 +1,2 @@
xlrd
openpyxl
jinja2