ChimeraTK-ApplicationCore 04.08.00
Loading...
Searching...
No Matches
drawModuleConnections.py
Go to the documentation of this file.
1#!/bin/python3
2
3import xml.etree.ElementTree as ET
4import sys
5
6ns = "{https://github.com/ChimeraTK/ApplicationCore}"
7
8moduleConnections = {}
9
10
11def parseVariable(node):
12 varDir = node.find(ns + 'direction').text
13
14 feeder = None
15 moduleList = set()
16
17 if varDir == 'control_system_to_application' or varDir == 'control_system_to_application_with_return':
18 return
19 feeder = 'ControlSystem'
20# else :
21# moduleList.add("ControlSystem")
22
23 for peer in node.find(ns + 'connections'):
24 peerType = peer.attrib['type']
25 peerDir = peer.attrib['direction']
26 if peerType == "ApplicationModule" or peerType == "Device":
27 if peerType == "ApplicationModule":
28 peerName = peer.attrib['class']
29 else:
30 peerName = 'Device:' + peer.attrib['name']
31 if peerDir == 'consuming':
32 moduleList.add(peerName)
33 else:
34 if feeder is not None:
35 print("ERROR: Found two feeders!")
36 print(node.attrib['name'])
37 sys.exit(1)
38 feeder = peerName
39
40 if feeder is None:
41 print("ERROR: No feeders found!")
42 print(node.attrib['name'])
43 sys.exit(1)
44
45 for m in moduleList:
46 if m not in moduleConnections.keys():
47 moduleConnections[m] = set()
48 if feeder not in moduleConnections.keys():
49 moduleConnections[feeder] = set()
50
51 for m in moduleList:
52 moduleConnections[feeder].add(m)
53
54
55def parseDirectory(subtree):
56
57 for node in subtree:
58
59 if node.tag == ns + 'directory':
60 parseDirectory(node)
61 elif node.tag == ns + 'variable':
62 parseVariable(node)
63
64
65tree = ET.parse('llrfctrl.xml')
66root = tree.getroot()
67
69
70print("digraph {")
71
72
73def makeNodeName(label):
74 name = label.replace(':', '_')
75 name = name.replace('/', '_')
76 name = name.replace('<', '_')
77 name = name.replace('>', '_')
78 name = name.replace(',', '_')
79 name = name.replace(' ', '_')
80 return name
81
82
83def defineNode(label):
84 if label not in nodeIds.keys():
85 nodeIds[label] = makeNodeName(label)
86 print(nodeIds[label] + ' [label="' + label + '", style=filled', end="")
87 if label.startswith("Device:"):
88 print(', fillcolor=silver', end="")
89 else:
90 print(', fillcolor=lightgreen', end="")
91 print(']')
92
93
94nodeIds = {}
95for source in moduleConnections.keys():
96 defineNode(source)
97 for target in moduleConnections[source]:
98 defineNode(target)
99
100
101for source in moduleConnections.keys():
102 if source is None:
103 continue
104 print(nodeIds[source] + ' -> { ', end="")
105 for target in moduleConnections[source]:
106 print(nodeIds[target] + ' ', end="")
107 print('}')
108
109print('}')