[PATCH evemu v2 3/4] py: remove heuristic _find_newest_devnode() and rely on evemu
Benjamin Tissoires
benjamin.tissoires at gmail.com
Wed Jan 15 13:05:00 PST 2014
Evemu can now give us the device node from the library, so remove the
heuristic in python.
This commit breaks the python 3 support:
the property devnode() now returns a bytes (we get the initial information
from the C library). So the test in the constructor "if type(f) == str"
fails.
Things are OK in python 2.X
Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
v2:
- remove .decode(evemu.const.ENCODING) call after evemu_get_devnode() C call
(not needed in Python 2.X)
- splitted the str/unicode with following patch
python/evemu/__init__.py | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 4f64204..deaf95e 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -73,21 +73,8 @@ class Device(object):
def _create_devnode(self):
self._libevemu.evemu_create_managed(self._evemu_device)
- return open(self._find_newest_devnode(self.name), 'r+b', buffering=0)
-
- def _find_newest_devnode(self, target_name):
- newest_node = (None, float(0))
- for sysname in glob.glob("/sys/class/input/event*/device/name"):
- with open(sysname) as f:
- name = f.read().rstrip()
- if name == target_name:
- ev = re.search("(event\d+)", sysname)
- if ev:
- devname = os.path.join("/dev/input", ev.group(1))
- ctime = os.stat(devname).st_ctime
- if ctime > newest_node[1]:
- newest_node = (devname, ctime)
- return newest_node[0]
+ devnode = self._libevemu.evemu_get_devnode(self._evemu_device)
+ return open(devnode, 'r+b', buffering=0)
def _check_is_propfile(self, f):
if stat.S_ISCHR(os.fstat(f.fileno()).st_mode):
--
1.8.4.2
More information about the Input-tools
mailing list