[PATCH evemu 09/12] python: add an extra flag to evemu.Device.__init__ to avoid uinput creation

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 22 16:42:47 PDT 2014


If we're just reading a file for info, we don't need to create a uinput
device.

This means we can now use the conversion script without being root. Oh, the
progress!

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 python/evemu/__init__.py          |  7 +++++--
 python/evemu/tests/test_device.py | 14 ++++++++++++++
 src/convert-old-dumps-to-1.1.py   |  2 +-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 4f64204..65c7cf0 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -35,7 +35,7 @@ class Device(object):
     reported by the kernel or a pseudodevice as created through a .prop file.
     """
 
-    def __init__(self, f):
+    def __init__(self, f, create=True):
         """
         Initializas an evemu Device.
 
@@ -43,6 +43,8 @@ class Device(object):
         f -- a file object or filename string for either an existing input
         device node (/dev/input/eventNN) or an evemu prop file that can be used
         to create a pseudo-device node.
+        create -- If f points to an evemu prop file, 'create' specifies if a
+        uinput device should be created
         """
 
         if type(f) == str:
@@ -61,7 +63,8 @@ class Device(object):
         if self._is_propfile:
             fs = self._libc.fdopen(self._file.fileno(), b"r")
             self._libevemu.evemu_read(self._evemu_device, fs)
-            self._file = self._create_devnode()
+            if create:
+                self._file = self._create_devnode()
         else:
             self._libevemu.evemu_extract(self._evemu_device,
                                          self._file.fileno())
diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
index faca6ad..51a0050 100644
--- a/python/evemu/tests/test_device.py
+++ b/python/evemu/tests/test_device.py
@@ -64,6 +64,13 @@ class DeviceActionTestCase(evemu.testing.testcase.BaseTestCase):
         """
         d = evemu.Device(self.get_device_file())
 
+    def test_construct_from_prop_file_name_no_create(self):
+        """
+        Verifies a device can be constructed from an evemu prop file name,
+        without creating a uinput device.
+        """
+        d = evemu.Device(self.get_device_file(), create=False)
+
     def test_construct_from_prop_file_file(self):
         """
         Verifies a device can be constructed from an evemu prop file file
@@ -71,6 +78,13 @@ class DeviceActionTestCase(evemu.testing.testcase.BaseTestCase):
         """
         d = evemu.Device(open(self.get_device_file()))
 
+    def test_construct_from_prop_file_file(self):
+        """
+        Verifies a device can be constructed from an evemu prop file file
+        object, without creating a uinput device.
+        """
+        d = evemu.Device(open(self.get_device_file()), create=False)
+
     def test_describe(self):
         """
         Verifies that a device description can be correctly extracted from a
diff --git a/src/convert-old-dumps-to-1.1.py b/src/convert-old-dumps-to-1.1.py
index 52ea141..4caf4df 100755
--- a/src/convert-old-dumps-to-1.1.py
+++ b/src/convert-old-dumps-to-1.1.py
@@ -48,7 +48,7 @@ if __name__ == "__main__":
 	if len(sys.argv) < 2:
 		exit(usage(sys.argv))
 	file_desc = sys.argv[1]
-	d = evemu.Device(file_desc)
+	d = evemu.Device(file_desc, create=False)
 	d.describe(sys.stdout)
 	d = None
 	if len(sys.argv) > 2:
-- 
1.9.3



More information about the Input-tools mailing list