Skip to content

Commit

Permalink
Update XML parser to support revision history check (#30929)
Browse files Browse the repository at this point in the history
* Update XML parser to support revision history check

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Feb 12, 2024
1 parent a1e3d1c commit 4463202
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,39 @@ def GetNextProcessor(self, name: str, attrs: AttributesImpl):
return BaseHandler(self.context)


class RevisionHistoryHandler(BaseHandler):
"""
Parses elements of revision history that look like:
'''
<revisionHistory>
<revision revision="1" summary="Global mandatory ClusterRevision attribute added"/>
<revision revision="2" summary="CCB 2808"/>
<revision revision="3" summary="All Hubs changes"/>
<revision revision="4" summary="New data model format and notation; add IdentifyType"/>
</revisionHistory>
'''
"""

def __init__(self, context: Context, cluster: Cluster):
super().__init__(context, handled=HandledDepth.SINGLE_TAG)
self._cluster = cluster

def GetNextProcessor(self, name: str, attrs: AttributesImpl):
if name == "revision":
if 'revision' not in attrs:
LOGGER.error(
f"Could not find a revision for {attrs}: no revision data")
return BaseHandler(self.context, handled=HandledDepth.ENTIRE_TREE)
else:
rev = int(attrs['revision'])
if self._cluster.revision < rev:
self._cluster.revision = rev
return BaseHandler(self.context, handled=HandledDepth.SINGLE_TAG)
else:
return BaseHandler(self.context)


class DataTypesHandler(BaseHandler):
def __init__(self, context: Context, cluster: Cluster):
super().__init__(context, handled=HandledDepth.SINGLE_TAG)
Expand Down Expand Up @@ -580,12 +613,7 @@ def EndProcessing(self):

def GetNextProcessor(self, name: str, attrs: AttributesImpl):
if name == "revisionHistory":
# Revision history COULD be used to find the latest revision of a cluster
# however current IDL files do NOT have a revision info field
#
# NOTE: we COULD set this as a `default` for attribute clusterRevision, however this will likely
# not match with what matter IDL would parse into.
return BaseHandler(self.context, handled=HandledDepth.ENTIRE_TREE)
return RevisionHistoryHandler(self.context, self._cluster)
elif name == "section":
# Documentation data, skipped
return BaseHandler(self.context, handled=HandledDepth.ENTIRE_TREE)
Expand Down
2 changes: 2 additions & 0 deletions scripts/py_matter_idl/matter_idl/test_data_model_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def testClusterDerivation(self):

expected_idl = IdlTextToIdl('''
client cluster DishwasherMode = 89 {
revision 2;
bitmap Feature: bitmap32 {
kOnOff = 0x1;
}
Expand Down

0 comments on commit 4463202

Please sign in to comment.