460 Parse an existing map file.
461 @param inputFile: The map file name.
462 @return: list that includes the number of not found directories (index 0), pvs (index 1) and excludes (index 2).
463 In the map file the sourceName is given and it can happen that the source
464 given in the map file does not correspond to a PV or directory from the original
466 @raise RuntimeError: If the given input file is not a mapping XML file.
467 A mapping file is identified by the root node called 'uamapping'.
469 logging.debug(
"Parsing map file.")
473 if data.tag ==
'uamapping':
474 nsmap = {
'csa':
'https://github.com/ChimeraTK/ControlSystemAdapter-OPC-UA-Adapter'}
475 if nsmap != data.nsmap:
476 RuntimeError(
"Wrong name space ({}) used in mapping file.".format(data.nsmap))
484 for folder
in data.findall(
'folder', namespaces=data.nsmap):
485 if "sourceName" in folder.attrib:
486 directory = self.
dir.findDir(
"/root/" +
str(folder.attrib[
"sourceName"]))
487 if directory !=
None:
492 if 'history' in folder.attrib:
493 directory.historizing =
str(folder.attrib[
"history"])
494 if folder.find(
'description', namespaces=folder.nsmap) !=
None and folder.find(
'description', namespaces=folder.nsmap).text !=
None:
495 directory.newDescription = folder.find(
'description', namespaces=folder.nsmap).text
496 if folder.find(
'destination', namespaces=folder.nsmap) !=
None and folder.find(
'destination', namespaces=folder.nsmap).text !=
None:
497 tmpDestination = directory.path.removeprefix(
"/root").removeprefix(
"/").removesuffix(directory.name).removesuffix(
"/")
498 tmpPath = tmpPath + folder.find(
'destination', namespaces=folder.nsmap).text
499 if tmpDestination != folder.find(
'destination', namespaces=folder.nsmap).text:
500 directory.newDestination =
"/root/"+folder.find(
'destination', namespaces=folder.nsmap).text
501 if folder.find(
'name', namespaces=folder.nsmap) !=
None and directory.name != folder.find(
'name', namespaces=folder.nsmap).text:
502 directory.newName = folder.find(
'name', namespaces=folder.nsmap).text
504 tmpPath = tmpPath.removesuffix(
"/") +
"/" + folder.find(
'name', namespaces=folder.nsmap).text
505 if directory.newDestination ==
None and tmpPath != directory.path:
506 directory.newDestination =
"/root"
508 logging.warning(
"Failed to find source folder path {} in the application variable tree!".format(
"/root/" +
str(folder.attrib[
"sourceName"])))
509 nSkipped[0] = nSkipped[0] + 1
511 tmpDestination =
None
513 if folder.find(
'destination', namespaces=folder.nsmap) !=
None:
514 tmpDestination = folder.find(
'destination', namespaces=folder.nsmap).text
515 if folder.find(
'name', namespaces=folder.nsmap) !=
None:
516 tmpName = folder.find(
'name', namespaces=folder.nsmap).text
518 logging.warning(
"For folder entry in the map file with no sourceName no name is given. Will be skipped.")
519 tmpSourceName =
"/root/"
520 if tmpDestination ==
None:
521 tmpSourceName = tmpSourceName + tmpName
523 tmpSourceName = tmpSourceName + tmpDestination +
"/" + tmpName
524 directory = self.
dir.findDir(tmpSourceName)
525 if directory !=
None:
526 if folder.find(
'description', namespaces=folder.nsmap) !=
None:
527 directory.newDescription = folder.find(
'description', namespaces=folder.nsmap).text
529 logging.warning(
"Failed to find source folder path {} in the application variable tree!".format(tmpSourceName))
530 nSkipped[0] = nSkipped[0] + 1
532 for pv
in data.findall(
'process_variable', namespaces=data.nsmap):
533 if "sourceName" in pv.attrib:
534 var = self.
dir.findVar(
"/root/" +
str(pv.attrib[
"sourceName"]))
536 if 'history' in pv.attrib:
537 var.historizing =
str(pv.attrib[
"history"])
538 if pv.find(
'description', namespaces=pv.nsmap) !=
None:
539 var.newDescription = pv.find(
'description', namespaces=pv.nsmap).text
540 if pv.find(
'unit', namespaces=pv.nsmap) !=
None:
541 var.newUnit = pv.find(
'unit', namespaces=pv.nsmap).text
542 if pv.find(
'name', namespaces=pv.nsmap) !=
None:
543 var.newName = pv.find(
'name', namespaces=pv.nsmap).text
544 if pv.find(
'destination', namespaces=pv.nsmap) !=
None:
545 var.newDestination = pv.find(
'destination', namespaces=pv.nsmap).text
546 if (var.newDestination ==
"" or var.newDestination ==
None)
and var.name == var.newName:
547 var.newDestination =
"/root"
550 logging.warning(
"Failed to find source pv path {} in the application variable tree!".format(
"/root/" +
str(pv.attrib[
"sourceName"])))
551 nSkipped[1] = nSkipped[1] + 1
552 for exclude
in data.findall(
'exclude', namespaces=data.nsmap):
553 if "sourceName" in exclude.attrib:
554 if exclude.attrib[
"sourceName"].endswith(
"/*"):
555 directory = self.
dir.findDir(
"/root/" + exclude.attrib[
"sourceName"][0:-2])
556 if directory !=
None:
557 directory.exclude =
True
559 logging.warning(
"Failed to find source exclude path {} in the application variable tree!".format(
"/root/" +
str(exclude.attrib[
"sourceName"][0:-2])))
560 nSkipped[2] = nSkipped[2] + 1
562 var = self.
dir.findVar(
"/root/" + exclude.attrib[
"sourceName"])
566 logging.warning(
"Failed to find source exclude path {} in the application variable tree!".format(
"/root/" +
str(exclude.attrib[
"sourceName"])))
567 nSkipped[2] = nSkipped[2] + 1
570 raise RuntimeError(
"Failed to find uamapping tag. Not an ControlSystem-OPC-UA XML mapping file.")