Commit e9902c4a authored by Kirill Smelkov's avatar Kirill Smelkov

X improve `xbtree topoview`

good viewer is spawned; the picture is not changed when another topoview
is run in parallel.
parent 8fc2a3ab
...@@ -980,7 +980,7 @@ def zcheck(ztree): ...@@ -980,7 +980,7 @@ def zcheck(ztree):
# ---------------------------------------- # ----------------------------------------
import sys import sys, tempfile, shutil, subprocess
# graphviz returns tree graph representation in dot language. # graphviz returns tree graph representation in dot language.
@func(Tree) @func(Tree)
...@@ -1072,6 +1072,7 @@ def graphviz(t, clustername=''): ...@@ -1072,6 +1072,7 @@ def graphviz(t, clustername=''):
# topoview display topologies provided in argv. # topoview display topologies provided in argv.
@func
def topoview(argv): def topoview(argv):
if len(argv) == 0: if len(argv) == 0:
raise RuntimeError('E: empty argument') raise RuntimeError('E: empty argument')
...@@ -1095,8 +1096,17 @@ def topoview(argv): ...@@ -1095,8 +1096,17 @@ def topoview(argv):
import graphviz as gv import graphviz as gv
g = gv.Source('\n'.join(outv)) g = gv.Source('\n'.join(outv))
g.view() tmpd = tempfile.mkdtemp('', 'xbtree')
#g.render('x', format='svg') def _():
shutil.rmtree(tmpd)
defer(_)
# set filename so that it shows in window title.
filename = ' '.join([_.replace('/', '\\') for _ in argv]) # no / in filename
g.render(filename, tmpd, format='svg')
# XXX g.view spawns viewer, but does not wait for it to stop
subprocess.check_call(["inkview", "%s/%s.svg" % (tmpd, filename)])
if __name__ == '__main__': if __name__ == '__main__':
......
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