Skip to content

Commit

Permalink
Fix corner case
Browse files Browse the repository at this point in the history
attribute id is None
MEI cluster
  • Loading branch information
erwinpan1 committed Sep 25, 2024
1 parent 22e4443 commit d727803
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ClusterReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ def is_attribute_non_volatile(source, attribute_id):
with open(source, 'r') as file:
content = file.read()

print(f"source = {source}")
print(f"attribute_id = {attribute_id}")
soup = BeautifulSoup(content, 'lxml-xml')

# Debug: Print the parsed XML structure (for a quick visual check)
# print("Parsed XML:", soup.prettify())

# Find the attribute with the given ID (convert hex ID from XML to integer for comparison)
attribute = soup.find('attribute', {'id': lambda x: int(x, 16) == attribute_id})
attribute = soup.find('attribute', {'id': lambda x: x is not None and int(x, 16) == attribute_id})

# Debug: Check if the attribute was found
print("Attribute found:", attribute is not None)
Expand Down
4 changes: 4 additions & 0 deletions ParseZap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def find_ram_attributes_and_replace(data, replace=False):
cluster_name = cluster.get('name')
cluster_code = cluster.get('code')

if cluster_code > 0x7FFF: # Not standard cluster ID
continue;

for attribute in cluster.get('attributes', []): # Iterate through the attributes
attribute_code = attribute.get('code') # Get the attribute's code
# Filter global element
Expand All @@ -59,6 +62,7 @@ def find_ram_attributes_and_replace(data, replace=False):

attribute_name = attribute.get('name') # Get the attribute's name

print(f"cluster_code = {cluster_code}, attribute_code={attribute_code}, attribute_name = {attribute_name}")
spec_xml = id2XmlMap[cluster_code]['file']
if not is_attribute_non_volatile(spec_xml, attribute_code):
print(f"\033[41m Ignore cluster: {cluster_name}, name:{attribute_name} \033[0m")
Expand Down

0 comments on commit d727803

Please sign in to comment.