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
4d2a6fb8
Commit
4d2a6fb8
authored
Jul 17, 2022
by
Alexander Schrode
Committed by
oroulet
Jul 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add namespace meta data
parent
7456fac3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
+53
-0
asyncua/common/xmlimporter.py
asyncua/common/xmlimporter.py
+21
-0
asyncua/common/xmlparser.py
asyncua/common/xmlparser.py
+18
-0
tests/test_xml.py
tests/test_xml.py
+14
-0
No files found.
asyncua/common/xmlimporter.py
View file @
4d2a6fb8
...
@@ -93,6 +93,26 @@ class XmlImporter:
...
@@ -93,6 +93,26 @@ class XmlImporter:
raise
ValueError
(
"Server doesn't satisfy required XML-Models. Import them first!"
)
raise
ValueError
(
"Server doesn't satisfy required XML-Models. Import them first!"
)
return
None
return
None
async
def
_check_if_namespace_meta_information_is_added
(
self
):
"""
check if the NamespaceMetadata objects in server namespaces exists otherwise add them
to prevent errors when other nodesets depend on this namespace.
"""
descs
=
await
self
.
server
.
nodes
.
namespaces
.
get_children_descriptions
()
ns_objs
=
[
n
.
BrowseName
.
Name
for
n
in
descs
]
for
uri
,
version
,
pub_date
in
self
.
parser
.
get_nodeset_namespaces
():
if
uri
not
in
ns_objs
:
idx
=
await
self
.
server
.
register_namespace
(
uri
)
obj
=
await
self
.
nodes
.
namespaces
.
add_object
(
idx
,
uri
,
ua
.
ObjectIds
.
NamespaceMetadataType
,
False
)
ns_uri
=
await
obj
.
get_child
(
'NamespaceUri'
)
await
ns_uri
.
write_value
(
uri
,
ua
.
VariantType
.
String
)
ns_ver
=
await
obj
.
get_child
(
'NamespaceVersion'
)
await
ns_ver
.
write_value
(
version
,
ua
.
VariantType
.
String
)
ns_date
=
await
obj
.
get_child
(
'NamespacePublicationDate'
)
await
ns_date
.
write_value
(
pub_date
)
ns_subset
=
await
obj
.
get_child
(
'IsNamespaceSubset'
)
await
ns_subset
.
write_value
(
True
)
async
def
import_xml
(
self
,
xmlpath
=
None
,
xmlstring
=
None
):
async
def
import_xml
(
self
,
xmlpath
=
None
,
xmlstring
=
None
):
"""
"""
import xml and return added nodes
import xml and return added nodes
...
@@ -131,6 +151,7 @@ class XmlImporter:
...
@@ -131,6 +151,7 @@ class XmlImporter:
"The following references could not be imported and are probably broken: %s"
,
"The following references could not be imported and are probably broken: %s"
,
self
.
refs
,
self
.
refs
,
)
)
await
self
.
_check_if_namespace_meta_information_is_added
()
return
nodes
return
nodes
async
def
_add_missing_reverse_references
(
self
,
new_nodes
):
async
def
_add_missing_reverse_references
(
self
,
new_nodes
):
...
...
asyncua/common/xmlparser.py
View file @
4d2a6fb8
...
@@ -5,6 +5,7 @@ import re
...
@@ -5,6 +5,7 @@ import re
import
asyncio
import
asyncio
import
base64
import
base64
import
logging
import
logging
from
typing
import
List
,
Tuple
import
xml.etree.ElementTree
as
ET
import
xml.etree.ElementTree
as
ET
from
pytz
import
utc
from
pytz
import
utc
...
@@ -439,3 +440,20 @@ class XMLParser:
...
@@ -439,3 +440,20 @@ class XMLParser:
# check if ModelUri X, in Version Y from time Z was already imported
# check if ModelUri X, in Version Y from time Z was already imported
required_models
.
append
(
child
.
attrib
)
required_models
.
append
(
child
.
attrib
)
return
required_models
return
required_models
def
get_nodeset_namespaces
(
self
)
->
List
[
Tuple
[
str
,
ua
.
String
,
ua
.
DateTime
]]:
"""
Get all namespaces that are registered with version and date_time
"""
ns
=
[]
for
model
in
self
.
root
.
findall
(
'base:Models/base:Model'
,
self
.
ns
):
uri
=
model
.
attrib
.
get
(
'ModelUri'
)
if
uri
is
not
None
:
version
=
model
.
attrib
.
get
(
'Version'
,
ua
.
String
())
date_time
=
model
.
attrib
.
get
(
'PublicationDate'
)
if
date_time
is
None
:
date_time
=
ua
.
DateTime
(
1
,
1
,
1
)
else
:
date_time
=
ua
.
DateTime
.
strptime
(
date_time
,
"%Y-%m-%dT%H:%M:%SZ"
)
ns
.
append
((
uri
,
version
,
date_time
))
return
ns
tests/test_xml.py
View file @
4d2a6fb8
...
@@ -582,3 +582,17 @@ async def test_disable_xml_export_without_value(opc, tmpdir):
...
@@ -582,3 +582,17 @@ async def test_disable_xml_export_without_value(opc, tmpdir):
assert
dv
.
Value
!=
v
.
Value
assert
dv
.
Value
!=
v
.
Value
assert
v
.
Value
.
Value
is
None
assert
v
.
Value
.
Value
is
None
await
opc
.
opc
.
delete_nodes
([
o2
])
await
opc
.
opc
.
delete_nodes
([
o2
])
async
def
test_if_missing_meta_data_is_added
(
opc
):
# check if missing namespace infos are added
urn
=
"http://yourorganisation.org/testenum104/"
idx
=
await
opc
.
opc
.
register_namespace
(
urn
)
await
opc
.
opc
.
import_xml
(
CUSTOM_REQ_XML_PASS_PATH
)
o
=
await
opc
.
opc
.
nodes
.
namespaces
.
get_child
([
f"
{
idx
}
:
{
urn
}
"
])
assert
await
(
await
o
.
get_child
(
"NamespaceUri"
)).
read_value
()
==
urn
assert
await
(
await
o
.
get_child
(
"NamespaceVersion"
)).
read_value
()
==
"1.0.0"
dt
=
await
(
await
o
.
get_child
(
"NamespacePublicationDate"
)).
read_value
()
assert
dt
.
year
==
2020
assert
dt
.
month
==
8
assert
dt
.
day
==
11
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