Closed enok71 closed 3 weeks ago
Ok I found now that this is by design. See the documentation string for Enumerator
class. Still I can't see the practical reason though. A design bug at least? Or perhaps this is a design feature in libudev?
Before iteration the device list can be filtered by subsystem or by
property values using :meth:`match_subsystem` and
:meth:`match_property`. Multiple subsystem (property) filters are
combined using a logical OR, filters of different types are combined
using a logical AND. The following filter for instance::
devices.match_subsystem('block').match_property(
'ID_TYPE', 'disk').match_property('DEVTYPE', 'disk')
means the following::
subsystem == 'block' and (ID_TYPE == 'disk' or DEVTYPE == 'disk')
Ok I found now that this is by design. See the documentation string for
Enumerator
class. Still I can't see the practical reason though. A design bug at least? Or perhaps this is a design feature in libudev?Before iteration the device list can be filtered by subsystem or by property values using :meth:`match_subsystem` and :meth:`match_property`. Multiple subsystem (property) filters are combined using a logical OR, filters of different types are combined using a logical AND. The following filter for instance:: devices.match_subsystem('block').match_property( 'ID_TYPE', 'disk').match_property('DEVTYPE', 'disk') means the following:: subsystem == 'block' and (ID_TYPE == 'disk' or DEVTYPE == 'disk')
Yes. I think this exactly reflects the libudev design (and that probably reflects the systemd design).
Yes. I think this exactly reflects the libudev design (and that probably reflects the systemd design).
How inconvenient. And hard to fix. But workaround is to write explicit additional filtering code of course. And to remember to not specify more than one property argument (unless that surprising OR between properties is desired):
for d in context.list_devices(subsystem='usb', DEVNUM='001'):
if d.get('BUSNUM') != '001':
continue
print(d.get('BUSNUM'), d.get('DEVNUM'))
I am using pyudev 0.24.3. I want to list the USB devices filtering on given Bus and Device numbers. I have the following devices attached:
But it seems that if both BUSNUM and DEVNUM arguments are given to
list_devices(BUSNUM=a, DEVNUM=b)
the resulting list contains the devices that matches either BUSNUM=a or DEVNUM=b. I would have expected to only have devices listed that match both BUSNUM=a and DEVNUM=b.Looks like a bug. E.g.:
If I skip 'BUSNUM' argument the 'DEVNUM' works fine:
The order of 'BUSNUM' and 'DEVNUM' doesn't matter: