5 def copy_node(parent, node, nodeid=None, recursive=True):
7 Copy a node or node tree as child of parent node 9 print(
"Copying", node,
"into ", parent)
13 nodeid =
ua.NodeId(namespaceidx=node.nodeid.NamespaceIndex)
14 added_nodeids =
_copy_node(parent.server, parent.nodeid, rdesc, nodeid, recursive)
15 return [
Node(parent.server, nid)
for nid
in added_nodeids]
18 def _copy_node(server, parent_nodeid, rdesc, nodeid, recursive):
20 addnode.RequestedNewNodeId = nodeid
21 addnode.BrowseName = rdesc.BrowseName
22 addnode.ParentNodeId = parent_nodeid
23 addnode.ReferenceTypeId = rdesc.ReferenceTypeId
24 addnode.TypeDefinition = rdesc.TypeDefinition
25 addnode.NodeClass = rdesc.NodeClass
27 node_to_copy =
Node(server, rdesc.NodeId)
29 attrObj = getattr(ua, rdesc.NodeClass.name +
"Attributes")
32 res = server.add_nodes([addnode])[0]
34 added_nodes = [res.AddedNodeId]
37 descs = node_to_copy.get_children_descriptions()
39 nodes =
_copy_node(server, res.AddedNodeId, desc, nodeid=
ua.NodeId(namespaceidx=desc.NodeId.NamespaceIndex), recursive=
True)
40 added_nodes.extend(nodes)
46 results = node.get_attributes([ua.AttributeIds.NodeClass, ua.AttributeIds.BrowseName, ua.AttributeIds.DisplayName])
47 nclass, qname, dname = [res.Value.Value
for res
in results]
50 rdesc.NodeId = node.nodeid
51 rdesc.BrowseName = qname
52 rdesc.DisplayName = dname
53 rdesc.NodeClass = nclass
54 if parent.get_type_definition() ==
ua.NodeId(ua.ObjectIds.FolderType):
55 rdesc.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.Organizes)
57 rdesc.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.HasComponent)
58 typedef = node.get_type_definition()
60 rdesc.TypeDefinition = typedef
65 names = [name
for name
in struct.__dict__.keys()
if not name.startswith(
"_")
and name
not in (
"BodyLength",
"TypeId",
"SpecifiedAttributes",
"Encoding",
"IsAbstract",
"EventNotifier")]
68 results = node_type.get_attributes(attrs)
69 for idx, name
in enumerate(names):
70 if results[idx].StatusCode.is_good():
72 setattr(struct, name, results[idx].Value)
74 setattr(struct, name, results[idx].Value.Value)
76 print(
"Instantiate: while copying attributes from node type {0!s}, attribute {1!s}, statuscode is {2!s}".format(node_type, name, results[idx].StatusCode))
77 addnode.NodeAttributes = struct
def _rdesc_from_node(parent, node)
def _copy_node(server, parent_nodeid, rdesc, nodeid, recursive)
def copy_node(parent, node, nodeid=None, recursive=True)
def _read_and_copy_attrs(node_type, struct, addnode)