summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-command-op-templates7
-rwxr-xr-xscripts/build-command-templates11
-rwxr-xr-xscripts/override-default9
3 files changed, 14 insertions, 13 deletions
diff --git a/scripts/build-command-op-templates b/scripts/build-command-op-templates
index c60b32a1e..c285ee594 100755
--- a/scripts/build-command-op-templates
+++ b/scripts/build-command-op-templates
@@ -170,12 +170,11 @@ def process_node(n, tmpl_dir):
print("Processing node {}".format(name))
nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def")
- if not os.path.exists(nodedef_path):
+ # Only create the "node.def" file if it exists but is empty, or if it
+ # does not exist at all.
+ if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0:
with open(nodedef_path, "w") as f:
f.write(make_node_def(props, command))
- else:
- # Something has already generated this file
- pass
if children is not None:
inner_nodes = children.iterfind("*")
diff --git a/scripts/build-command-templates b/scripts/build-command-templates
index d6585b0cc..452c420eb 100755
--- a/scripts/build-command-templates
+++ b/scripts/build-command-templates
@@ -274,13 +274,14 @@ def process_node(n, tmpl_dir):
raise ValueError("<valueless/> is only allowed in <leafNode>")
nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def")
- if not os.path.exists(nodedef_path):
+
+ # Only create the "node.def" file if it exists but is empty, or if it does
+ # not exist at all. An empty node.def file could be generated by XML paths
+ # that derive from one another bot having a common base structure like
+ # "protocols static"
+ if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0:
with open(nodedef_path, "w") as f:
f.write(make_node_def(props))
- else:
- # Something has already generated that file
- pass
-
if node_type == "node":
inner_nodes = children.iterfind("*")
diff --git a/scripts/override-default b/scripts/override-default
index d91b89426..c8a0ff1da 100755
--- a/scripts/override-default
+++ b/scripts/override-default
@@ -63,8 +63,7 @@ def override_element(l: list):
def collect_and_override(dir_name):
"""
Collect elements with defaultValue tag into dictionary indexed by tuple
- of (name, str(ancestor path)); the second component must be immutable for
- tuple to act as key, hence str().
+ of (name: str, ancestor path: str).
"""
for fname in glob.glob(f'{dir_name}/*.xml'):
tree = etree.parse(fname)
@@ -76,11 +75,13 @@ def collect_and_override(dir_name):
for element in xp:
ap = element.xpath('ancestor::*[@name]')
- defv.setdefault((ap[-1].get("name"), str(ap[:-1])), []).append(element)
+ ap_name = [el.get("name") for el in ap]
+ ap_path_str = ' '.join(ap_name[:-1])
+ defv.setdefault((ap_name[-1], ap_path_str), []).append(element)
for k, v in defv.items():
if len(v) > 1:
- logger.debug(f'overridding default in {k[0]}')
+ logger.info(f"overridding default in {k[0]}, path '{k[1]}'")
override_element(v)
revised_str = etree.tostring(root, encoding='unicode', pretty_print=True)