ChimeraTK-ApplicationCore 04.06.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
17def parseDirectory(directory, cwd, stripDescriptionPrefix) :
18
19 for elem in directory.findall("{https://github.com/ChimeraTK/ApplicationCore}variable") :
20 varname = elem.attrib["name"]
21 vartype = elem.find("{https://github.com/ChimeraTK/ApplicationCore}value_type").text
22 vardirection = elem.find("{https://github.com/ChimeraTK/ApplicationCore}direction").text
23 varunit = elem.find("{https://github.com/ChimeraTK/ApplicationCore}unit").text
24 if not varunit :
25 varunit = ""
26 vardescription = elem.find("{https://github.com/ChimeraTK/ApplicationCore}description").text
27 if not vardescription :
28 vardescription = ""
29 varlength = int(elem.find("{https://github.com/ChimeraTK/ApplicationCore}numberOfElements").text)
30
31 if vardirection == "application_to_control_system" :
32 thetype=vartype+" (ro)"
33 else :
34 thetype=vartype
35 if varlength > 1 :
36 thetype=thetype+" ("+str(varlength)+" elements)"
37
38 print("| "+varname+" | "+vartype+" | "+varunit+" | "+vardescription[stripDescriptionPrefix:]+" |")
39
40 for elem in directory.findall("{https://github.com/ChimeraTK/ApplicationCore}directory") :
41 dirdescription = ""
42 for subelem in elem.findall("{https://github.com/ChimeraTK/ApplicationCore}variable") :
43 vardescription = subelem.find("{https://github.com/ChimeraTK/ApplicationCore}description").text
44 if not vardescription :
45 vardescription = ""
46 if dirdescription == "" :
47 dirdescription = vardescription
48 else :
49 dirdescription = findCommonPrefix(dirdescription, vardescription)
50
51 print("^ "+cwd+"/"+elem.attrib["name"]+" - "+dirdescription[:-2]+" ||||")
52
53 parseDirectory(elem, cwd+"/"+elem.attrib["name"], len(dirdescription)+1)
54
55
56if len(sys.argv) != 2 :
57 print("Usage: variableHouseholdToWikiTable.py <xml_file_name>")
58 sys.exit(1)
59
60filename=sys.argv[1]
61
62
63print("^ PV name ^ Type ^ Unit ^ Description ^")
64
65tree = ET.parse("llrfctrl.xml")
66root = tree.getroot()
67parseDirectory(root,"",0)
parseDirectory(directory, cwd, stripDescriptionPrefix)