Skip to content

Commit

Permalink
ovs-tcpundump: Fix incompatibilities with python3
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
drizzt authored and blp committed Jul 24, 2018
1 parent 7a2ce38 commit 227abb7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions utilities/ovs-tcpundump.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,33 @@ 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".

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)

for key, value in options:
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)

Expand All @@ -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
Expand Down

0 comments on commit 227abb7

Please sign in to comment.