2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 23:05:29 +00:00

ovs-tcpundump: Fix incompatibilities with python3

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@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Timothy Redaelli
2018-07-24 18:35:22 +02:00
committed by Ben Pfaff
parent 7a2ce387d8
commit 227abb77d3

View File

@@ -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