diff options
author | Daniel Martin <consume.noise@gmail.com> | 2014-01-06 18:38:02 +0100 |
---|---|---|
committer | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2014-01-07 20:38:54 -0500 |
commit | f0e73f0bcb9d3afbbc27c7eaab898f9a6cd572e3 (patch) | |
tree | 6aad779b00b0f3c417342adce6f02a0edcb59009 /src | |
parent | 925b18c38fc8f22d652f1742071b433a50b6293c (diff) |
py: Replace print statement with function call
In Python 3 backward compatibility for the print statement has been
removed. Replace it with the function call.
Additionally, add
from __future__ import print_function
to make sure the statement is disabled and the function is used for
Python versions <3.
Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Diffstat (limited to 'src')
-rwxr-xr-x | src/convert-old-dumps-to-1.1.py | 21 | ||||
-rwxr-xr-x | src/make-event-names.py | 97 |
2 files changed, 62 insertions, 56 deletions
diff --git a/src/convert-old-dumps-to-1.1.py b/src/convert-old-dumps-to-1.1.py index 8eaabfe..a224a97 100755 --- a/src/convert-old-dumps-to-1.1.py +++ b/src/convert-old-dumps-to-1.1.py @@ -6,6 +6,9 @@ # python convert-old-dumps-to-1.1.py myEvent.desc [myEvent.events] # +# Make sure the print statement is disabled and the function is used. +from __future__ import print_function + import re import os import sys @@ -22,20 +25,20 @@ def convert_events(lines): type = int(type, 16) code = int(code, 16) value = int(value, 0) - print "E: %s %04x %04x %04d\t" % (t, type, code, value), + print("E: %s %04x %04x %04d\t" % (t, type, code, value)) desc = "" if type == ev_map["EV_SYN"]: if code == syn_map["SYN_MT_REPORT"]: - print "# ++++++++++++ %s (%d) ++++++++++" % (event_get_code_name(type, code), value) + print("# ++++++++++++ %s (%d) ++++++++++" % (event_get_code_name(type, code), value)) else: - print "# ------------ %s (%d) ----------" % (event_get_code_name(type, code), value) + print("# ------------ %s (%d) ----------" % (event_get_code_name(type, code), value)) else: - print "# %s / %-20s %d" % ( event_get_type_name(type), event_get_code_name(type, code), value) + print("# %s / %-20s %d" % ( event_get_type_name(type), event_get_code_name(type, code), value)) else: - print line, + print(line) def usage(args): - print "%s mydev.desc [mydev.events]" % os.path.basename(args[0]) + print("%s mydev.desc [mydev.events]" % os.path.basename(args[0])) return 1 @@ -47,8 +50,8 @@ if __name__ == "__main__": d.describe(sys.stdout) d = None if len(sys.argv) > 2: - print "################################" - print "# Waiting for events #" - print "################################" + print("################################") + print("# Waiting for events #") + print("################################") with open(sys.argv[2]) as f: convert_events(f.readlines()) diff --git a/src/make-event-names.py b/src/make-event-names.py index 2092cfd..a62c2c3 100755 --- a/src/make-event-names.py +++ b/src/make-event-names.py @@ -4,6 +4,9 @@ # mapping table # +# Make sure the print statement is disabled and the function is used. +from __future__ import print_function + import re import sys import argparse @@ -42,57 +45,57 @@ blacklist = [ def print_bits(bits, prefix): if not hasattr(bits, prefix): return - print "static const char * const %s_map[%s_MAX + 1] = {" % (prefix, prefix.upper()) - print " [0 ... %s_MAX] = NULL," % prefix.upper() + print("static const char * const %s_map[%s_MAX + 1] = {" % (prefix, prefix.upper())) + print(" [0 ... %s_MAX] = NULL," % prefix.upper()) for val, name in getattr(bits, prefix).items(): - print " [%s] = \"%s\"," % (name, name) - print "};" - print "" + print(" [%s] = \"%s\"," % (name, name)) + print("};") + print("") def print_python_bits(bits, prefix): if not hasattr(bits, prefix): return - print "%s_map = {" % (prefix) + print("%s_map = {" % (prefix)) for val, name in getattr(bits, prefix).items(): - print " %d : \"%s\"," % (val, name) - print "}" - print "for k, v in %s_map.items():" % (prefix) - print " %s_map[v] = k" % (prefix) - print "" + print(" %d : \"%s\"," % (val, name)) + print("}") + print("for k, v in %s_map.items():" % (prefix)) + print(" %s_map[v] = k" % (prefix)) + print("") def print_map(bits): - print "static const char * const * const map[EV_MAX + 1] = {" - print " [0 ... EV_MAX] = NULL," + print("static const char * const * const map[EV_MAX + 1] = {") + print(" [0 ... EV_MAX] = NULL,") for prefix in prefixes: if prefix == "BTN_" or prefix == "EV_" or prefix == "INPUT_PROP_": continue - print " [EV_%s] = %s_map," % (prefix[:-1], prefix[:-1].lower()) + print(" [EV_%s] = %s_map," % (prefix[:-1], prefix[:-1].lower())) - print "};" - print "" + print("};") + print("") def print_python_map(bits): - print "map = {" + print("map = {") for val, name in getattr(bits, "ev").items(): name = name[3:] if name == "REP" or name == "PWR" or name == "FF_STATUS" or name == "MAX": continue - print " %d : %s_map," % (val, name.lower()) + print(" %d : %s_map," % (val, name.lower())) - print "}" - print "" + print("}") + print("") def print_mapping_table(bits): - print "/* THIS FILE IS GENERATED, DO NOT EDIT */" - print "" - print "#ifndef EVENT_NAMES_H" - print "#define EVENT_NAMES_H" - print "" - print "#define SYN_MAX 3 /* linux/input.h doesn't define that */" - print "" + print("/* THIS FILE IS GENERATED, DO NOT EDIT */") + print("") + print("#ifndef EVENT_NAMES_H") + print("#define EVENT_NAMES_H") + print("") + print("#define SYN_MAX 3 /* linux/input.h doesn't define that */") + print("") for prefix in prefixes: if prefix == "BTN_": @@ -101,19 +104,19 @@ def print_mapping_table(bits): print_map(bits) - print "static const char * event_get_type_name(int type) {" - print " return ev_map[type];" - print " }" - print "" - print "static const char * event_get_code_name(int type, int code) {" - print " return map[type] ? map[type][code] : NULL;" - print "}" - print "" - print "#endif /* EVENT_NAMES_H */" + print("static const char * event_get_type_name(int type) {") + print(" return ev_map[type];") + print(" }") + print("") + print("static const char * event_get_code_name(int type, int code) {") + print(" return map[type] ? map[type][code] : NULL;") + print("}") + print("") + print("#endif /* EVENT_NAMES_H */") def print_python_mapping_table(bits): - print "# THIS FILE IS GENERATED, DO NOT EDIT" - print "" + print("# THIS FILE IS GENERATED, DO NOT EDIT") + print("") for prefix in prefixes: if prefix == "BTN_": @@ -122,15 +125,15 @@ def print_python_mapping_table(bits): print_python_map(bits) - print "def event_get_type_name(type):" - print " return ev_map[type]" - print "" - print "" - print "def event_get_code_name(type, code):" - print " if map.has_key(type) and map[type].has_key(code):" - print " return map[type][code]" - print " return 'UNKNOWN'" - print "" + print("def event_get_type_name(type):") + print(" return ev_map[type]") + print("") + print("") + print("def event_get_code_name(type, code):") + print(" if map.has_key(type) and map[type].has_key(code):") + print(" return map[type][code]") + print(" return 'UNKNOWN'") + print("") def parse_define(bits, line): m = re.match(r"^#define\s+(\w+)\s+(\w+)", line) |