[PATCH evemu 3/3] py: remove heuristic _find_newest_devnode() and rely on evemu
Benjamin Tissoires
benjamin.tissoires at gmail.com
Mon Jan 13 15:30:32 PST 2014
Evemu can now give us the device node from the library, so remove the
heuristic in python.
I also had to play with unicode and bytes regarding Device constructor.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
Ok, here I have a ugly 'sys.version_info >= (3,0,0)'.
If someone has a better idea, I'll take it :)
Cheers,
Benjamin
python/evemu/__init__.py | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 4f64204..2ff767e 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -28,6 +28,11 @@ import evemu.const
__all__ = ["Device"]
+import sys
+if sys.version_info >= (3,0,0):
+ global basestring
+ basestring = str
+
class Device(object):
"""
@@ -45,7 +50,7 @@ class Device(object):
to create a pseudo-device node.
"""
- if type(f) == str:
+ if isinstance(f, basestring):
self._file = open(f)
elif hasattr(f, "read"):
self._file = f
@@ -73,21 +78,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).decode(evemu.const.ENCODING)
+ 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