chore: initialize repository and staged implementation plan
This commit is contained in:
commit
cb0e9d156f
48 files changed
+7343
No files matched your search
+80
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Диагностика USB-клавиатур (без блокирующего чтения)."""
|
||||
import os
|
||||
import re
|
||||
import glob
|
||||
import stat
|
||||
|
||||
import evdev
|
||||
from evdev import ecodes
|
||||
|
||||
|
||||
def sysfs_port(path):
|
||||
sysfs = os.path.realpath(f"/sys/class/input/{os.path.basename(path)}")
|
||||
while sysfs and sysfs != "/":
|
||||
if os.path.exists(os.path.join(sysfs, "idVendor")):
|
||||
name = os.path.basename(sysfs)
|
||||
m = re.match(r"\d+-([\d.]+)", name)
|
||||
return m.group(1) if m else name
|
||||
sysfs = os.path.dirname(sysfs)
|
||||
return None
|
||||
|
||||
|
||||
def phys_port(dev):
|
||||
m = re.search(r"usb-[\d.]+-([\d.]+)/", dev.phys or "")
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
def by_path_port(dev_path):
|
||||
"""Порт из /dev/input/by-path/<...>-usb-0:1.3.2:1.0-event-kbd."""
|
||||
for link in glob.glob("/dev/input/by-path/*"):
|
||||
target = os.path.realpath(link)
|
||||
if target == os.path.realpath(dev_path):
|
||||
m = re.search(r"usb-0:([\d.]+):", os.path.basename(link))
|
||||
if m:
|
||||
return m.group(1)
|
||||
return None
|
||||
|
||||
|
||||
print(f"UID={os.getuid()} USER={os.getenv('USER')}")
|
||||
print("-" * 100)
|
||||
print(f"{'device':<22} {'perms':<7} {'kbd':<4} {'by-path':<8} {'sysfs':<8} {'phys':<8} name")
|
||||
print("-" * 100)
|
||||
|
||||
devices = list(evdev.list_devices())
|
||||
if not devices:
|
||||
print("evdev.list_devices() вернул пустой список!")
|
||||
print("Проверьте: ls -l /dev/input/")
|
||||
|
||||
for path in devices:
|
||||
try:
|
||||
st = os.stat(path)
|
||||
perms = oct(stat.S_IMODE(st.st_mode))
|
||||
except OSError as e:
|
||||
print(f"{path:<22} STAT ERROR: {e}")
|
||||
continue
|
||||
|
||||
try:
|
||||
dev = evdev.InputDevice(path)
|
||||
except Exception as e:
|
||||
print(f"{path:<22} {perms:<7} OPEN ERR: {e}")
|
||||
continue
|
||||
|
||||
try:
|
||||
keys = dev.capabilities().get(ecodes.EV_KEY, [])
|
||||
is_kb = ecodes.KEY_A in keys and ecodes.KEY_B in keys
|
||||
bpp = by_path_port(path)
|
||||
sp = sysfs_port(path)
|
||||
pp = phys_port(dev)
|
||||
print(f"{path:<22} {perms:<7} {str(is_kb):<4} {str(bpp):<8} {str(sp):<8} {str(pp):<8} {dev.name!r}")
|
||||
finally:
|
||||
dev.close()
|
||||
|
||||
print("-" * 100)
|
||||
print("\nВсё, что лежит в /dev/input/by-path/:")
|
||||
for link in sorted(glob.glob("/dev/input/by-path/*")):
|
||||
print(f" {os.path.basename(link)} → {os.readlink(link)}")
|
||||
|
||||
print("\nСоветы:")
|
||||
print(" * Значение 'by-path' (например, 1.3.2) — самый надёжный идентификатор порта.")
|
||||
print(" * Впишите эти значения в PORT_TO_GROUP внутри badusb.py.")
|
||||
Reference in new issue
Block a user