Skip to content

Commit 7f9f4e3

Browse files
Include and maintain input event codes
The previous dynamic build-time mechanism for generating ev.py was just a recipe for troubles. The recent change in the filepath of the event code header file is just one example. Dynamic update worked pretty well, but because Linux is known for its uapi stability, we can safely rely on them to maintain event codes in backwards-compatible manner. After all, Python-uinput is just a wrapper for uinput. src/ev.py should be updated whenever new event codes are introduced in mainline kernels. Yes, it is a bit more work, but it's a lot simpler code-wise and the update process is trivial to (semi-)automate.
1 parent 1a60d6d commit 7f9f4e3

2 files changed

Lines changed: 595 additions & 28 deletions

File tree

setup.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import with_statement
3-
from __future__ import print_function
4-
import re
5-
import os.path
62

7-
from distutils.command.build_py import build_py as _build_py
83
from distutils.core import setup, Extension
94

10-
def append_ev(ev_type, ev_name):
11-
# Newer kernels define events in different file
12-
if os.path.exists("/usr/include/linux/input-event-codes.h"):
13-
fpath = "/usr/include/linux/input-event-codes.h"
14-
else:
15-
fpath = "/usr/include/linux/input.h"
16-
with open(fpath) as f:
17-
with open("src/ev.py", "a") as f2:
18-
for line in f:
19-
match = re.match(r"^#define (" + ev_name + "_.*)\t+((?:0x[0-9a-f]+)|(?:\d+))", line)
20-
if match:
21-
print("%s = (%s, %s)" % (match.group(1).strip(), ev_type, match.group(2).strip()), file=f2)
22-
23-
class build_py(_build_py):
24-
25-
def run(self):
26-
append_ev("0x01", "KEY")
27-
append_ev("0x01", "BTN")
28-
append_ev("0x02", "REL")
29-
append_ev("0x03", "ABS")
30-
_build_py.run(self)
31-
325
setup(name='python-uinput',
336
version='0.10.2',
347
description='Pythonic API to Linux uinput kernel module.',
@@ -62,7 +35,6 @@ def run(self):
6235
keyboards and mice for generating arbitrary input events
6336
programmatically.
6437
""",
65-
cmdclass={'build_py': build_py},
6638
ext_modules=[Extension('_libsuinput', ['libsuinput/src/suinput.c'],
6739
libraries=[":libudev.so"])]
6840
)

0 commit comments

Comments
 (0)