Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
scripts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Benjamin Graillot
scripts
Commits
77fa3f64
Commit
77fa3f64
authored
Jun 21, 2013
by
Valentin Samir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[sip/asterisk-graph] Supression du fichier temporaire
On écrit directement dans PIPE avec subprocess
parent
c8cee16a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
61 deletions
+72
-61
sip/asterisk-graph.py
sip/asterisk-graph.py
+72
-61
No files found.
sip/asterisk-graph.py
View file @
77fa3f64
#!/usr/bin/env python
from
__future__
import
print_function
from
sh
import
neato
from
sh
import
date
from
sh
import
dot
# -*- coding: utf-8 -*-
"""
Génère un graphe de dépendance des extensions
du plan de numérotation d'asterisk
tmp_file
=
'/tmp/graph.gv'
exten_file
=
'/etc/asterisk/extensions.conf'
start_nodes
=
[
"crans-sip"
,
"crans-from-external"
,
"ovh-sip"
,
"crans-sms"
]
Auteur: Valentin Samir
out
=
file
(
tmp_file
,
'w'
)
arrow
=
{}
iarrow
=
{}
"""
print
(
"""digraph G {
rankdir=LR
edge [len=2.50, ratio=fill]
"""
,
file
=
out
)
for
node
in
start_nodes
:
print
(
'"%s" [style=filled];'
%
node
,
file
=
out
)
from
subprocess
import
Popen
,
PIPE
,
STDOUT
import
time
file
=
open
(
exten_file
).
read
()
file
=
file
.
split
(
'
\n
['
)
del
(
file
[
0
])
for
context
in
file
:
def
gen_extentions_graph
(
exten_file
,
start_nodes
,
svg_file
):
out
=
""
arrow
=
{}
iarrow
=
{}
out
+=
"""digraph G {
rankdir=LR
edge [len=2.50, ratio=fill]
"""
for
node
in
start_nodes
:
out
+=
'"%s" [style=filled];'
%
node
file
=
open
(
exten_file
).
read
()
file
=
file
.
split
(
'
\n
['
)
del
(
file
[
0
])
for
context
in
file
:
context
=
context
.
split
(
'
\n
'
)
context_name
=
context
[
0
].
strip
()[:
-
1
]
arrow
[
context_name
]
=
arrow
.
get
(
context_name
,
set
())
iarrow
[
context_name
]
=
iarrow
.
get
(
context_name
,
set
())
del
(
context
[
0
])
print
(
'"%s";'
%
context_name
,
file
=
out
)
out
+=
'"%s";'
%
context_name
for
line
in
context
:
if
line
.
startswith
(
'include'
):
dest
=
line
.
split
(
'=>'
,
1
)[
1
].
strip
()
...
...
@@ -39,14 +44,14 @@ for context in file:
arrow
[
context_name
].
add
(
dest
)
for
(
context_name
,
dests
)
in
arrow
.
items
():
for
(
context_name
,
dests
)
in
arrow
.
items
():
for
dest
in
dests
:
print
(
'"%s" -> "%s" [arrowhead=normal];'
%
(
context_name
,
dest
),
file
=
ou
t
)
for
(
context_name
,
dests
)
in
iarrow
.
items
():
out
+=
'"%s" -> "%s" [arrowhead=normal];'
%
(
context_name
,
des
t
)
for
(
context_name
,
dests
)
in
iarrow
.
items
():
for
dest
in
dests
:
print
(
'"%s" -> "%s" [arrowhead=crow, style=dashed];'
%
(
context_name
,
dest
),
file
=
ou
t
)
out
+=
'"%s" -> "%s" [arrowhead=crow, style=dashed];'
%
(
context_name
,
des
t
)
print
(
"""
out
+=
"""
node [shape=plaintext]
subgraph cluster_01 {
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:i2:e -> key2:j2:w []
}
"""
,
file
=
out
)
"""
out
+=
"""
label = "
\\
n
\\
nAsterisk extensions
\\
nLes Nounous
\\
n%s";
}"""
%
time
.
strftime
(
'%A %d %B %Y, %H:%M:%S'
)
print
(
"""
label = "
\\
n
\\
nAsterisk extensions
\\
nLes Nounous
\\
n%s";
}"""
%
str
(
date
())[
0
:
-
1
],
file
=
out
)
out
.
close
()
p
=
Popen
([
'dot'
,
'-Tsvg'
,
'-o'
,
svg_file
],
stdout
=
PIPE
,
stdin
=
PIPE
,
stderr
=
STDOUT
)
p
.
communicate
(
input
=
out
)
dot
(
"-Tsvg"
,
tmp_file
,
"-o"
,
"/usr/scripts/var/doc/asterisk/extensions.svg"
)
#neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/asterisk/extensions.svg")
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
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment