From 42f97f3a3c532a50373aecbacd52e45a243df001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alin=20Tr=C4=83istaru?= Date: Wed, 19 Apr 2017 23:29:05 +0300 Subject: [PATCH] linux: rethink device detection logic Don't rely on ID_USB udev item Should fix #110 --- scripts/usb.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/usb.py b/scripts/usb.py index 7cd799e..1187ea7 100644 --- a/scripts/usb.py +++ b/scripts/usb.py @@ -98,15 +98,16 @@ def list_devices(partition=1, fixed=False): import pyudev context = pyudev.Context() + for device in context.list_devices(subsystem='block', ID_BUS="usb"): + devices.append(str(device['DEVNAME'])) + gen.log("\t" + device['DEVNAME']) + if fixed is True: for device in context.list_devices(subsystem='block'): - if device.get('ID_BUS') in ("usb", "scsi", "ata") and device['DEVTYPE'] in ['disk', 'partition']: - devices.append(str(device['DEVNAME'])) - gen.log("\t" + device['DEVNAME']) - else: - for device in context.list_devices(subsystem='block', ID_BUS="usb"): - devices.append(str(device['DEVNAME'])) - gen.log("\t" + device['DEVNAME']) + if device.get('DEVTYPE') in ['disk', 'partition'] and device.get('ID_PART_TABLE_TYPE'): + if device['DEVNAME'] not in devices: + devices.append(str(device['DEVNAME'])) + gen.log("\t" + device['DEVNAME']) except: import dbus