[ovs-dev] [PATCH] ovs-tcpundump: Fix incompatibilities with python3

Timothy Redaelli tredaelli at redhat.com
Tue Jul 24 16:35:22 UTC 2018


Added parenthesis after print and use "as" instead of "," in except.

This commit fixes also a couple of flake8 warnings:

    utilities/ovs-tcpundump:23:1: E302 expected 2 blank lines, found 1
    utilities/ovs-tcpundump:35:1: E305 expected 2 blank lines after class or
    function definition, found 1

Tested on Python 2.7.15 and Python 3.6.5

Signed-off-by: Timothy Redaelli <tredaelli at redhat.com>
---
 utilities/ovs-tcpundump.in | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/utilities/ovs-tcpundump.in b/utilities/ovs-tcpundump.in
index c99015b5b..c29870062 100755
--- a/utilities/ovs-tcpundump.in
+++ b/utilities/ovs-tcpundump.in
@@ -20,8 +20,9 @@ import sys
 
 argv0 = sys.argv[0]
 
+
 def usage():
-    print """\
+    print("""\
 %(argv0)s: print "tcpdump -xx" output as hex
 usage: %(argv0)s < FILE
 where FILE is output from "tcpdump -xx".
@@ -29,14 +30,15 @@ where FILE is output from "tcpdump -xx".
 The following options are also available:
   -h, --help                  display this help message
   -V, --version               display version information\
-""" % {'argv0': argv0}
+""" % {'argv0': argv0})
     sys.exit(0)
 
+
 if __name__ == "__main__":
     try:
         options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
                                           ['help', 'version'])
-    except getopt.GetoptError, geo:
+    except getopt.GetoptError as geo:
         sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
         sys.exit(1)
 
@@ -44,7 +46,7 @@ if __name__ == "__main__":
         if key in ['-h', '--help']:
             usage()
         elif key in ['-V', '--version']:
-            print "ovs-tcpundump (Open vSwitch) @VERSION@"
+            print("ovs-tcpundump (Open vSwitch) @VERSION@")
         else:
             sys.exit(0)
 
@@ -63,12 +65,12 @@ if __name__ == "__main__":
         m = regex.match(line)
         if m is None or int(m.group(1), 16) == 0:
             if packet != '':
-                print packet
+                print(packet)
             packet = ''
         if m:
             packet += re.sub(r'\s', '', m.group(2), 0)
     if packet != '':
-        print packet
+        print(packet)
 
 # Local variables:
 # mode: python
-- 
2.17.1



More information about the dev mailing list