extract-ofp-errors doesn't work with python 3 for the
following reasons:
- several "SyntaxError: invalid syntax":
print not a keyword anymore. As a function it requires '()'
- AttributeError: 'dict' object has no attribute 'itervalues'
Use values() instead.
Test done:
Generate using ofp-errors.inc as a reference
Patch for python 3, then regenerate ofp-errors.inc
Diff between the two outputs.
Signed-off-by: Damien Millescamps <damien.millescamps@6wind.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Casey Barker crbarker@google.com
Chris Wright chrisw@sous-sol.org
Chuck Short zulcss@ubuntu.com
Casey Barker crbarker@google.com
Chris Wright chrisw@sous-sol.org
Chuck Short zulcss@ubuntu.com
+Damien Millescamps damien.millescamps@6wind.com
Dan Carpenter dan.carpenter@oracle.com
Dan Wendlandt dan@nicira.com
Daniel Roman droman@nicira.com
Dan Carpenter dan.carpenter@oracle.com
Dan Wendlandt dan@nicira.com
Daniel Roman droman@nicira.com
return name
def print_enum(tag, constants, storage_class):
return name
def print_enum(tag, constants, storage_class):
%(storage_class)sconst char *
%(tag)s_to_string(uint16_t value)
{
switch (value) {\
""" % {"tag": tag,
"bufferlen": len(tag) + 32,
%(storage_class)sconst char *
%(tag)s_to_string(uint16_t value)
{
switch (value) {\
""" % {"tag": tag,
"bufferlen": len(tag) + 32,
- "storage_class": storage_class}
+ "storage_class": storage_class})
for constant in constants:
for constant in constants:
- print " case %s: return \"%s\";" % (constant, constant)
- print """\
+ print (" case %s: return \"%s\";" % (constant, constant))
+ print ("""\
def usage():
argv0 = os.path.basename(sys.argv[0])
def usage():
argv0 = os.path.basename(sys.argv[0])
%(argv0)s, for extracting OpenFlow error codes from header files
usage: %(argv0)s FILE [FILE...]
%(argv0)s, for extracting OpenFlow error codes from header files
usage: %(argv0)s FILE [FILE...]
This program is specialized for reading lib/ofp-errors.h. It will not
work on arbitrary header files without extensions.\
This program is specialized for reading lib/ofp-errors.h. It will not
work on arbitrary header files without extensions.\
sys.exit(0)
def extract_ofp_errors(filenames):
sys.exit(0)
def extract_ofp_errors(filenames):
- for fn, ln in expected_errors.itervalues():
+ for fn, ln in expected_errors.values():
sys.stderr.write("%s:%d: expected duplicate not used.\n" % (fn, ln))
n_errors += 1
if n_errors:
sys.exit(1)
sys.stderr.write("%s:%d: expected duplicate not used.\n" % (fn, ln))
n_errors += 1
if n_errors:
sys.exit(1)
/* Generated automatically; do not modify! -*- buffer-read-only: t -*- */
#define OFPERR_N_ERRORS %d
/* Generated automatically; do not modify! -*- buffer-read-only: t -*- */
#define OFPERR_N_ERRORS %d
""" % (len(names),
'\n'.join(' "%s",' % name for name in names),
'\n'.join(' "%s",' % re.sub(r'(["\\])', r'\\\1', comment)
""" % (len(names),
'\n'.join(' "%s",' % name for name in names),
'\n'.join(' "%s",' % re.sub(r'(["\\])', r'\\\1', comment)
- for comment in comments))
+ for comment in comments)))
def output_domain(map, name, description, version):
def output_domain(map, name, description, version):
static enum ofperr
%s_decode(uint16_t type, uint16_t code)
{
static enum ofperr
%s_decode(uint16_t type, uint16_t code)
{
- switch ((type << 16) | code) {""" % name
+ switch ((type << 16) | code) {""" % name)
found = set()
for enum in names:
if enum not in map:
found = set()
for enum in names:
if enum not in map:
if value in found:
continue
found.add(value)
if value in found:
continue
found.add(value)
- print " case (%d << 16) | %d:" % (type_, code)
- print " return OFPERR_%s;" % enum
- print """\
+ print (" case (%d << 16) | %d:" % (type_, code))
+ print (" return OFPERR_%s;" % enum)
+ print ("""\
static const struct ofperr_domain %s = {
"%s",
%d,
%s_decode,
static const struct ofperr_domain %s = {
"%s",
%d,
%s_decode,
- {""" % (name, description, version, name)
+ {""" % (name, description, version, name))
for enum in names:
if enum in map:
type_, code = map[enum]
for enum in names:
if enum in map:
type_, code = map[enum]
code = -1
else:
type_ = code = -1
code = -1
else:
type_ = code = -1
- print " { %2d, %3d }, /* %s */" % (type_, code, enum)
- print """\
+ print (" { %2d, %3d }, /* %s */" % (type_, code, enum))
+ print ("""\
output_domain(reverse["OF1.0"], "ofperr_of10", "OpenFlow 1.0", 0x01)
output_domain(reverse["OF1.1"], "ofperr_of11", "OpenFlow 1.1", 0x02)
output_domain(reverse["OF1.0"], "ofperr_of10", "OpenFlow 1.0", 0x01)
output_domain(reverse["OF1.1"], "ofperr_of11", "OpenFlow 1.1", 0x02)