]> git.proxmox.com Git - mirror_ovs.git/blame - ovsdb/dot2pic
raft: Send all missing logs in one single append_request.
[mirror_ovs.git] / ovsdb / dot2pic
CommitLineData
ddd7d381 1#! /usr/bin/env python
fca64c12 2
ddd7d381 3# Copyright (c) 2009, 2010, 2011, 2013, 2017 Nicira, Inc.
fca64c12
BP
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at:
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
ddd7d381
BP
17import getopt
18import sys
fca64c12 19
ddd7d381
BP
20def dot2pic(src, dst):
21 scale = 1.0
22 while True:
23 line = src.readline()
24 if not line:
25 break
86c65682 26
ddd7d381
BP
27 words = line.split()
28 command = words[0]
29 if command == 'graph':
30 scale = float(words[1])
31 elif command == 'node':
32 name = words[1]
33 x = float(words[2])
34 y = float(words[3])
35 width = float(words[4])
36 height = float(words[5])
37 label, style, shape, color, fillcolor = words[6:11]
38 x *= scale
39 y *= scale
40 width *= scale
41 height *= scale
42 dst.write("linethick = %f;\n" % (0.5 if style == 'bold' else 1.0))
43 dst.write('box at %f,%f wid %f height %f "%s"\n'
44 % (x, y, width, height, name))
45 if style == 'bold':
46 inset = 2.0 / 72.0
47 width -= inset * 2
48 height -= inset * 2
49 dst.write("box at %f,%f wid %f height %f\n"
50 % (x, y, width, height))
51 elif command == 'edge':
52 tail = words[1]
53 head = words[2]
54 n = int(words[3])
86c65682 55
ddd7d381
BP
56 # Extract x,y coordinates.
57 words = words[4:]
58 xy = []
59 for i in range(n):
60 x = float(words[0]) * scale
61 y = float(words[1]) * scale
62 words = words[2:]
63 xy.append((x, y))
fca64c12 64
ddd7d381
BP
65 # Extract style and color from end of words.
66 style, color = words[-2:]
67 words = words[:-2]
c5f341ab 68
ddd7d381
BP
69 # If there's anything left, that's the label.
70 if words:
71 xl = float(words[-2]) * scale
72 yl = float(words[-1]) * scale
73 label = ' '.join(words[:-2])
74 if label.startswith('"') and label.endswith('"'):
75 label = label[1:-1]
76 else:
77 label = None
fca64c12 78
ddd7d381
BP
79 dst.write("linethick = %f;\n"
80 % (0.5 if style == 'dotted' else 1.0))
81 dst.write("spline -> from %f,%f" % xy[0])
82 for x, y in xy:
83 dst.write(" to %f,%f" % (x, y))
84 dst.write('\n')
85
86 if label:
87 dst.write('"%s" at %f,%f\n' % (label, xl, yl))
88 elif command == 'stop':
89 break
90 else:
91 sys.stderr.write("%s\n" % command)
92 assert False
93
94
95options, args = getopt.gnu_getopt(sys.argv[1:], 'f:', [])
96
97font_scale = 0
98for key, value in options:
99 if key == '-f':
100 font_scale = int(value)
101 else:
102 raise False
103
104if font_scale:
105 print(".ps %+d" % -font_scale)
106
107print(".PS")
108print("linethick = 1;")
109if args:
110 for arg in args:
111 dot2pic(open(arg), sys.stdout)
112else:
113 dot2pic(sys.stdin, sys.stdout)
114if font_scale:
115 print(".ps %+d" % font_scale)
116print(".PE")
fca64c12 117