[PATCH lsplug 1/2] Simplify device output
Export this patch
---
lsplug/__main__.py | 32 +++++++++++---------------------
1 file changed, 11 insertions(+), 21 deletions(-)
diff --git a/lsplug/__main__.py b/lsplug/__main__.py
index 6fbdc18..a35d372 100644
--- a/lsplug/__main__.py
+++ b/lsplug/__main__.py
@@ -84,9 +84,7 @@ def get_ports(filter=None, use_db=True, fixed=False, portinfo=False, devinfo=Fal
for intf in glob.glob(os.path.join(port, "*:*")):
# Check for disks
- for scsi in glob.glob(os.path.join(intf, "host*/target*/*:*/block/*")):
- devname = os.path.basename(scsi)
- print(f" Device /dev/{devname}")
+ glob_device_basename(os.path.join(intf, "host*/target*/*:*/block/*"), "/dev/")
# Check for mmc storage
for mmc in glob.glob(os.path.join(intf, "*/mmc_host/*")):
@@ -103,33 +101,25 @@ def get_ports(filter=None, use_db=True, fixed=False, portinfo=False, devinfo=Fal
print(f" Device /dev/{ttydir}")
# Check for usbmisc
- for device in glob.glob(os.path.join(intf, "usbmisc/*")):
- devname = os.path.basename(device)
- print(f" Device /dev/usb/{devname}")
+ glob_device_basename(os.path.join(intf, "usbmisc/*"), "/dev/usb/")
# Check for v4l2
- for device in glob.glob(os.path.join(intf, "video4linux/video*")):
- devname = os.path.basename(device)
- print(f" Device /dev/{devname}")
- for device in glob.glob(os.path.join(intf, "media*")):
- devname = os.path.basename(device)
- print(f" Device /dev/{devname}")
+ glob_device_basename(os.path.join(intf, "video4linux/video*"), "/dev/")
+ glob_device_basename(os.path.join(intf, "media*"), "/dev/")
# Check for input devices
- for device in glob.glob(os.path.join(intf, "input/input*/event*")):
- devname = os.path.basename(device)
- print(f" Device /dev/input/{devname}")
+ glob_device_basename(os.path.join(intf, "input/input*/event*"), "/dev/input/")
# Some input drivers have deeper nested paths
- for device in glob.glob(os.path.join(intf, "*/input/input*/event*")):
- devname = os.path.basename(device)
- print(f" Device /dev/input/{devname}")
+ glob_device_basename(os.path.join(intf, "*/input/input*/event*"), "/dev/input/")
# Check for network devices
- for device in glob.glob(os.path.join(intf, "net/*")):
- devname = os.path.basename(device)
- print(f" Device {devname}")
+ glob_device_basename(os.path.join(intf, "net/*"), "")
+def glob_device_basename(path: str, prefix: str):
+ for device in glob.glob(path):
+ devname = os.path.basename(device)
+ print(f" Device {prefix}{devname}")
def main():
parser = argparse.ArgumentParser(description="USB listing tool")
--
2.41.0
[PATCH lsplug 2/2] Add support for /dev/input/(js*,mouse*)
Export this patch
---
lsplug/__main__.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lsplug/__main__.py b/lsplug/__main__.py
index a35d372..adc7b8f 100644
--- a/lsplug/__main__.py
+++ b/lsplug/__main__.py
@@ -109,9 +109,13 @@ def get_ports(filter=None, use_db=True, fixed=False, portinfo=False, devinfo=Fal
# Check for input devices
glob_device_basename(os.path.join(intf, "input/input*/event*"), "/dev/input/")
+ glob_device_basename(os.path.join(intf, "input/input*/js*"), "/dev/input/")
+ glob_device_basename(os.path.join(intf, "input/input*/mouse*"), "/dev/input/")
# Some input drivers have deeper nested paths
glob_device_basename(os.path.join(intf, "*/input/input*/event*"), "/dev/input/")
+ glob_device_basename(os.path.join(intf, "*/input/input*/js*"), "/dev/input/")
+ glob_device_basename(os.path.join(intf, "*/input/input*/mouse*"), "/dev/input/")
# Check for network devices
glob_device_basename(os.path.join(intf, "net/*"), "")
--
2.41.0