ChimeraTK-ApplicationCore 04.08.00
Loading...
Searching...
No Matches
variableHouseoldToWikiTable.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3import sys
4import xml.etree.ElementTree as ET
5
6
7def findCommonPrefix(string1, string2):
8 length = min(len(string1), len(string2))
9 for i in range(length):
10 if string1[i] != string2[i]:
11 return string1[0:i - 1]
12 if len(string1) < len(string2):
13 return string1
14 else:
15 return string2
16
17
18def parseDirectory(directory, cwd, stripDescriptionPrefix):
19
20 for elem in directory.findall("{https://github.com/ChimeraTK/ApplicationCore}variable"):
21 varname = elem.attrib["name"]
22 vartype = elem.find("{https://github.com/ChimeraTK/ApplicationCore}value_type").text
23 vardirection = elem.find("{https://github.com/ChimeraTK/ApplicationCore}direction").text
24 varunit = elem.find("{https://github.com/ChimeraTK/ApplicationCore}unit").text
25 if not varunit:
26 varunit = ""
27 vardescription = elem.find("{https://github.com/ChimeraTK/ApplicationCore}description").text
28 if not vardescription:
29 vardescription = ""
30 varlength = int(elem.find("{https://github.com/ChimeraTK/ApplicationCore}numberOfElements").text)
31
32 if vardirection == "application_to_control_system":
33 thetype = vartype + " (ro)"
34 else:
35 thetype = vartype
36 if varlength > 1:
37 thetype = thetype + " (" + str(varlength) + " elements)"
38
39 print("| " + varname + " | " + vartype + " | " + varunit +
40 " | " + vardescription[stripDescriptionPrefix:] + " |")
41
42 for elem in directory.findall("{https://github.com/ChimeraTK/ApplicationCore}directory"):
43 dirdescription = ""
44 for subelem in elem.findall("{https://github.com/ChimeraTK/ApplicationCore}variable"):
45 vardescription = subelem.find("{https://github.com/ChimeraTK/ApplicationCore}description").text
46 if not vardescription:
47 vardescription = ""
48 if dirdescription == "":
49 dirdescription = vardescription
50 else:
51 dirdescription = findCommonPrefix(dirdescription, vardescription)
52
53 print("^ " + cwd + "/" + elem.attrib["name"] + " - " + dirdescription[:-2] + " ||||")
54
55 parseDirectory(elem, cwd + "/" + elem.attrib["name"], len(dirdescription) + 1)
56
57
58if len(sys.argv) != 2:
59 print("Usage: variableHouseholdToWikiTable.py <xml_file_name>")
60 sys.exit(1)
61
62filename = sys.argv[1]
63
64
65print("^ PV name ^ Type ^ Unit ^ Description ^")
66
67tree = ET.parse("llrfctrl.xml")
68root = tree.getroot()
69parseDirectory(root, "", 0)
parseDirectory(directory, cwd, stripDescriptionPrefix)