summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtools/groups-to-dot.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/tools/groups-to-dot.py b/tools/groups-to-dot.py
index 164d5599d..f3a009c4e 100755
--- a/tools/groups-to-dot.py
+++ b/tools/groups-to-dot.py
@@ -3,17 +3,18 @@
'''This script generates graphviz diagrams using bcfg2 metadata'''
__revision__ = '$Revision$'
-import lxml.etree, sys
+import lxml.etree, sys, popen2
colors = ['aquamarine', 'chartreuse', 'gold', 'magenta', 'indianred1', 'limegreen', 'midnightblue',
'lightblue', 'limegreen']
if __name__ == '__main__':
if len(sys.argv) < 2:
- print "Usage groups-to-dot.py [-h] <metadatadir>"
+ print "Usage groups-to-dot.py [-h] -o <outputfile> <metadatadir>"
raise SystemExit, 1
groups = lxml.etree.parse(sys.argv[-1] + '/groups.xml').getroot()
- clients= lxml.etree.parse(sys.argv[-1] + '/clients.xml').getroot()
+ clients = lxml.etree.parse(sys.argv[-1] + '/clients.xml').getroot()
+ dotpipe = popen2.Popen4("dot -Tpng")
categories = {'default':'grey83'}
instances = {}
for group in groups.findall('Group'):
@@ -21,9 +22,9 @@ if __name__ == '__main__':
if not categories.has_key(group.get('category')):
categories[group.get('category')] = colors.pop()
- print "digraph groups {"
+ dotpipe.tochild.write("digraph groups {\n")
if '-h' in sys.argv:
- print '\trankdir="LR";'
+ dotpipe.tochild.write('\trankdir="LR";\n')
for client in clients.findall('Client'):
if instances.has_key(client.get('profile')):
instances[client.get('profile')].append(client.get('name'))
@@ -31,8 +32,8 @@ if __name__ == '__main__':
instances[client.get('profile')] = [client.get('name')]
for profile, clist in instances.iteritems():
clist.sort()
- print '''\t"%s-instances" [ label="%s", shape="record" ];''' % (profile, '|'.join(clist))
- print '''\t"%s-instances" -> "%s";''' % (profile, profile)
+ dotpipe.tochild.write('''\t"%s-instances" [ label="%s", shape="record" ];\n''' % (profile, '|'.join(clist)))
+ dotpipe.tochild.write('''\t"%s-instances" -> "group-%s";\n''' % (profile, profile))
if '-b' in sys.argv:
bundles = []
@@ -40,20 +41,30 @@ if __name__ == '__main__':
if bund.get('name') not in bundles]
bundles.sort()
for bundle in bundles:
- print '''\t"%s" [ shape="rect"];''' % (bundle)
+ dotpipe.tochild.write('''\t"bundle-%s" [ label="%s", shape="rect"];\n''' % (bundle, bundle))
for group in groups.findall('Group'):
color = categories[group.get('category', 'default')]
if group.get('profile', 'false') == 'true':
- print '\t"%s" [style="filled,bold", fillcolor=%s];' % (group.get('name'), color)
+ style="filled, bold"
else:
- print '\t"%s" [style="filled", fillcolor=%s];' % (group.get('name'), color)
+ style = "filled"
+ dotpipe.tochild.write('\t"group-%s" [label="%s", style="%s", fillcolor=%s];\n' %
+ (group.get('name'), group.get('name'), style, color))
if '-b' in sys.argv:
for bundle in group.findall('Bundle'):
- print '\t"%s" -> "%s";' % (group.get('name'), bundle.get('name'))
+ dotpipe.tochild.write('\t"group-%s" -> "bundle-%s";\n' %
+ (group.get('name'), bundle.get('name')))
for group in groups.findall('Group'):
for parent in group.findall('Group'):
- print '\t"%s" -> "%s" ;' % (group.get('name'), parent.get('name'))
- print "}"
+ dotpipe.tochild.write('\t"group-%s" -> "group-%s" ;\n' %
+ (group.get('name'), parent.get('name')))
+ dotpipe.tochild.write("}\n")
+ dotpipe.tochild.close()
+ data = dotpipe.fromchild.read()
+ if '-o' in sys.argv:
+ output = open(sys.argv[sys.argv.index('-o') + 1], 'w').write(data)
+ else:
+ print data