summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-08-08 09:03:21 -0500
committerGitHub <noreply@github.com>2025-08-08 09:03:21 -0500
commit6fa4978e8bd57b3e50357a87eee4d884aba431ef (patch)
treec300b7d21e3ae9c7d1ec7dbc739449c52ae3127a /python
parent08feca7dbe5c14a468a041e212bcc4f6618edd96 (diff)
parentddc8059fb7ecd5fe0e9ffd636e5199d32c06800a (diff)
downloadvyos-1x-6fa4978e8bd57b3e50357a87eee4d884aba431ef.tar.gz
vyos-1x-6fa4978e8bd57b3e50357a87eee4d884aba431ef.zip
Merge pull request #4653 from jestabro/op-cache-field-update
T7699: Fix update of command/help fields in the op_mode_cache generator when paths are shared across files
Diffstat (limited to 'python')
-rwxr-xr-xpython/vyos/xml_ref/generate_op_cache.py37
-rw-r--r--python/vyos/xml_ref/op_definition.py6
2 files changed, 32 insertions, 11 deletions
diff --git a/python/vyos/xml_ref/generate_op_cache.py b/python/vyos/xml_ref/generate_op_cache.py
index fb48debad..f49b2290b 100755
--- a/python/vyos/xml_ref/generate_op_cache.py
+++ b/python/vyos/xml_ref/generate_op_cache.py
@@ -93,7 +93,7 @@ def translate_command(s: str, pos: list[str]) -> str:
# it means the command is incorrect,
# e.g., it references "$6" when it only has five words.
if re.search(r'_place_holder_', s):
- print(f"Command translation failed: {s}")
+ print(f'Command translation failed: {s}')
sys.exit(1)
return s
@@ -155,7 +155,9 @@ def insert_node(
else:
name = n.get('name')
if not name:
- raise ValueError("Node name is required for all node types except <virtualTagNode>")
+ raise ValueError(
+ 'Node name is required for all node types except <virtualTagNode>'
+ )
if path is None:
path = []
@@ -223,23 +225,42 @@ def insert_node(
new_node_data.standalone_help_text = standalone_help_text
new_node_data.standalone_command = standalone_command
new_node_data.path = path
+ new_node_data.files = [file]
value = {('__node_data', None): new_node_data}
key = (name, node_type)
cur_value = d.setdefault(key, value)
- # track the correct pointer reference:
- cur_node_data = cur_value[('__node_data', None)]
- cur_node_data.files.append(file)
-
- if parent and key not in parent.children:
- parent.children.append(key)
if CHECK_XML_CONSISTENCY:
out = node_data_difference(get_node_data(cur_value), get_node_data(value))
if out:
err_buf.write(out)
+ # track the correct pointer reference:
+ cur_node_data = cur_value[('__node_data', None)]
+
+ if file not in cur_node_data.files:
+ cur_node_data.files.append(file)
+
+ if not cur_node_data.comp_help and comp_help:
+ cur_node_data.comp_help = comp_help
+
+ if not cur_node_data.help_text and help_text:
+ cur_node_data.help_text = help_text
+
+ if not cur_node_data.command and command_text:
+ cur_node_data.command = command_text
+
+ if not cur_node_data.standalone_help_text and standalone_help_text:
+ cur_node_data.standalone_help_text = standalone_help_text
+
+ if not cur_node_data.standalone_command and standalone_command:
+ cur_node_data.standalone_command = standalone_command
+
+ if parent and key not in parent.children:
+ parent.children.append(key)
+
if children is not None:
inner_nodes = children.iterfind('*')
for inner_n in inner_nodes:
diff --git a/python/vyos/xml_ref/op_definition.py b/python/vyos/xml_ref/op_definition.py
index 1a4f53a3a..d4b767324 100644
--- a/python/vyos/xml_ref/op_definition.py
+++ b/python/vyos/xml_ref/op_definition.py
@@ -126,13 +126,13 @@ def get_node_data_at_path(d: dict, tpath):
def node_data_difference(a: NodeData, b: NodeData):
out = ''
for fld in fields(NodeData):
- if fld.name in ('children', 'file'):
+ if fld.name in ('children', 'files'):
continue
a_fld = getattr(a, fld.name)
b_fld = getattr(b, fld.name)
if a_fld != b_fld:
- out += f'prev: {a.file} {a.path} {fld.name}: {a_fld}\n'
- out += f'new: {b.file} {b.path} {fld.name}: {b_fld}\n'
+ out += f'prev: {a.files[-1:]} {a.path} {fld.name}: {a_fld}\n'
+ out += f'new: {b.files[-1:]} {b.path} {fld.name}: {b_fld}\n'
out += '\n'
return out