[bcfg2-graph] comments+avoid sh module
This commit is contained in:
parent
23a0a30678
commit
5253e7340c
1 changed files with 23 additions and 8 deletions
|
@ -1,26 +1,41 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Génère un graphe de dépendance des groups bcfg2
|
||||||
|
|
||||||
|
Auteurs: Daniel Stan
|
||||||
|
Valentin Samir
|
||||||
|
|
||||||
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import xml.dom.minidom
|
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
|
import datetime
|
||||||
from sh import date
|
|
||||||
|
|
||||||
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 {
|
print("""digraph G {
|
||||||
edge [len=4.50, ratio=fill]
|
edge [len=4.50, ratio=fill]
|
||||||
""", file=out)
|
""", file=out)
|
||||||
|
|
||||||
def childGroups(parent):
|
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 \
|
return [ x for x in parent.childNodes if \
|
||||||
x.nodeType == x.ELEMENT_NODE and x.tagName == u'Group']
|
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("""
|
print("""
|
||||||
subgraph cluster_1 {
|
subgraph cluster_1 {
|
||||||
node [style=filled];
|
node [style=filled];
|
||||||
|
@ -44,8 +59,8 @@ for elem in childGroups(groups):
|
||||||
|
|
||||||
print("""
|
print("""
|
||||||
label = "\\n\\nBCFG2 Groups\\nLes Nounous\\n%s";
|
label = "\\n\\nBCFG2 Groups\\nLes Nounous\\n%s";
|
||||||
}""" % str(date())[0:-1], file=out)
|
}""" % datetime.datetime.now().strftime('%c'), file=out)
|
||||||
|
|
||||||
out.close()
|
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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue