Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
52074ecd
Commit
52074ecd
authored
Nov 12, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make Node.get_path return nodes. get_path_as_string returns qname strings
parent
73a2fee8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
10 deletions
+53
-10
opcua/common/node.py
opcua/common/node.py
+32
-4
opcua/common/shortcuts.py
opcua/common/shortcuts.py
+2
-0
tests/tests_common.py
tests/tests_common.py
+19
-6
No files found.
opcua/common/node.py
View file @
52074ecd
...
...
@@ -353,7 +353,7 @@ class Node(object):
return
None
return
references
[
0
].
NodeId
def
get_path
(
self
,
max_length
=
20
):
def
get_path
_as_string
(
self
,
max_length
=
20
):
"""
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
...
...
@@ -362,14 +362,42 @@ class Node(object):
Since address space may have circular references, a max length is specified
"""
path
=
[
self
.
get_browse_name
().
to_string
()]
path
=
self
.
_get_path
(
max_length
)
path
=
[
ref
.
BrowseName
.
to_string
()
for
ref
in
path
]
path
.
append
(
self
.
get_browse_name
().
to_string
())
return
path
def
get_path
(
self
,
max_length
=
20
):
"""
Attempt to find path of node from root node and return it as a list of Nodes.
There might several possible paths to a node, this function will return one
Some nodes may be missing references, so this method may
return an empty list
Since address space may have circular references, a max length is specified
"""
path
=
self
.
_get_path
(
max_length
)
path
=
[
Node
(
self
.
server
,
ref
.
NodeId
)
for
ref
in
path
]
path
.
append
(
self
)
return
path
def
_get_path
(
self
,
max_length
=
20
):
"""
Attempt to find path of node from root node and return it as a list of Nodes.
There might several possible paths to a node, this function will return one
Some nodes may be missing references, so this method may
return an empty list
Since address space may have circular references, a max length is specified
"""
path
=
[]
node
=
self
while
True
:
refs
=
node
.
get_references
(
refs
=
ua
.
ObjectIds
.
HierarchicalReferences
,
direction
=
ua
.
BrowseDirection
.
Inverse
)
if
len
(
refs
)
>
0
:
path
.
insert
(
0
,
refs
[
0
]
.
BrowseName
.
to_string
()
)
path
.
insert
(
0
,
refs
[
0
])
node
=
Node
(
self
.
server
,
refs
[
0
].
NodeId
)
if
len
(
path
)
>=
max_length
:
if
len
(
path
)
>=
(
max_length
-
1
)
:
return
path
else
:
return
path
...
...
opcua/common/shortcuts.py
View file @
52074ecd
...
...
@@ -14,3 +14,5 @@ class Shortcuts(object):
self
.
base_object_type
=
Node
(
server
,
ObjectIds
.
BaseObjectType
)
self
.
base_data_type
=
Node
(
server
,
ObjectIds
.
BaseDataType
)
self
.
base_event_type
=
Node
(
server
,
ObjectIds
.
BaseEventType
)
self
.
base_variable_type
=
Node
(
server
,
ObjectIds
.
BaseVariableType
)
self
.
folder_type
=
Node
(
server
,
ObjectIds
.
FolderType
)
tests/tests_common.py
View file @
52074ecd
...
...
@@ -6,6 +6,7 @@ from datetime import timedelta
import
math
from
opcua
import
ua
from
opcua
import
Node
from
opcua
import
uamethod
from
opcua
import
instantiate
from
opcua
import
copy_node
...
...
@@ -539,15 +540,27 @@ class CommonTests(object):
self
.
assertEqual
(
p
.
get_parent
(),
o
)
self
.
assertEqual
(
p
.
get_type_definition
().
Identifier
,
ua
.
ObjectIds
.
PropertyType
)
def
test_path
(
self
):
def
test_path
_string
(
self
):
o
=
self
.
opc
.
nodes
.
objects
.
add_folder
(
1
,
"titif"
).
add_object
(
3
,
"opath"
)
path
=
o
.
get_path
()
path
=
o
.
get_path
_as_string
()
self
.
assertEqual
([
"0:Root"
,
"0:Objects"
,
"1:titif"
,
"3:opath"
],
path
)
path
=
o
.
get_path
(
2
)
path
=
o
.
get_path
_as_string
(
2
)
self
.
assertEqual
([
"1:titif"
,
"3:opath"
],
path
)
self
.
opc
.
get_node
(
"i=27"
)
path
=
self
.
opc
.
get_node
(
"i=13387"
).
get_path
()
self
.
assertEqual
([
'0:BaseObjectType'
,
'0:FolderType'
,
'0:FileDirectoryType'
,
'0:CreateDirectory'
],
path
)
# FIXME this is wrong in our server! BaseObjectType is missing an inverse reference to its parent! seems xml definition is wrong
path
=
self
.
opc
.
get_node
(
"i=13387"
).
get_path_as_string
()
# FIXME this is wrong in our server! BaseObjectType is missing an inverse reference to its parent! seems xml definition is wrong
self
.
assertEqual
([
'0:BaseObjectType'
,
'0:FolderType'
,
'0:FileDirectoryType'
,
'0:CreateDirectory'
],
path
)
def
test_path
(
self
):
of
=
self
.
opc
.
nodes
.
objects
.
add_folder
(
1
,
"titif"
)
op
=
of
.
add_object
(
3
,
"opath"
)
path
=
op
.
get_path
()
self
.
assertEqual
([
self
.
opc
.
nodes
.
root
,
self
.
opc
.
nodes
.
objects
,
of
,
op
],
path
)
path
=
op
.
get_path
(
2
)
self
.
assertEqual
([
of
,
op
],
path
)
target
=
self
.
opc
.
get_node
(
"i=13387"
)
path
=
target
.
get_path
()
# FIXME this is wrong in our server! BaseObjectType is missing an inverse reference to its parent! seems xml definition is wrong
self
.
assertEqual
([
self
.
opc
.
nodes
.
base_object_type
,
self
.
opc
.
nodes
.
folder_type
,
self
.
opc
.
get_node
(
ua
.
ObjectIds
.
FileDirectoryType
),
target
],
path
)
def
test_get_endpoints
(
self
):
endpoints
=
self
.
opc
.
get_endpoints
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment