[ovs-dev] [manager-options 2/5] docs: Implement our own dot->pic translator.

Ben Pfaff blp at nicira.com
Wed Nov 3 17:39:53 UTC 2010


Recent versions of Graphviz no longer support output to PIC format, so this
commit adds our own internal translator from dot's "plain" output format
to PIC format.  The "plain" format works best with slightly different
"dot" input (advised by the Graphviz manual description of the "plain"
format) so this commit also adjusts ovsdb-dot's output.
---
 ovsdb/dot2pic        |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 ovsdb/ovsdb-dot.in   |    1 +
 vswitchd/automake.mk |    9 +++----
 3 files changed, 68 insertions(+), 5 deletions(-)
 create mode 100755 ovsdb/dot2pic

diff --git a/ovsdb/dot2pic b/ovsdb/dot2pic
new file mode 100755
index 0000000..3e2f308
--- /dev/null
+++ b/ovsdb/dot2pic
@@ -0,0 +1,63 @@
+#! /usr/bin/perl
+
+# Copyright (c) 2009, 2010 Nicira Networks
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+
+my ($scale) = 1;
+print ".PS\n";
+print "linethick = 1;\n";
+while (<>) {
+    if (/graph (\S+) (\S+) (\S+)/) {
+        $scale = $1;
+    } elsif (my ($name, $x, $y, $width, $height, $label, $style, $shape, $color, $fillcolor) = /node (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/) {
+        $x *= $scale;
+        $y *= $scale;
+        $width *= $scale;
+        $height *= $scale;
+        print "box at $x,$y wid $width height $height \"$name\"\n";
+    } elsif (/edge/) {
+        my (undef, $tail, $head, $n, $rest) = split(' ', $_, 5);
+        my @xy;
+        for (1...$n) {
+            my ($x, $y);
+            ($x, $y, $rest) = split(' ', $rest, 3);
+            push(@xy, [$x * $scale, $y * $scale]);
+        }
+        my ($label, $xl, $yl);
+        if (scalar(my @junk = split(' ', $rest)) > 2) {
+            if ($rest =~ s/^"([^"]*)"\s+//) {
+                $label = $1;
+            } else {
+                ($label, $rest) = split(' ', $rest, 2);
+            }
+            ($xl, $yl, $rest) = split(' ', $rest, 3);
+            $xl *= $scale;
+            $yl *= $scale;
+        }
+        my ($style, $color) = split(' ', $rest);
+
+        print "spline -> from $xy[0][0],$xy[0][1]";
+        for (my ($i) = 0; $i <= $#xy; $i++) {
+            print " to $xy[$i][0],$xy[$i][1]";
+        }
+        print "\n";
+
+        print "\"$label\" at $xl,$yl\n" if defined($label);
+    }
+
+}
+print ".PE\n";
diff --git a/ovsdb/ovsdb-dot.in b/ovsdb/ovsdb-dot.in
index 4569f2e..cea8987 100755
--- a/ovsdb/ovsdb-dot.in
+++ b/ovsdb/ovsdb-dot.in
@@ -29,6 +29,7 @@ def schemaToDot(schemaFile):
         print '\tsize="6.5,4";'
         print '\tmargin="0";'
         print "\tnode [shape=box];"
+        print "\tedge [dir=none, arrowhead=none, arrowtail=none];"
         print "\t%s;" % tableName
         for columnName, column in table.columns.iteritems():
             if column.type.value:
diff --git a/vswitchd/automake.mk b/vswitchd/automake.mk
index 93c6f92..6ef7763 100644
--- a/vswitchd/automake.mk
+++ b/vswitchd/automake.mk
@@ -50,12 +50,11 @@ vswitchd/vswitch-idl.ovsidl: $(VSWITCH_IDL_FILES)
 
 # vswitch E-R diagram
 if BUILD_ER_DIAGRAMS
-$(srcdir)/vswitchd/vswitch.pic: ovsdb/ovsdb-dot.in vswitchd/vswitch.ovsschema
+$(srcdir)/vswitchd/vswitch.pic: ovsdb/ovsdb-dot.in ovsdb/dot2pic \
+                                vswitchd/vswitch.ovsschema
 	$(OVSDB_DOT) $(srcdir)/vswitchd/vswitch.ovsschema \
-		| dot -T pic \
-		| sed -e "/^'/d" \
-		      -e '/^box attrs0/d' \
-		      -e 's/linethick = 0;/linethick = 1;/' \
+		| dot -T plain \
+		| $(srcdir)/ovsdb/dot2pic \
 		> $@.tmp
 	mv $@.tmp $@
 else
-- 
1.7.1





More information about the dev mailing list