debian: Update changelog to reflect current OVS version.
[openvswitch] / ovsdb / OVSDB.py
index f40af1e9deca923a436ab7af2e20a433adb904d1..6e426e57183484625933a3204409a1d1944ae8d9 100644 (file)
@@ -21,25 +21,23 @@ def mustGetMember(json, name, expectedType, description):
     return member
 
 class DbSchema:
-    def __init__(self, name, comment, tables):
+    def __init__(self, name, tables):
         self.name = name
-        self.comment = comment
         self.tables = tables
 
     @staticmethod
     def fromJson(json):
         name = mustGetMember(json, 'name', [unicode], 'database')
-        comment = getMember(json, 'comment', [unicode], 'database')
         tablesJson = mustGetMember(json, 'tables', [dict], 'database')
         tables = {}
         for tableName, tableJson in tablesJson.iteritems():
             tables[tableName] = TableSchema.fromJson(tableJson,
                                                      "%s table" % tableName)
-        return DbSchema(name, comment, tables)
+        return DbSchema(name, tables)
 
 class IdlSchema(DbSchema):
-    def __init__(self, name, comment, tables, idlPrefix, idlHeader):
-        DbSchema.__init__(self, name, comment, tables)
+    def __init__(self, name, tables, idlPrefix, idlHeader):
+        DbSchema.__init__(self, name, tables)
         self.idlPrefix = idlPrefix
         self.idlHeader = idlHeader
 
@@ -48,39 +46,34 @@ class IdlSchema(DbSchema):
         schema = DbSchema.fromJson(json)
         idlPrefix = mustGetMember(json, 'idlPrefix', [unicode], 'database')
         idlHeader = mustGetMember(json, 'idlHeader', [unicode], 'database')
-        return IdlSchema(schema.name, schema.comment, schema.tables,
-                         idlPrefix, idlHeader)
+        return IdlSchema(schema.name, schema.tables, idlPrefix, idlHeader)
 
 class TableSchema:
-    def __init__(self, comment, columns):
-        self.comment = comment
+    def __init__(self, columns):
         self.columns = columns
 
     @staticmethod
     def fromJson(json, description):
-        comment = getMember(json, 'comment', [unicode], description)
         columnsJson = mustGetMember(json, 'columns', [dict], description)
         columns = {}
         for name, json in columnsJson.iteritems():
             columns[name] = ColumnSchema.fromJson(
                 json, "column %s in %s" % (name, description))
-        return TableSchema(comment, columns)
+        return TableSchema(columns)
 
 class ColumnSchema:
-    def __init__(self, comment, type, persistent):
-        self.comment = comment
+    def __init__(self, type, persistent):
         self.type = type
         self.persistent = persistent
 
     @staticmethod
     def fromJson(json, description):
-        comment = getMember(json, 'comment', [unicode], description)
         type = Type.fromJson(mustGetMember(json, 'type', [dict, unicode],
                                            description),
                              'type of %s' % description)
         ephemeral = getMember(json, 'ephemeral', [bool], description)
         persistent = ephemeral != True
-        return ColumnSchema(comment, type, persistent)
+        return ColumnSchema(type, persistent)
 
 def escapeCString(src):
     dst = ""
@@ -200,16 +193,28 @@ class Atom:
         elif self.type == 'uuid':
             return self.value.value
 
+# Returns integer x formatted in decimal with thousands set off by commas.
+def commafy(x):
+    return _commafy("%d" % x)
+def _commafy(s):
+    if s.startswith('-'):
+        return '-' + _commafy(s[1:])
+    elif len(s) <= 3:
+        return s
+    else:
+        return _commafy(s[:-3]) + ',' + _commafy(s[-3:])
+
 class BaseType:
     def __init__(self, type,
                  enum=None,
-                 refTable=None,
+                 refTable=None, refType="strong",
                  minInteger=None, maxInteger=None,
                  minReal=None, maxReal=None,
                  minLength=None, maxLength=None):
         self.type = type
         self.enum = enum
         self.refTable = refTable
+        self.refType = refType
         self.minInteger = minInteger
         self.maxInteger = maxInteger
         self.minReal = minReal
@@ -228,17 +233,23 @@ class BaseType:
                 enumType = Type(atomicType, None, 0, 'unlimited')
                 enum = Datum.fromJson(enumType, enum)
             refTable = getMember(json, 'refTable', [unicode], description)
+            refType = getMember(json, 'refType', [unicode], description)
+            if refType == None:
+                refType = "strong"
             minInteger = getMember(json, 'minInteger', [int, long], description)
             maxInteger = getMember(json, 'maxInteger', [int, long], description)
             minReal = getMember(json, 'minReal', [int, long, float], description)
             maxReal = getMember(json, 'maxReal', [int, long, float], description)
             minLength = getMember(json, 'minLength', [int], description)
             maxLength = getMember(json, 'minLength', [int], description)
-            return BaseType(atomicType, enum, refTable, minInteger, maxInteger, minReal, maxReal, minLength, maxLength)
+            return BaseType(atomicType, enum, refTable, refType, minInteger, maxInteger, minReal, maxReal, minLength, maxLength)
 
     def toEnglish(self, escapeLiteral=returnUnchanged):
         if self.type == 'uuid' and self.refTable:
-            return escapeLiteral(self.refTable)
+            s = escapeLiteral(self.refTable)
+            if self.refType == 'weak':
+                s = "weak reference to " + s
+            return s
         else:
             return self.type
 
@@ -253,13 +264,14 @@ class BaseType:
                                                  ', '.join(literals[1:-1]),
                                                  literals[-1])
         elif self.minInteger != None and self.maxInteger != None:
-            return 'in range [%d,%d]' % (self.minInteger, self.maxInteger)
+            return 'in range %s to %s' % (commafy(self.minInteger),
+                                         commafy(self.maxInteger))
         elif self.minInteger != None:
-            return 'at least %d' % self.minInteger
+            return 'at least %s' % commafy(self.minInteger)
         elif self.maxInteger != None:
-            return 'at most %d' % self.maxInteger
+            return 'at most %s' % commafy(self.maxInteger)
         elif self.minReal != None and self.maxReal != None:
-            return 'in range [%g, %g]' % (self.minReal, self.maxReal)
+            return 'in range %g to %g' % (self.minReal, self.maxReal)
         elif self.minReal != None:
             return 'at least %g' % self.minReal
         elif self.maxReal != None: