[PATCH evemu 07/10] python: move make-event-names to the python directory

Peter Hutterer peter.hutterer at who-t.net
Mon Aug 4 21:01:49 PDT 2014


Nothing in the C code uses it anymore

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 python/evemu/Makefile.am         |   5 +-
 python/evemu/make-event-names.py | 182 +++++++++++++++++++++++++++++++++++++++
 src/Makefile.am                  |   2 +-
 src/make-event-names.py          | 182 ---------------------------------------
 4 files changed, 186 insertions(+), 185 deletions(-)
 create mode 100755 python/evemu/make-event-names.py
 delete mode 100755 src/make-event-names.py

diff --git a/python/evemu/Makefile.am b/python/evemu/Makefile.am
index 7048627..2801819 100644
--- a/python/evemu/Makefile.am
+++ b/python/evemu/Makefile.am
@@ -1,5 +1,6 @@
-event_names.py: Makefile $(top_srcdir)/src/make-event-names.py
-	$(PYTHON) $(top_srcdir)/src/make-event-names.py --output=python > $@
+event_names.py: Makefile make-event-names.py
+	$(PYTHON) $(srcdir)/make-event-names.py --output=python > $@
 
 BUILT_SOURCES = event_names.py
 CLEANFILES = event_names.py event_names.pyc
+EXTRA_DIST = make-event-names.py
diff --git a/python/evemu/make-event-names.py b/python/evemu/make-event-names.py
new file mode 100755
index 0000000..d07e383
--- /dev/null
+++ b/python/evemu/make-event-names.py
@@ -0,0 +1,182 @@
+#!/usr/bin/env python
+# Parses linux/input.h scanning for #define KEY_FOO 134
+# Prints a Python file that can be used as mapping table
+#
+
+# Make sure the print statement is disabled and the function is used.
+from __future__ import print_function
+
+import argparse
+import re
+import sys
+import textwrap
+
+SOURCE_FILE = "/usr/include/linux/input.h"
+
+class Bits(object):
+	pass
+
+prefixes = [
+		"EV_",
+		"REL_",
+		"ABS_",
+		"KEY_",
+		"BTN_",
+		"LED_",
+		"SND_",
+		"MSC_",
+		"SW_",
+		"FF_",
+		"SYN_",
+		"INPUT_PROP_",
+]
+
+blacklist = [
+		"EV_VERSION",
+]
+
+# These defines only work from string->value, not the other way round
+oneway = [
+		"BTN_MISC",
+		"BTN_MOUSE",
+		"BTN_JOYSTICK",
+		"BTN_GAMEPAD",
+		"BTN_DIGI",
+		"BTN_WHEEL",
+		"BTN_TRIGGER_HAPPY"
+]
+
+# As above, but input.h defines them as aliases instead of int values
+aliases = {}
+
+def p(s):
+	print(textwrap.dedent(s))
+
+def print_python_bits(bits, prefix):
+	if  not hasattr(bits, prefix):
+		return
+
+	print("%s_map = {" % (prefix))
+	for val, name in getattr(bits, prefix).items():
+		if val in oneway:
+			print("	\"%s\" : %d," % (val, name))
+		else:
+			print("	%d : \"%s\", \"%s\" : %d," % (val, name, name, val))
+
+	for alias, mapping in aliases.items():
+		if prefix == "key" and alias.lower().startswith("btn"):
+			pass
+		elif not alias.lower().startswith(prefix):
+			continue
+		for val, name in getattr(bits, prefix).items():
+			if name == mapping:
+				print("	\"%s\" : %d," % (alias, val))
+				break
+
+	print("}")
+	print("")
+
+def print_python_map(bits):
+	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("	\"EV_%s\" : %s_map," % (name, name.lower()))
+
+	print("}")
+	print("")
+
+def print_python_mapping_table(bits):
+	p("""# THIS FILE IS GENERATED, DO NOT EDIT")
+	""")
+
+	for prefix in prefixes:
+		if prefix == "BTN_":
+			continue
+		print_python_bits(bits, prefix[:-1].lower())
+
+	print_python_map(bits)
+
+	p("""
+	def event_get_name(event_type, event_code = None):
+		'''
+		Returns the event type or code name.
+		'''
+		if not event_code:
+			if type(event_type) != int:
+				raise TypeError("expected an int")
+			return ev_map[event_type]
+
+		if type(event_code) != int:
+			raise TypeError("expected an int")
+
+		return map[event_type][event_code]
+
+	def event_get_value(event_type, event_code = None):
+		'''
+		Returns the event type or code value.
+		'''
+		if not event_code:
+			if type(event_type) != str:
+				raise TypeError("expected a string")
+			return ev_map[event_type]
+
+		if type(event_code) != str:
+			raise TypeError("expected a string")
+
+		return map[event_type][event_code]
+	""")
+
+def parse_define(bits, line):
+	m = re.match(r"^#define\s+(\w+)\s+(\w+)", line)
+	if m == None:
+		return
+
+	name = m.group(1)
+
+	if name in blacklist:
+		return
+	if name.startswith("EVIOC"):
+		return
+
+	try:
+		value = int(m.group(2), 0)
+	except ValueError:
+		aliases[name] = m.group(2)
+		return
+
+	for prefix in prefixes:
+		if not name.startswith(prefix):
+			continue
+
+		attrname = prefix[:-1].lower()
+		if attrname == "btn":
+			attrname = "key"
+
+		if not hasattr(bits, attrname):
+			setattr(bits, attrname, {})
+		b = getattr(bits, attrname)
+		if name in oneway:
+			b[name] = value
+		else:
+			b[value] = name
+
+def parse(path):
+	fp = open(path)
+
+	bits = Bits()
+
+	lines = fp.readlines()
+	for line in lines:
+		if not line.startswith("#define"):
+			continue
+		parse_define(bits, line)
+
+	return bits
+
+if __name__ == "__main__":
+	bits = parse(SOURCE_FILE)
+	print_python_mapping_table(bits)
diff --git a/src/Makefile.am b/src/Makefile.am
index 8eeaf2c..128164a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,4 +20,4 @@ AM_CPPFLAGS = -I$(top_srcdir)/include/ $(LIBEVDEV_CFLAGS)
 libevemuincludedir = $(includedir)
 libevemuinclude_HEADERS = evemu.h
 
-EXTRA_DIST = $(version_script) make-event-names.py convert-old-dumps-to-1.1.py
+EXTRA_DIST = $(version_script) convert-old-dumps-to-1.1.py
diff --git a/src/make-event-names.py b/src/make-event-names.py
deleted file mode 100755
index d07e383..0000000
--- a/src/make-event-names.py
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/usr/bin/env python
-# Parses linux/input.h scanning for #define KEY_FOO 134
-# Prints a Python file that can be used as mapping table
-#
-
-# Make sure the print statement is disabled and the function is used.
-from __future__ import print_function
-
-import argparse
-import re
-import sys
-import textwrap
-
-SOURCE_FILE = "/usr/include/linux/input.h"
-
-class Bits(object):
-	pass
-
-prefixes = [
-		"EV_",
-		"REL_",
-		"ABS_",
-		"KEY_",
-		"BTN_",
-		"LED_",
-		"SND_",
-		"MSC_",
-		"SW_",
-		"FF_",
-		"SYN_",
-		"INPUT_PROP_",
-]
-
-blacklist = [
-		"EV_VERSION",
-]
-
-# These defines only work from string->value, not the other way round
-oneway = [
-		"BTN_MISC",
-		"BTN_MOUSE",
-		"BTN_JOYSTICK",
-		"BTN_GAMEPAD",
-		"BTN_DIGI",
-		"BTN_WHEEL",
-		"BTN_TRIGGER_HAPPY"
-]
-
-# As above, but input.h defines them as aliases instead of int values
-aliases = {}
-
-def p(s):
-	print(textwrap.dedent(s))
-
-def print_python_bits(bits, prefix):
-	if  not hasattr(bits, prefix):
-		return
-
-	print("%s_map = {" % (prefix))
-	for val, name in getattr(bits, prefix).items():
-		if val in oneway:
-			print("	\"%s\" : %d," % (val, name))
-		else:
-			print("	%d : \"%s\", \"%s\" : %d," % (val, name, name, val))
-
-	for alias, mapping in aliases.items():
-		if prefix == "key" and alias.lower().startswith("btn"):
-			pass
-		elif not alias.lower().startswith(prefix):
-			continue
-		for val, name in getattr(bits, prefix).items():
-			if name == mapping:
-				print("	\"%s\" : %d," % (alias, val))
-				break
-
-	print("}")
-	print("")
-
-def print_python_map(bits):
-	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("	\"EV_%s\" : %s_map," % (name, name.lower()))
-
-	print("}")
-	print("")
-
-def print_python_mapping_table(bits):
-	p("""# THIS FILE IS GENERATED, DO NOT EDIT")
-	""")
-
-	for prefix in prefixes:
-		if prefix == "BTN_":
-			continue
-		print_python_bits(bits, prefix[:-1].lower())
-
-	print_python_map(bits)
-
-	p("""
-	def event_get_name(event_type, event_code = None):
-		'''
-		Returns the event type or code name.
-		'''
-		if not event_code:
-			if type(event_type) != int:
-				raise TypeError("expected an int")
-			return ev_map[event_type]
-
-		if type(event_code) != int:
-			raise TypeError("expected an int")
-
-		return map[event_type][event_code]
-
-	def event_get_value(event_type, event_code = None):
-		'''
-		Returns the event type or code value.
-		'''
-		if not event_code:
-			if type(event_type) != str:
-				raise TypeError("expected a string")
-			return ev_map[event_type]
-
-		if type(event_code) != str:
-			raise TypeError("expected a string")
-
-		return map[event_type][event_code]
-	""")
-
-def parse_define(bits, line):
-	m = re.match(r"^#define\s+(\w+)\s+(\w+)", line)
-	if m == None:
-		return
-
-	name = m.group(1)
-
-	if name in blacklist:
-		return
-	if name.startswith("EVIOC"):
-		return
-
-	try:
-		value = int(m.group(2), 0)
-	except ValueError:
-		aliases[name] = m.group(2)
-		return
-
-	for prefix in prefixes:
-		if not name.startswith(prefix):
-			continue
-
-		attrname = prefix[:-1].lower()
-		if attrname == "btn":
-			attrname = "key"
-
-		if not hasattr(bits, attrname):
-			setattr(bits, attrname, {})
-		b = getattr(bits, attrname)
-		if name in oneway:
-			b[name] = value
-		else:
-			b[value] = name
-
-def parse(path):
-	fp = open(path)
-
-	bits = Bits()
-
-	lines = fp.readlines()
-	for line in lines:
-		if not line.startswith("#define"):
-			continue
-		parse_define(bits, line)
-
-	return bits
-
-if __name__ == "__main__":
-	bits = parse(SOURCE_FILE)
-	print_python_mapping_table(bits)
-- 
1.9.3



More information about the Input-tools mailing list