From 3bb3d09d747182aa7c485f7c9eb6eaf0d27238a3 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Fri, 9 Apr 2021 20:45:56 +0200 Subject: [PATCH] #78 filtering yubikey devices --- keymapper/getdevices.py | 26 ++++++++++++++++++++++++++ tests/test.py | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/keymapper/getdevices.py b/keymapper/getdevices.py index 95d7890c..6bb69382 100644 --- a/keymapper/getdevices.py +++ b/keymapper/getdevices.py @@ -22,6 +22,7 @@ """Device and evdev stuff that is independent from the display server.""" +import re import multiprocessing import threading import time @@ -168,6 +169,28 @@ def classify(device): return UNKNOWN +DENYLIST = [ + ('Yubico', r'.*YubiKey.*') +] + + +def is_denylisted(device): + """Check if a device should not be used in key-mapper. + + Parameters + ---------- + device : InputDevice + """ + for vendor, name in DENYLIST: + if not re.match(vendor, str(device.info.vendor), re.IGNORECASE): + return False + + if not re.match(name, str(device.name), re.IGNORECASE): + return False + + return True + + class _GetDevices(threading.Thread): """Process to get the devices that can be worked with. @@ -217,6 +240,9 @@ class _GetDevices(threading.Thread): # skip devices that don't provide buttons that can be mapped continue + if is_denylisted(device): + continue + name = device.name path = device.path diff --git a/tests/test.py b/tests/test.py index 31a052ad..00723e7b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -212,6 +212,14 @@ fixtures = { 'info': evdev.device.DeviceInfo(5, 1, 5, 1), 'name': 'key-mapper device 2' }, + + # denylisted + '/dev/input/event51': { + 'capabilities': {evdev.ecodes.EV_KEY: keyboard_keys}, + 'phys': 'usb-0000:03:00.0-5/input1', + 'info': evdev.device.DeviceInfo(6, 'YuBiCo', 6, 1), + 'name': 'fooYuBiKeYbar' + }, }