Fix minor Python 3 compatibility issues.  There was only one place where
we needed to adapt based on Python version.  The inline implementation
of the set of valid string types seemed better than taking on the 'six'
dependency in this script since it's executed at ovs build time.

Signed-off-by: Russell Bryant <russ...@ovn.org>
---
 ovsdb/ovsdb-doc | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/ovsdb/ovsdb-doc b/ovsdb/ovsdb-doc
index 5cf26ee..ee5fcb3 100755
--- a/ovsdb/ovsdb-doc
+++ b/ovsdb/ovsdb-doc
@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from __future__ import print_function
+
 from datetime import date
 import getopt
 import os
@@ -26,6 +28,11 @@ import ovs.db.schema
 
 from build.nroff import *
 
+if sys.version_info[0] >= 3:
+    STRING_TYPES = (str)
+else:
+    STRING_TYPES = (str, unicode)
+
 argv0 = sys.argv[0]
 
 def typeAndConstraintsToNroff(column):
@@ -65,8 +72,8 @@ def columnGroupToNroff(table, groupXml, documented_columns):
                 if node.hasAttribute('type'):
                     type_string = node.attributes['type'].nodeValue
                     type_json = ovs.json.from_string(str(type_string))
-                    if type(type_json) in (str, unicode):
-                        raise error.Error("%s %s:%s has invalid 'type': %s" 
+                    if isinstance(type_json, STRING_TYPES):
+                        raise error.Error("%s %s:%s has invalid 'type': %s"
                                           % (table.name, name, key, type_json))
                     type_ = ovs.db.types.BaseType.from_json(type_json)
                 else:
@@ -258,7 +265,7 @@ represent strong references; thin lines represent weak 
references.
     return s
 
 def usage():
-    print """\
+    print("""\
 %(argv0)s: ovsdb schema documentation generator
 Prints documentation for an OVSDB schema as an nroff-formatted manpage.
 usage: %(argv0)s [OPTIONS] SCHEMA XML
@@ -269,7 +276,7 @@ The following options are also available:
   --er-diagram=DIAGRAM.PIC    include E-R diagram from DIAGRAM.PIC
   --version=VERSION           use VERSION to display on document footer
   -h, --help                  display this help message\
-""" % {'argv0': argv0}
+""" % {'argv0': argv0})
     sys.exit(0)
 
 if __name__ == "__main__":
@@ -278,7 +285,7 @@ if __name__ == "__main__":
             options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
                                               ['er-diagram=',
                                                'version=', 'help'])
-        except getopt.GetoptError, geo:
+        except getopt.GetoptError as geo:
             sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
             sys.exit(1)
 
@@ -304,9 +311,9 @@ if __name__ == "__main__":
         for line in s.split("\n"):
             line = line.strip()
             if len(line):
-                print line
+                print(line)
 
-    except error.Error, e:
+    except error.Error as e:
         sys.stderr.write("%s: %s\n" % (argv0, e.msg))
         sys.exit(1)
 
-- 
2.5.0

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to