Commit d4e3b869 authored by olivier R-D's avatar olivier R-D

get_current_path -> get_path and avoid circular loops

parent 1fc97eac
...@@ -353,20 +353,26 @@ class Node(object): ...@@ -353,20 +353,26 @@ class Node(object):
return None return None
return references[0].NodeId return references[0].NodeId
def get_current_path(self): def get_path(self, max_length=20):
""" """
Attempt to find current path of node and return it as a list of strings. Attempt to find path of node from root node and return it as a list of strings.
There might several possible paths to a node, this function will return one There might several possible paths to a node, this function will return one
Some nodes may be missing references, so this method may Some nodes may be missing references, so this method may
return an empty list return an empty list
Since address space may have circular references, a max length is specified
""" """
path = [] path = [self.get_browse_name().to_string()]
node = self node = self
count = 0
while True: while True:
refs = node.get_references(refs=ua.ObjectIds.HierarchicalReferences, direction=ua.BrowseDirection.Inverse) refs = node.get_references(refs=ua.ObjectIds.HierarchicalReferences, direction=ua.BrowseDirection.Inverse)
if len(refs) > 0: if len(refs) > 0:
path.insert(0, refs[0].BrowseName.to_string()) path.insert(0, refs[0].BrowseName.to_string())
node = Node(self.server, refs[0].NodeId) node = Node(self.server, refs[0].NodeId)
count += 1
if count > max_length:
return path
else: else:
return path return path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment