From d727803cc848e116fc49e002bd58968cc909a172 Mon Sep 17 00:00:00 2001 From: erwinpan1 Date: Wed, 25 Sep 2024 21:22:13 +0800 Subject: [PATCH] Fix corner case attribute id is None MEI cluster --- ClusterReader.py | 4 +++- ParseZap.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ClusterReader.py b/ClusterReader.py index 399af791985c67..d6688691734707 100644 --- a/ClusterReader.py +++ b/ClusterReader.py @@ -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) diff --git a/ParseZap.py b/ParseZap.py index 16f89263bdeae2..5dfc8aa365efa4 100644 --- a/ParseZap.py +++ b/ParseZap.py @@ -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 @@ -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")