Commit 5253e734 authored by Daniel STAN's avatar Daniel STAN

[bcfg2-graph] comments+avoid sh module

parent 23a0a306
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Génère un graphe de dépendance des groups bcfg2
Auteurs: Daniel Stan
Valentin Samir
"""
from __future__ import print_function
import xml.dom.minidom
import subprocess
tmp_file = '/tmp/graph.gv'
GRAPH_BIN = '/usr/bin/neato'
TMP_FILE = '/tmp/graph.gv'
GROUPS_FILE = '/var/lib/bcfg2/Metadata/groups.xml'
OUTPUT_FILE = '/usr/scripts/var/doc/bcfg2/groups.svg'
out = file(tmp_file,'w')
out = file(TMP_FILE, 'w')
from sh import neato
from sh import date
import datetime
groups = xml.dom.minidom.parse(file('/var/lib/bcfg2/Metadata/groups.xml','r')).documentElement
# groups est le nœud racine
groups = xml.dom.minidom.parse(file(GROUPS_FILE,'r')).documentElement
print("""digraph G {
edge [len=4.50, ratio=fill]
""", file=out)
def childGroups(parent):
"""Récupère les groups enfants (dépendances) d'un nœud
Attention, cette fonction travaille sur (et renvoie) des nœuds xml
"""
return [ x for x in parent.childNodes if \
x.nodeType == x.ELEMENT_NODE and x.tagName == u'Group']
# Les clients
# Les clients (ie des serveurs)
# sont coloriés d'une autre couleur
print("""
subgraph cluster_1 {
node [style=filled];
......@@ -44,8 +59,8 @@ for elem in childGroups(groups):
print("""
label = "\\n\\nBCFG2 Groups\\nLes Nounous\\n%s";
}""" % str(date())[0:-1], file=out)
}""" % datetime.datetime.now().strftime('%c'), file=out)
out.close()
neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/bcfg2/groups.svg")
subprocess.Popen([GRAPH_BIN, "-Tsvg", TMP_FILE, "-o", OUTPUT_FILE]).communicate()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment