Skip to content

Commit f571a6f

Browse files
Generate ev.py in build_py step.
1 parent f7dd579 commit f571a6f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
# -*- coding: utf-8 -*-
22

3+
import re
4+
5+
from distutils.command.build_py import build_py as _build_py
36
from distutils.core import setup, Extension
47

8+
def append_ev(ev_type, ev_name):
9+
with open("/usr/include/linux/input.h") as f:
10+
with open("src/ev.py", "a") as f2:
11+
for line in f:
12+
match = re.match(r"^#define (" + ev_name + "_.*)\t+((?:0x[0-9a-f]+)|(?:\d+))", line)
13+
if match:
14+
print >>f2, "%s = (%s, %s)" % (match.group(1).strip(), ev_type, match.group(2).strip())
15+
16+
class build_py(_build_py):
17+
18+
def run(self):
19+
append_ev("0x01", "KEY")
20+
append_ev("0x01", "BTN")
21+
append_ev("0x02", "REL")
22+
append_ev("0x03", "ABS")
23+
_build_py.run(self)
24+
525
setup(name='python-uinput',
626
version='0.5',
727
description='Python bindings for Linux uinput system.',
@@ -27,6 +47,7 @@
2747
device drivers into the Linux kernel. Python-uinput provides a
2848
pythonic API to the Linux uinput system.
2949
""",
50+
cmdclass={'build_py': build_py},
3051
ext_modules=[Extension('_libsuinput', ['libsuinput/src/suinput.c'],
3152
libraries=["udev"])]
3253
)

0 commit comments

Comments
 (0)