[PATCH evemu 02/19] py: Replace print statement with function call

Daniel Martin consume.noise at gmail.com
Mon Jan 6 09:38:02 PST 2014


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.

v2: Don't bump AM_PYTHON_PATH to 2.7, add "from __future__ ..." and
    adjust the commit message.

Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
 src/convert-old-dumps-to-1.1.py | 21 +++++----
 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)
-- 
1.8.5.2



More information about the Input-tools mailing list