[PATCH evemu 6/7] python: remove deprecated make-event-names.py and the generated event_name.py

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Aug 14 11:00:44 PDT 2014


Nobody uses this file anymore, and it was never been a public python API.
We can safely kill it and remove the need to generate some files from
input.h.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
 .gitignore                       |   1 -
 python/Makefile.am               |  13 +--
 python/evemu/make-event-names.py | 200 ---------------------------------------
 src/convert-old-dumps-to-1.1.py  |   1 -
 4 files changed, 3 insertions(+), 212 deletions(-)
 delete mode 100755 python/evemu/make-event-names.py

diff --git a/.gitignore b/.gitignore
index eddbe2f..a4271f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -87,7 +87,6 @@ patches
 .bzr
 .bzrignore
 python/evemu-test-runner
-python/evemu/event_names.py
 *.pyc
 test-suite.log
 *.trs
diff --git a/python/Makefile.am b/python/Makefile.am
index dc0b777..382bcec 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -21,8 +21,7 @@ python_sources = \
 	evemu/__init__.py \
 	evemu/base.py \
 	evemu/const.py \
-	evemu/exception.py \
-	evemu/event_names.py # generated!
+	evemu/exception.py
 
 nobase_python_PYTHON = $(python_sources)
 
@@ -36,12 +35,6 @@ test_sources = \
 	       evemu/tests/test_base.py \
 	       evemu/tests/test_device.py
 
-$(builddir)/evemu/event_names.py: Makefile $(srcdir)/evemu/make-event-names.py
-	$(MKDIR_P) evemu/
-	$(PYTHON) $(srcdir)/evemu/make-event-names.py > $@
-
-BUILT_SOURCES = $(builddir)/evemu/event_names.py
-
 if BUILD_TESTS
 check_SCRIPTS = evemu-test-runner
 
@@ -56,11 +49,11 @@ evemu-test-runner: evemu-test-runner.in Makefile
 	  $< >$@
 	chmod +x $@
 
-BUILT_SOURCES += evemu-test-runner
+BUILT_SOURCES = evemu-test-runner
 endif
 endif
 
-EXTRA_DIST =  evemu-test-runner.in $(test_sources) $(srcdir)/evemu/make-event-names.py
+EXTRA_DIST =  evemu-test-runner.in $(test_sources)
 
 python3_pyc = \
 		evemu/__pycache__/ \
diff --git a/python/evemu/make-event-names.py b/python/evemu/make-event-names.py
deleted file mode 100755
index 241ee4e..0000000
--- a/python/evemu/make-event-names.py
+++ /dev/null
@@ -1,200 +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("_type_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
-	# This is module-internal API and subject to change at any time.
-	# Use evemu.event_get_value() and evemu.event_get_name() instead.
-	""")
-
-	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 event_code == None:
-			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 _type_map[event_type][event_code]
-
-	def _event_get_value(event_type, event_code = None):
-		'''
-		Returns the event type or code value.
-		'''
-		if event_code == None:
-			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 _type_map[event_type][event_code]
-
-	def _input_prop_get_name(prop):
-		'''
-		Returns the name of the input property.
-		'''
-		if type(prop) != int:
-			raise TypeError("expected an int")
-		return _input_prop_map[prop]
-
-	def _input_prop_get_value(prop):
-		'''
-		Returns the value of the input property.
-		'''
-		if type(prop) != str:
-			raise TypeError("expected a string")
-		return _input_prop_map[prop]
-	""")
-
-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/convert-old-dumps-to-1.1.py b/src/convert-old-dumps-to-1.1.py
index 01362fb..7a7db8b 100755
--- a/src/convert-old-dumps-to-1.1.py
+++ b/src/convert-old-dumps-to-1.1.py
@@ -15,7 +15,6 @@ import re
 import sys
 
 import evemu
-import evemu.event_names
 
 def usage(args):
 	print("%s mydev.desc [mydev.events]" % os.path.basename(args[0]))
-- 
2.0.4



More information about the Input-tools mailing list