[PATCH evemu 3/3] py: remove heuristic _find_newest_devnode() and rely on evemu
Peter Hutterer
peter.hutterer at who-t.net
Mon Jan 13 21:42:45 PST 2014
On Mon, Jan 13, 2014 at 06:30:32PM -0500, Benjamin Tissoires wrote:
> 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
can we get this into a separate patch with an explanation of what's going
wrong here? any reason we even have this condition for string?
the following should be acceptable too:
if hasattr(f, "read"):
self._file = f
else
self._file = open(f)
If open succeeds, we don't really care what the type of "f" is.
> @@ -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):
this hunk Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
> --
> 1.8.4.2
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools
More information about the Input-tools
mailing list