summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-12-24 11:09:08 +0100
committerGitHub <noreply@github.com>2023-12-24 11:09:08 +0100
commit04e24e89623620466b56b432c36f727768e5dcb7 (patch)
treeab120cf162e798ee8a88e6b0c88b7eae644ddbe3
parentea0fab9ed609741da29709ac6c807e964c02f040 (diff)
parent3ba1686b1fee167dffe5c14f961412fe0363116c (diff)
downloadvyos-1x-04e24e89623620466b56b432c36f727768e5dcb7.tar.gz
vyos-1x-04e24e89623620466b56b432c36f727768e5dcb7.zip
Merge pull request #2680 from vyos/mergify/bp/sagitta/pr-2679
xml: T5854: clear empty paths left by embedded override of defaultValue (backport #2679)
-rwxr-xr-xscripts/override-default18
1 files changed, 15 insertions, 3 deletions
diff --git a/scripts/override-default b/scripts/override-default
index 0c49087c8..5058e79b3 100755
--- a/scripts/override-default
+++ b/scripts/override-default
@@ -41,6 +41,14 @@ if debug:
else:
logger.setLevel(logging.INFO)
+def clear_empty_path(el):
+ # on the odd chance of interleaved comments
+ tmp = [l for l in el if isinstance(l.tag, str)]
+ if not tmp:
+ p = el.getparent()
+ p.remove(el)
+ clear_empty_path(p)
+
def override_element(l: list):
"""
Allow multiple override elements; use the final one (in document order).
@@ -59,7 +67,9 @@ def override_element(l: list):
# remove all but overridden element
for el in parents:
- el.getparent().remove(el)
+ tmp = el.getparent()
+ tmp.remove(el)
+ clear_empty_path(tmp)
def merge_remaining(l: list, elementtree):
"""
@@ -81,7 +91,9 @@ def merge_remaining(l: list, elementtree):
# override_element() has already run
for child in el:
rp[0].append(deepcopy(child))
- el.getparent().remove(el)
+ tmp = el.getparent()
+ tmp.remove(el)
+ clear_empty_path(tmp)
def collect_and_override(dir_name):
"""
@@ -104,7 +116,7 @@ def collect_and_override(dir_name):
for k, v in defv.items():
if len(v) > 1:
- logger.info(f"overridding default in path '{k}'")
+ logger.info(f"overriding default in path '{k}'")
override_element(v)
to_merge = list(defv)