-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopo_show.py
More file actions
executable file
·35 lines (29 loc) · 915 Bytes
/
Copy pathtopo_show.py
File metadata and controls
executable file
·35 lines (29 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import sys
import tempfile
import subprocess
import logging
logging.basicConfig(
# level=logging.INFO,
format='%(asctime)-15s %(name)-8s %(levelname)-8s %(message)s')
# logger = logging.getLogger(__name__)
log_file = os.path.join(sys.argv[1], 'log')
with open(log_file) as fd:
data = [i.strip().split() for i in fd if i.startswith('born')]
logging.info('Data loaded.')
iset = set(i[3] for i in data)
logging.info('Writing to dot.')
fd = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
fd.close()
p = subprocess.Popen(['dot', '-Tpng', '-o', fd.name],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
txt = "DiGraph {\n"
for i in data:
if i[5] in iset:
txt = txt + "{} -> {};\n".format(i[3], i[5])
txt = txt + "}\n"
p.communicate(txt.encode('utf-8'))
logging.info('Show.')
os.system('eog {}'.format(fd.name))
os.unlink(fd.name)