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
092a7817
Commit
092a7817
authored
Aug 06, 2020
by
oroulet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
while importing xml, check for parents in all nodes in caseit is not declared locally
parent
4866eef1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletion
+27
-1
asyncua/common/shortcuts.py
asyncua/common/shortcuts.py
+3
-0
asyncua/common/xmlimporter.py
asyncua/common/xmlimporter.py
+23
-0
asyncua/common/xmlparser.py
asyncua/common/xmlparser.py
+1
-1
No files found.
asyncua/common/shortcuts.py
View file @
092a7817
...
...
@@ -27,3 +27,6 @@ class Shortcuts(object):
self
.
opc_binary
=
Node
(
server
,
ObjectIds
.
OPCBinarySchema_TypeSystem
)
self
.
base_structure_type
=
Node
(
server
,
ObjectIds
.
Structure
)
self
.
server_state
=
Node
(
server
,
ObjectIds
.
Server_ServerStatus_State
)
self
.
HasComponent
=
Node
(
server
,
ObjectIds
.
HasComponent
)
self
.
HasProperty
=
Node
(
server
,
ObjectIds
.
HasProperty
)
self
.
Organizes
=
Node
(
server
,
ObjectIds
.
Organizes
)
asyncua/common/xmlimporter.py
View file @
092a7817
...
...
@@ -52,10 +52,12 @@ class XmlImporter:
self
.
parser
=
XMLParser
()
await
self
.
parser
.
parse
(
xmlpath
,
xmlstring
)
self
.
namespaces
=
await
self
.
_map_namespaces
(
self
.
parser
.
get_used_namespaces
())
_logger
.
info
(
"namespace map: %s"
,
self
.
namespaces
)
self
.
aliases
=
self
.
_map_aliases
(
self
.
parser
.
get_aliases
())
self
.
refs
=
[]
dnodes
=
self
.
parser
.
get_node_datas
()
dnodes
=
self
.
make_objects
(
dnodes
)
self
.
_add_missing_parents
(
dnodes
)
nodes_parsed
=
self
.
_sort_nodes_by_parentid
(
dnodes
)
nodes
=
[]
for
nodedata
in
nodes_parsed
:
# self.parser:
...
...
@@ -71,6 +73,27 @@ class XmlImporter:
_logger
.
warning
(
"The following references could not be imported and are probably broken: %s"
,
self
.
refs
)
return
nodes
def
_add_missing_parents
(
self
,
dnodes
):
missing
=
[]
childs
=
{}
for
nd
in
dnodes
:
if
not
nd
.
parent
or
nd
.
parent
==
nd
.
nodeid
:
missing
.
append
(
nd
)
for
ref
in
nd
.
refs
:
if
ref
.
forward
:
if
ref
.
reftype
in
[
self
.
server
.
nodes
.
HasComponent
.
nodeid
,
self
.
server
.
nodes
.
HasProperty
.
nodeid
,
self
.
server
.
nodes
.
Organizes
.
nodeid
]:
# if a node has several links, the last one will win
if
ref
.
target
in
childs
:
_logger
.
warning
(
"overwriting parent target, shouldbe fixed"
,
ref
.
target
,
nd
.
nodeid
,
ref
.
reftype
,
childs
[
ref
.
target
])
childs
[
ref
.
target
]
=
(
nd
.
nodeid
,
ref
.
reftype
)
for
nd
in
missing
:
if
nd
.
nodeid
in
childs
:
target
,
reftype
=
childs
[
nd
.
nodeid
]
nd
.
parent
=
target
nd
.
parentlink
=
reftype
from
IPython
import
embed
embed
()
async
def
_add_node_data
(
self
,
nodedata
)
->
"Node"
:
if
nodedata
.
nodetype
==
"UAObject"
:
node
=
await
self
.
add_object
(
nodedata
)
...
...
asyncua/common/xmlparser.py
View file @
092a7817
...
...
@@ -174,7 +174,7 @@ class XMLParser:
obj
.
nodetype
=
nodetype
for
key
,
val
in
child
.
attrib
.
items
():
self
.
_set_attr
(
key
,
val
,
obj
)
self
.
logger
.
info
(
"Parsing node: %s %s"
,
obj
.
nodeid
,
obj
.
browsename
)
self
.
logger
.
debug
(
"Parsing node: %s %s"
,
obj
.
nodeid
,
obj
.
browsename
)
obj
.
displayname
=
obj
.
browsename
# give a default value to display name
for
el
in
child
:
self
.
_parse_attr
(
el
,
obj
)
...
...
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