diff --git a/cpu/stm32/dist/kconfig/gen_kconfig.py b/cpu/stm32/dist/kconfig/gen_kconfig.py index ce533df07c..8fef1a471b 100755 --- a/cpu/stm32/dist/kconfig/gen_kconfig.py +++ b/cpu/stm32/dist/kconfig/gen_kconfig.py @@ -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) diff --git a/cpu/stm32/dist/kconfig/requirements.txt b/cpu/stm32/dist/kconfig/requirements.txt index 35ec90e4f7..fd02b050ae 100644 --- a/cpu/stm32/dist/kconfig/requirements.txt +++ b/cpu/stm32/dist/kconfig/requirements.txt @@ -1,2 +1,2 @@ -xlrd +openpyxl jinja2