diff options
author | John Estabrook <jestabro@vyos.io> | 2025-06-20 15:23:04 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2025-06-20 15:26:25 -0500 |
commit | ecc08e77849295605700ac409b2e93bf1357969c (patch) | |
tree | 0c504c5d2293dbe3dff0880a12215915214516cb | |
parent | 4f29a02c84d87553303f45b7b0be6d39126011f4 (diff) | |
download | vyos-1x-ecc08e77849295605700ac409b2e93bf1357969c.tar.gz vyos-1x-ecc08e77849295605700ac409b2e93bf1357969c.zip |
T7561: add option --check-path-ambiguity to show duplicate paths
-rwxr-xr-x | python/vyos/xml_ref/generate_op_cache.py | 11 | ||||
-rw-r--r-- | python/vyos/xml_ref/op_definition.py | 30 |
2 files changed, 41 insertions, 0 deletions
diff --git a/python/vyos/xml_ref/generate_op_cache.py b/python/vyos/xml_ref/generate_op_cache.py index 4c98cf18d..4c22672b2 100755 --- a/python/vyos/xml_ref/generate_op_cache.py +++ b/python/vyos/xml_ref/generate_op_cache.py @@ -38,6 +38,7 @@ from op_definition import key_name from op_definition import key_type from op_definition import node_data_difference from op_definition import get_node_data +from op_definition import collapse _here = dirname(__file__) @@ -235,6 +236,11 @@ def main(): action='store_true', help='check consistency of node data across files', ) + parser.add_argument( + '--check-path-ambiguity', + action='store_true', + help='attempt to reduce to unique paths, reporting if error', + ) args = vars(parser.parse_args()) @@ -251,6 +257,11 @@ def main(): d = sort_op_data(d) + if args['check_path_ambiguity']: + # when the following passes with no output, return value will be + # the full dictionary indexed by str, not tuple + _ = collapse(d) + with open(op_ref_cache, 'w') as f: f.write('from vyos.xml_ref.op_definition import NodeData\n') f.write(f'op_reference = {str(d)}') diff --git a/python/vyos/xml_ref/op_definition.py b/python/vyos/xml_ref/op_definition.py index 46ccc3ef4..71076bdb7 100644 --- a/python/vyos/xml_ref/op_definition.py +++ b/python/vyos/xml_ref/op_definition.py @@ -134,6 +134,36 @@ def node_data_difference(a: NodeData, b: NodeData): return out +def collapse(d: OpData, acc: dict = None) -> dict: + if acc is None: + acc = {} + if not isinstance(d, dict): + return d + for k, v in d.items(): + if isinstance(k, tuple): + # reduce + name = key_name(k) + if name != '__node_data': + new_data = get_node_data(v) + if name in list(acc.keys()): + prev_data = acc[name].get('__node_data', {}) + if prev_data: + out = f'prev: {prev_data.file} {prev_data.path}\n' + else: + out = '\n' + out += f'new: {new_data.file} {new_data.path}\n' + print(out) + else: + acc[name] = {} + acc[name]['__node_data'] = new_data + acc[name].update(collapse(v)) + else: + name = k + acc[name] = v + + return acc + + class OpXml: def __init__(self): self.op_ref = {} |