From 105531013d2c5eceb83ec265f61cbb3aff8a63e8 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 12 Dec 2023 14:57:44 -0500 Subject: [PATCH] Update XML parser to support revision history check (#30929) * Update XML parser to support revision history check * Restyle --- .../data_model_xml/handlers/handlers.py | 40 ++++++++++++++++--- .../matter_idl/test_data_model_xml.py | 2 + 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py b/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py index ee13991f23d8df..5fa6f06482439c 100644 --- a/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py +++ b/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/handlers.py @@ -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: + + ''' + + + + + + + ''' + """ + + 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) @@ -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) diff --git a/scripts/py_matter_idl/matter_idl/test_data_model_xml.py b/scripts/py_matter_idl/matter_idl/test_data_model_xml.py index 06418f894ffcd6..647a275ea8d547 100755 --- a/scripts/py_matter_idl/matter_idl/test_data_model_xml.py +++ b/scripts/py_matter_idl/matter_idl/test_data_model_xml.py @@ -204,6 +204,8 @@ def testClusterDerivation(self): expected_idl = IdlTextToIdl(''' client cluster DishwasherMode = 89 { + revision 2; + bitmap Feature: bitmap32 { kOnOff = 0x1; }