Skip to content

Commit

Permalink
Merge pull request #20 from zhangyiant/zhangyiant/template-update
Browse files Browse the repository at this point in the history
Update template.
  • Loading branch information
zhangyiant authored Mar 8, 2022
2 parents b71a957 + 49cb81c commit 1342a2d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Binary file modified abc.xlsx
Binary file not shown.
Binary file modified excels/block1.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion register_printer/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.1.3
40 changes: 20 additions & 20 deletions register_printer/parser/block_template_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,66 @@


def is_empty_row(row):
if row[0].value == "" and row[1].value == "":
if row[0].value.strip() == "" and row[1].value.strip() == "":
return True
return False

def is_register_table_flag_row(row):
if row[0].value.upper() == "register description:".upper():
if row[0].value.strip().upper() == "register description".upper():
return True
return False

def is_register_table_title_row(row):
if row[0].value.upper() == "Offset".upper():
if row[0].value.strip().upper() == "Offset".upper():
return True
return False

def parse_register_table_title(row):
column_count = len(row)
result = {}
for i in range(column_count):
if row[i].value.upper() == "offset".upper():
if row[i].value.strip().upper() == "offset".upper():
result["offset"] = i
elif row[i].value.upper() == "name".upper():
elif row[i].value.strip().upper() == "name".upper():
result["name"] = i
elif row[i].value.upper() == "msb".upper():
elif row[i].value.strip().upper() == "msb".upper():
result["msb"] = i
elif row[i].value.upper() == "lsb".upper():
elif row[i].value.strip().upper() == "lsb".upper():
result["lsb"] = i
elif row[i].value.upper() == "field name".upper():
elif row[i].value.strip().upper() == "field name".upper():
result["field name"] = i
elif row[i].value.upper() == "access".upper():
elif row[i].value.strip().upper() == "access".upper():
result["access"] = i
elif row[i].value.upper() == "default value".upper():
result["default value"] = i
elif row[i].value.upper() == "description".upper():
elif row[i].value.strip().upper() == "default".upper():
result["default"] = i
elif row[i].value.strip().upper() == "description".upper():
result["description"] = i
LOGGER.debug("Register table column mapping: %s", result)
return result

def is_array_table_flag_row(row):
if row[0].value.upper() == "register array:".upper():
if row[0].value.strip().upper() == "register array".upper():
return True
return False

def is_array_table_title_row(row):
if row[1].value.upper() == "array_name".upper():
if row[1].value.strip().upper() == "array_name".upper():
return True
return False

def parse_array_table_title(row):
column_count = len(row)
result = {}
for i in range(column_count):
if row[i].value.upper() == "array_name".upper():
if row[i].value.strip().upper() == "array_name".upper():
result["array_name"] = i
elif row[i].value.upper() == "array_len".upper():
elif row[i].value.strip().upper() == "array_len".upper():
result["array_len"] = i
elif row[i].value.upper() == "array_offset".upper():
elif row[i].value.strip().upper() == "array_offset".upper():
result["array_offset"] = i
elif row[i].value.upper() == "start_addr".upper():
elif row[i].value.strip().upper() == "start_addr".upper():
result["start_addr"] = i
elif row[i].value.upper() == "end_addr".upper():
elif row[i].value.strip().upper() == "end_addr".upper():
result["end_addr"] = i
LOGGER.debug("Array table column mapping: %s", result)
return result
Expand Down Expand Up @@ -282,7 +282,7 @@ def validate_sheet(sheet, previous_context):

context.row = 0
context.column = 0
if sheet.cell(0, 0).value != "Module description:":
if sheet.cell(0, 0).value.upper() != "Module description".upper():
LOGGER.debug(
"sheet %s error: find no \"Module description:\" in cell(0,0)",
sheet.name)
Expand Down
2 changes: 1 addition & 1 deletion register_printer/parser/field_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def parse_field_row(row, register_table_column_mapping, previous_context):
msg = "Invalid access type: {}.".format(access)
raise ExcelParseException(msg, context)

context.column = register_table_column_mapping["default value"]
context.column = register_table_column_mapping["default"]
default = row[context.column].value
try:
if re.match(r"0x", str(default)):
Expand Down

0 comments on commit 1342a2d

Please sign in to comment.