Commit 8abec216 authored by cirp-usf's avatar cirp-usf Committed by Christian Bergmiller

cherry-pick/merge 1354c094

parent ee39f2e0
......@@ -187,6 +187,12 @@ class NodeManagementService(object):
results.append(self._add_node(item, user))
return results
def try_add_nodes(self, addnodeitems, user=User.Admin):
for item in addnodeitems:
ret = self._add_node(item, user)
if not ret.StatusCode.is_good():
yield item
def _add_node(self, item, user):
result = ua.AddNodesResult()
......
......@@ -15,21 +15,28 @@ from opcua.server.standard_address_space.standard_address_space_part13 import cr
class PostponeReferences(object):
def __init__(self, server):
self.server = server
self.postponed = None
self.add_nodes = self.server.add_nodes
self.postponed_refs = None
self.postponed_nodes = None
#self.add_nodes = self.server.add_nodes
def add_nodes(self,nodes):
self.postponed_nodes.extend(self.server.try_add_nodes(nodes))
def add_references(self, refs):
self.postponed.extend(self.server.try_add_references(refs))
self.postponed_refs.extend(self.server.try_add_references(refs))
# no return
def __enter__(self):
self.postponed = []
self.postponed_refs = []
self.postponed_nodes = []
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is None and exc_val is None:
remaining = list(self.server.try_add_references(self.postponed))
assert len(remaining) == 0, remaining
remaining_nodes = list(self.server.try_add_nodes(self.postponed_nodes))
assert len(remaining_nodes) == 0, remaining_nodes
remaining_refs = list(self.server.try_add_references(self.postponed_refs))
assert len(remaining_refs) == 0, remaining_refs
def fill_address_space(nodeservice):
with PostponeReferences(nodeservice) as server:
......@@ -41,4 +48,3 @@ def fill_address_space(nodeservice):
create_standard_address_space_Part10(server)
create_standard_address_space_Part11(server)
create_standard_address_space_Part13(server)
assert len(server.postponed) == 1561, len(server.postponed)
......@@ -5,36 +5,36 @@ from urllib.request import build_opener
# https://opcfoundation.org/UA/schemas/OPC%20UA%20Schema%20Files%20Readme.xls
resources = [
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.Types.xsd',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.Services.wsdl',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.Endpoints.wsdl',
'https://opcfoundation.org/UA/schemas/DI/1.00/Opc.Ua.Di.Types.xsd',
'https://opcfoundation.org/UA/schemas/ADI/1.00/Opc.Ua.Adi.Types.xsd',
'https://opcfoundation.org/UA/schemas/1.03/SecuredApplication.xsd',
'https://opcfoundation.org/UA/schemas/1.03/UANodeSet.xsd',
'https://opcfoundation.org/UA/schemas/1.03/UAVariant.xsd',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part3.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part4.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part5.xml',
'https://opcfoundation.org/UA/schemas/Opc.Ua.NodeSet2.Part8.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part9.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part10.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part11.xml',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.NodeSet2.Part13.xml',
'https://opcfoundation.org/UA/schemas/DI/1.00/Opc.Ua.Di.NodeSet2.xml',
'https://opcfoundation.org/UA/schemas/ADI/1.00/Opc.Ua.Adi.NodeSet2.xml',
'https://opcfoundation.org/UA/schemas/1.03/OPCBinarySchema.xsd',
'https://opcfoundation.org/UA/schemas/1.03/Opc.Ua.Types.bsd',
'https://opcfoundation.org/UA/schemas/DI/1.00/Opc.Ua.Di.Types.bsd',
'https://opcfoundation.org/UA/schemas/ADI/1.00/Opc.Ua.Adi.Types.bsd',
'https://opcfoundation.org/UA/schemas/1.03/AttributeIds.csv',
'https://opcfoundation.org/UA/schemas/1.03/StatusCodes.csv',
'https://opcfoundation.org/UA/schemas/1.03/NodeIds.csv',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.Types.xsd',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.Services.wsdl',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.Endpoints.wsdl',
'https://opcfoundation.org/UA/schemas/DI/1.0/Opc.Ua.Di.Types.xsd',
'https://opcfoundation.org/UA/schemas/ADI/1.1/Opc.Ua.Adi.Types.xsd',
'https://opcfoundation.org/UA/schemas/1.04/SecuredApplication.xsd',
'https://opcfoundation.org/UA/schemas/1.04/UANodeSet.xsd',
'https://opcfoundation.org/UA/schemas/1.04/UAVariant.xsd',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part3.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part4.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part5.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part8.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part9.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part10.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part11.xml',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.NodeSet2.Part13.xml',
'https://opcfoundation.org/UA/schemas/DI/1.0/Opc.Ua.Di.NodeSet2.xml',
'https://opcfoundation.org/UA/schemas/ADI/1.1/Opc.Ua.Adi.NodeSet2.xml',
'https://opcfoundation.org/UA/schemas/1.04/OPCBinarySchema.xsd',
'https://opcfoundation.org/UA/schemas/1.04/Opc.Ua.Types.bsd',
'https://opcfoundation.org/UA/schemas/DI/1.0/Opc.Ua.Di.Types.bsd',
'https://opcfoundation.org/UA/schemas/ADI/1.1/Opc.Ua.Adi.Types.bsd',
'https://opcfoundation.org/UA/schemas/1.04/AttributeIds.csv',
'https://opcfoundation.org/UA/schemas/1.04/StatusCode.csv',
'https://opcfoundation.org/UA/schemas/1.04/NodeIds.csv',
]
opener = build_opener()
......
......@@ -151,14 +151,14 @@ def create_standard_address_space_{self.part!s}(server):
self.writecode(indent, 'value = extobj')
self.writecode(indent, 'attrs.Value = ua.Variant(value, ua.VariantType.ExtensionObject)')
elif obj.valuetype == "ListOfLocalizedText":
value = [f'ua.LocalizedText({self.to_value(text)})' for text in obj.value]
value = [f'ua.LocalizedText({text!r})' for text in obj.value]
self.writecode(indent, f'attrs.Value = [{",".join(value)}]')
else:
if obj.valuetype.startswith("ListOf"):
obj.valuetype = obj.valuetype[6:]
self.writecode(
indent,
f'attrs.Value = ua.Variant({self.to_value(obj.value)}, ua.VariantType.{obj.valuetype})'
f'attrs.Value = ua.Variant({obj.value!r}, ua.VariantType.{obj.valuetype})'
)
if obj.rank:
self.writecode(indent, f'attrs.ValueRank = {obj.rank}')
......@@ -211,13 +211,6 @@ def create_standard_address_space_{self.part!s}(server):
self.writecode(indent, 'server.add_nodes([node])')
self.make_refs_code(obj, indent)
def to_value(self, val):
# if type(val) in (str, unicode):
if isinstance(val, str):
return f'"{val}"'
else:
return val
def make_method_code(self, obj):
indent = " "
self.writecode(indent)
......
......@@ -16,7 +16,7 @@ class EventsCodeGenerator(object):
root = tree.getroot()
for child in root:
if child.tag.endswith("UAObjectType"):
print child.attrib
print (child.attrib)
def write(self, line):
if line:
......@@ -94,7 +94,7 @@ class EventsCodeGenerator(object):
def generateEventsCode(self, model):
self.output_file = open(self.output_file, "w")
self.make_header()
for event in model.itervalues():
for event in model.values():
if (event.browseName == "BaseEvent"):
self.generateEventclass(event)
else:
......@@ -104,7 +104,7 @@ class EventsCodeGenerator(object):
self.write("")
self.write("IMPLEMENTED_EVENTS = {")
self.iidx += 1
for event in model.itervalues():
for event in model.values():
self.write("ua.ObjectIds.{0}Type: {0},".format(event.browseName))
self.write("}")
......
......@@ -313,6 +313,7 @@ class Parser(object):
tree = ElementTree.parse(self.path)
root = tree.getroot()
self.add_extension_object()
self.add_data_type_definition()
for child in root:
tag = child.tag[40:]
if tag == 'StructuredType':
......@@ -352,6 +353,12 @@ class Parser(object):
self.model.structs.append(obj)
def add_data_type_definition(self):
obj = Struct()
obj.name = "DataTypeDefinition"
self.model.struct_list.append(obj.name)
self.model.structs.append(obj)
def parse_struct(self, child):
tag = child.tag[40:]
struct = Struct()
......
......@@ -8,7 +8,7 @@ def status_codes():
name, val, doc = line.split(",", 2)
additional[int(val, 0)] = (name, val, doc)
inputfile = open("StatusCodes.csv")
inputfile = open("StatusCode.csv")
result = []
for line in inputfile:
name, val, doc = line.split(",", 2)
......
......@@ -5,7 +5,7 @@ from string import Template
if __name__ == "__main__":
codes = status_codes()
with open("../opcua/ua/errors/_auto.py", "w") as f:
with open("../opcua/ua/uaerrors/_auto.py", "w") as f:
preamble = """\
#AUTOGENERATED!!!
......
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