Skip to content

Commit d5c5cb7

Browse files
samuel-gauthierrjarry
authored andcommitted
diff: add an option to use data_path
When comparing two models including choices/cases, schema_diff will find differences, because the schema are actually different. Add an option to use the node data_paths, which will ignore choice/case. Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 56ca55a commit d5c5cb7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

libyang/diff.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def schema_diff(
1212
ctx_old: Context,
1313
ctx_new: Context,
1414
exclude_node_cb: Optional[Callable[[SNode], bool]] = None,
15+
use_data_path: bool = False,
1516
) -> Iterator["SNodeDiff"]:
1617
"""
1718
Compare two libyang Context objects, for a given set of paths and return all
@@ -25,6 +26,9 @@ def schema_diff(
2526
Optionnal user callback that will be called with each node that is found in each
2627
context. If the callback returns a "trueish" value, the node will be excluded
2728
from the diff (as well as all its children).
29+
:arg use_data_path:
30+
Use data path instead of schema path to compare the nodes. Using data path
31+
ignores choices and cases.
2832
2933
:return:
3034
An iterator that yield `SNodeDiff` objects.
@@ -40,7 +44,11 @@ def flatten(node, dic):
4044
"""
4145
if exclude_node_cb(node):
4246
return
43-
dic[node.schema_path()] = node
47+
if use_data_path:
48+
path = node.data_path()
49+
else:
50+
path = node.schema_path()
51+
dic[path] = node
4452
if isinstance(node, (SContainer, SList, SNotif, SRpc, SRpcInOut)):
4553
for child in node:
4654
flatten(child, dic)

0 commit comments

Comments
 (0)