Skip to content

Commit

Permalink
Python3 compatibility: Convert print statements
Browse files Browse the repository at this point in the history
This patch fixes up all the print statements to work with python3 or
python2.

Signed-off-by: Jason Wessel <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
jwessel authored and blp committed Jul 6, 2017
1 parent fb16fec commit d34a1cc
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 305 deletions.
4 changes: 2 additions & 2 deletions build-aux/check-structs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def checkStructs():

if '--help' in sys.argv:
argv0 = os.path.basename(sys.argv[0])
print '''\
print('''\
%(argv0)s, for checking struct and struct member alignment
usage: %(argv0)s -Ipath HEADER [HEADER]...
Expand All @@ -227,7 +227,7 @@ assertions using OFP_ASSERT.
This program is specialized for reading Open vSwitch's OpenFlow header
files. It will not work on arbitrary header files without extensions.\
''' % {"argv0": argv0}
''' % {"argv0": argv0})
sys.exit(0)

global fileName
Expand Down
68 changes: 34 additions & 34 deletions build-aux/extract-ofp-actions
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def fatal(msg):

def usage():
argv0 = os.path.basename(sys.argv[0])
print ('''\
print('''\
%(argv0)s, for extracting OpenFlow action data
usage: %(argv0)s OFP_ACTIONS.C [--prototypes | --definitions]
Expand Down Expand Up @@ -238,36 +238,36 @@ def extract_ofp_actions(fn, definitions):
if n_errors:
sys.exit(1)

print """\
print("""\
/* Generated automatically; do not modify! -*- buffer-read-only: t -*- */
"""
""")

if definitions:
print "/* Verify that structs used as actions are reasonable sizes. */"
print("/* Verify that structs used as actions are reasonable sizes. */")
for s in sorted(arg_structs):
print "BUILD_ASSERT_DECL(sizeof(%s) %% OFP_ACTION_ALIGN == 0);" % s
print("BUILD_ASSERT_DECL(sizeof(%s) %% OFP_ACTION_ALIGN == 0);" % s)

print "\nstatic struct ofpact_raw_instance all_raw_instances[] = {"
print("\nstatic struct ofpact_raw_instance all_raw_instances[] = {")
for vendor in domain:
for type_ in domain[vendor]:
for version in domain[vendor][type_]:
d = domain[vendor][type_][version]
print " { { 0x%08x, %2d, 0x%02x }, " % (
vendor, type_, version)
print " %s," % d["enum"]
print " HMAP_NODE_NULL_INITIALIZER,"
print " HMAP_NODE_NULL_INITIALIZER,"
print " %s," % d["min_length"]
print " %s," % d["max_length"]
print " %s," % d["arg_ofs"]
print " %s," % d["arg_len"]
print " \"%s\"," % re.sub('_RAW[0-9]*', '', d["enum"], 1)
print(" { { 0x%08x, %2d, 0x%02x }, " % (
vendor, type_, version))
print(" %s," % d["enum"])
print(" HMAP_NODE_NULL_INITIALIZER,")
print(" HMAP_NODE_NULL_INITIALIZER,")
print(" %s," % d["min_length"])
print(" %s," % d["max_length"])
print(" %s," % d["arg_ofs"])
print(" %s," % d["arg_len"])
print(" \"%s\"," % re.sub('_RAW[0-9]*', '', d["enum"], 1))
if d["deprecation"]:
print " \"%s\"," % re.sub(r'(["\\])', r'\\\1', d["deprecation"])
print(" \"%s\"," % re.sub(r'(["\\])', r'\\\1', d["deprecation"]))
else:
print " NULL,"
print " },"
print "};";
print(" NULL,")
print(" },")
print("};")

for versions in enums.values():
need_ofp_version = False
Expand Down Expand Up @@ -314,26 +314,26 @@ def extract_ofp_actions(fn, definitions):
decl += "}"
else:
decl += ";"
print decl
print
print(decl)
print("")

if definitions:
print """\
print("""\
static enum ofperr
ofpact_decode(const struct ofp_action_header *a, enum ofp_raw_action_type raw,
enum ofp_version version, uint64_t arg,
const struct vl_mff_map *vl_mff_map,
uint64_t *tlv_bitmap, struct ofpbuf *out)
{
switch (raw) {\
"""
""")
for versions in enums.values():
enum = versions[0]["enum"]
print " case %s:" % enum
print(" case %s:" % enum)
base_argtype = versions[0]["base_argtype"]
arg_vl_mff_map = versions[0]["arg_vl_mff_map"]
if base_argtype == 'void':
print " return decode_%s(out);" % enum
print(" return decode_%s(out);" % enum)
else:
if base_argtype.startswith('struct'):
arg = "ALIGNED_CAST(const %s *, a)" % base_argtype
Expand All @@ -344,16 +344,16 @@ ofpact_decode(const struct ofp_action_header *a, enum ofp_raw_action_type raw,
else:
arg = "arg"
if arg_vl_mff_map:
print " return decode_%s(%s, version, vl_mff_map, tlv_bitmap, out);" % (enum, arg)
print(" return decode_%s(%s, version, vl_mff_map, tlv_bitmap, out);" % (enum, arg))
else:
print " return decode_%s(%s, version, out);" % (enum, arg)
print
print """\
print(" return decode_%s(%s, version, out);" % (enum, arg))
print("")
print("""\
default:
OVS_NOT_REACHED();
}
}\
"""
""")
else:
for versions in enums.values():
enum = versions[0]["enum"]
Expand All @@ -368,15 +368,15 @@ ofpact_decode(const struct ofp_action_header *a, enum ofp_raw_action_type raw,
if arg_vl_mff_map:
prototype += 'const struct vl_mff_map *, uint64_t *, '
prototype += "struct ofpbuf *);"
print prototype
print(prototype)

print """
print("""
static enum ofperr ofpact_decode(const struct ofp_action_header *,
enum ofp_raw_action_type raw,
enum ofp_version version,
uint64_t arg, const struct vl_mff_map *vl_mff_map,
uint64_t *tlv_bitmap, struct ofpbuf *out);
"""
""")

if __name__ == '__main__':
if '--help' in sys.argv:
Expand Down
2 changes: 1 addition & 1 deletion build-aux/extract-ofp-errors
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static const struct ofperr_domain %s = {
vendor, type_, code = map[enum]
if code == None:
code = -1
print " { %#8x, %2d, %3d }, /* %s */" % (vendor, type_, code, enum)
print (" { %#8x, %2d, %3d }, /* %s */" % (vendor, type_, code, enum))
else:
print (" { -1, -1, -1 }, /* %s */" % enum)
print ("""\
Expand Down
2 changes: 1 addition & 1 deletion build-aux/extract-ofp-fields
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def make_ovs_fields(meta_flow_h, meta_flow_xml):
ovs\-fields \- protocol header fields in OpenFlow and Open vSwitch
.
.PP
''') % version
''' % version)

recursively_replace(doc, 'oxm_classes', make_oxm_classes_xml(document))

Expand Down
6 changes: 3 additions & 3 deletions build-aux/extract-ofp-msgs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def fatal(msg):

def usage():
argv0 = os.path.basename(sys.argv[0])
print '''\
print('''\
%(argv0)s, for extracting OpenFlow message types from header files
usage: %(argv0)s INPUT OUTPUT
where INPUT is the name of the input header file
and OUTPUT is the output file name.
Despite OUTPUT, the output is written to stdout, and the OUTPUT argument
only controls #line directives in the output.\
''' % {"argv0": argv0}
''' % {"argv0": argv0})
sys.exit(0)

def make_sizeof(s):
Expand Down Expand Up @@ -378,5 +378,5 @@ if __name__ == '__main__':
line_number = 0

for line in extract_ofp_msgs(sys.argv[2]):
print line
print(line)

6 changes: 3 additions & 3 deletions ovsdb/ovsdb-doc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,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
Expand All @@ -269,7 +269,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__":
Expand Down Expand Up @@ -304,7 +304,7 @@ if __name__ == "__main__":
for line in s.split("\n"):
line = line.strip()
if len(line):
print line
print(line)

except error.Error, e:
sys.stderr.write("%s: %s\n" % (argv0, e.msg))
Expand Down
Loading

0 comments on commit d34a1cc

Please sign in to comment.