3 from datetime import date
9 sys.path.insert(0, "@abs_top_srcdir@/ovsdb")
10 import simplejson as json
16 def printEdge(tableName, baseType, label):
19 options['label'] = '"%s"' % label
20 if baseType.refType == 'weak':
21 options['constraint'] = 'false'
22 print "\t%s -> %s [%s];" % (
25 ', '.join(['%s=%s' % (k,v) for k,v in options.items()]))
27 def schemaToDot(schemaFile):
28 schema = DbSchema.fromJson(json.load(open(schemaFile, "r")))
30 print "digraph %s {" % schema.name
31 for tableName, table in schema.tables.iteritems():
32 print '\tsize="6.5,4";'
34 print "\tnode [shape=box];"
35 print "\t%s;" % tableName
36 for columnName, column in table.columns.iteritems():
38 printEdge(tableName, column.type.key, "%s key" % columnName)
39 printEdge(tableName, column.type.value, "%s value" % columnName)
41 printEdge(tableName, column.type.key, columnName)
46 %(argv0)s: compiles ovsdb schemas to graphviz format
47 Prints a .dot file that "dot" can render to an entity-relationship diagram
48 usage: %(argv0)s [OPTIONS] SCHEMA
49 where SCHEMA is an OVSDB schema in JSON format
51 The following options are also available:
52 -h, --help display this help message
53 -V, --version display version information\
54 """ % {'argv0': argv0}
57 if __name__ == "__main__":
60 options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
62 except getopt.GetoptError, geo:
63 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
66 for key, value in options:
67 if key in ['-h', '--help']:
69 elif key in ['-V', '--version']:
70 print "ovsdb-dot (Open vSwitch) @VERSION@"
75 sys.stderr.write("%s: exactly 1 non-option argument required "
76 "(use --help for help)\n" % argv0)
82 sys.stderr.write("%s: %s\n" % (argv0, e.msg))