[sip/asterisk-graph] Supression du fichier temporaire
On écrit directement dans PIPE avec subprocess
This commit is contained in:
parent
c8cee16a97
commit
77fa3f6404
1 changed files with 72 additions and 61 deletions
|
@ -1,23 +1,28 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
# -*- coding: utf-8 -*-
|
||||||
from sh import neato
|
"""
|
||||||
from sh import date
|
Génère un graphe de dépendance des extensions
|
||||||
from sh import dot
|
du plan de numérotation d'asterisk
|
||||||
|
|
||||||
tmp_file = '/tmp/graph.gv'
|
Auteur: Valentin Samir
|
||||||
exten_file = '/etc/asterisk/extensions.conf'
|
|
||||||
start_nodes = ["crans-sip", "crans-from-external", "ovh-sip", "crans-sms" ]
|
|
||||||
|
|
||||||
out = file(tmp_file,'w')
|
"""
|
||||||
|
|
||||||
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
|
import time
|
||||||
|
|
||||||
|
def gen_extentions_graph(exten_file, start_nodes, svg_file):
|
||||||
|
|
||||||
|
out=""
|
||||||
arrow={}
|
arrow={}
|
||||||
iarrow={}
|
iarrow={}
|
||||||
|
|
||||||
print("""digraph G {
|
out+="""digraph G {
|
||||||
rankdir=LR
|
rankdir=LR
|
||||||
edge [len=2.50, ratio=fill]
|
edge [len=2.50, ratio=fill]
|
||||||
""", file=out)
|
"""
|
||||||
for node in start_nodes:
|
for node in start_nodes:
|
||||||
print('"%s" [style=filled];' % node, file=out)
|
out+='"%s" [style=filled];' % node
|
||||||
|
|
||||||
file=open(exten_file).read()
|
file=open(exten_file).read()
|
||||||
file=file.split('\n[')
|
file=file.split('\n[')
|
||||||
|
@ -28,7 +33,7 @@ for context in file:
|
||||||
arrow[context_name]= arrow.get(context_name, set())
|
arrow[context_name]= arrow.get(context_name, set())
|
||||||
iarrow[context_name]= iarrow.get(context_name, set())
|
iarrow[context_name]= iarrow.get(context_name, set())
|
||||||
del(context[0])
|
del(context[0])
|
||||||
print('"%s";' % context_name, file=out)
|
out+='"%s";' % context_name
|
||||||
for line in context:
|
for line in context:
|
||||||
if line.startswith('include'):
|
if line.startswith('include'):
|
||||||
dest=line.split('=>', 1)[1].strip()
|
dest=line.split('=>', 1)[1].strip()
|
||||||
|
@ -41,12 +46,12 @@ for context in file:
|
||||||
|
|
||||||
for (context_name, dests) in arrow.items():
|
for (context_name, dests) in arrow.items():
|
||||||
for dest in dests:
|
for dest in dests:
|
||||||
print('"%s" -> "%s" [arrowhead=normal];' % (context_name, dest), file=out)
|
out+='"%s" -> "%s" [arrowhead=normal];' % (context_name, dest)
|
||||||
for (context_name, dests) in iarrow.items():
|
for (context_name, dests) in iarrow.items():
|
||||||
for dest in dests:
|
for dest in dests:
|
||||||
print('"%s" -> "%s" [arrowhead=crow, style=dashed];' % (context_name, dest), file=out)
|
out+='"%s" -> "%s" [arrowhead=crow, style=dashed];' % (context_name, dest)
|
||||||
|
|
||||||
print("""
|
out+="""
|
||||||
node [shape=plaintext]
|
node [shape=plaintext]
|
||||||
subgraph cluster_01 {
|
subgraph cluster_01 {
|
||||||
key [label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
|
key [label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
|
||||||
|
@ -60,13 +65,19 @@ print("""
|
||||||
key:i1:e -> key2:j1:e [style=dashed, arrowhead=crow]
|
key:i1:e -> key2:j1:e [style=dashed, arrowhead=crow]
|
||||||
key:i2:e -> key2:j2:w []
|
key:i2:e -> key2:j2:w []
|
||||||
}
|
}
|
||||||
""", file=out)
|
"""
|
||||||
|
|
||||||
print("""
|
out+="""
|
||||||
label = "\\n\\nAsterisk extensions\\nLes Nounous\\n%s";
|
label = "\\n\\nAsterisk extensions\\nLes Nounous\\n%s";
|
||||||
}""" % str(date())[0:-1], file=out)
|
}""" % time.strftime('%A %d %B %Y, %H:%M:%S')
|
||||||
|
|
||||||
out.close()
|
|
||||||
|
|
||||||
dot("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/asterisk/extensions.svg")
|
p = Popen(['dot', '-Tsvg', '-o', svg_file], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
|
||||||
#neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/asterisk/extensions.svg")
|
p.communicate(input=out)
|
||||||
|
|
||||||
|
if __name__ == '__main__' :
|
||||||
|
import sys
|
||||||
|
if len(sys.argv)>1:
|
||||||
|
import locale
|
||||||
|
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
|
||||||
|
gen_extentions_graph('/etc/asterisk/extensions.conf', ["crans-sip", "crans-from-external", "ovh-sip", "crans-sms"], sys.argv[1])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue