diff options
author | John Estabrook <jestabro@vyos.io> | 2024-05-07 14:52:14 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2024-05-08 08:49:19 -0500 |
commit | 2551a741af9ac4f7dfff8dc5cbe47173a99fa478 (patch) | |
tree | 94d33a6d878ccb58bb1d44c1baecbe08ea68d7ef /python/vyos/xml_ref/definition.py | |
parent | 996f9af72d41324319602252f3628bf04ac86dc4 (diff) | |
download | vyos-1x-2551a741af9ac4f7dfff8dc5cbe47173a99fa478.tar.gz vyos-1x-2551a741af9ac4f7dfff8dc5cbe47173a99fa478.zip |
xml: T6319: add util for ancestor owner/priority
Diffstat (limited to 'python/vyos/xml_ref/definition.py')
-rw-r--r-- | python/vyos/xml_ref/definition.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/python/vyos/xml_ref/definition.py b/python/vyos/xml_ref/definition.py index c90c5ddbc..c85835ffd 100644 --- a/python/vyos/xml_ref/definition.py +++ b/python/vyos/xml_ref/definition.py @@ -135,6 +135,33 @@ class Xml: d = self._get_ref_path(path) return self._is_leaf_node(d) + def _least_upper_data(self, path: list, name: str) -> str: + ref_path = path.copy() + d = self.ref + data = '' + while ref_path and d: + d = d.get(ref_path[0], {}) + ref_path.pop(0) + if self._is_tag_node(d) and ref_path: + ref_path.pop(0) + if self._is_leaf_node(d) and ref_path: + ref_path.pop(0) + res = self._get_ref_node_data(d, name) + if res is not None: + data = res + + return data + + def owner(self, path: list) -> str: + from pathlib import Path + data = self._least_upper_data(path, 'owner') + if data: + data = Path(data.split()[0]).name + return data + + def priority(self, path: list) -> str: + return self._least_upper_data(path, 'priority') + @staticmethod def _dict_get(d: dict, path: list) -> dict: for i in path: |