pyudev.discover module¶
Tools to discover a device given limited information.
-
class
pyudev.discover.DeviceFileHypothesis¶ Bases:
pyudev.discover.HypothesisDiscover the device assuming the value is some portion of a device file.
The device file may be a link to a device node.
-
classmethod
get_link_dirs(context)¶ Get all directories that may contain links to device nodes.
This method checks the device links of every device, so it is very expensive.
-
classmethod
lookup(context, key)¶ Lookup the device under the assumption that the key is part of the name of a device file.
It is assumed that either it is the whole name of the device file or it is the basename.
A device file may be a device node or a device link.
-
classmethod
match(value)¶ Match the given string according to the hypothesis.
The purpose of this method is to obtain a value corresponding to
valueif that is possible. It may use a regular expression, but in general it should just returnvalueand let the lookup method sort out the rest.- Parameters
value (str) – the string to inspect
- Returns
the matched thing or None if unmatched
- Return type
the type of lookup’s key parameter or NoneType
-
classmethod
-
class
pyudev.discover.DeviceNameHypothesis¶ Bases:
pyudev.discover.HypothesisDiscover the device assuming the input is a device name.
Try every available subsystem.
-
classmethod
find_subsystems(context)¶ Find all subsystems in sysfs.
-
classmethod
lookup(context, key)¶ Lookup by the path.
-
classmethod
-
class
pyudev.discover.DeviceNumberHypothesis¶ Bases:
pyudev.discover.HypothesisRepresents the hypothesis that the device is a device number.
The device may be separated into major/minor number or a composite number.
-
classmethod
find_subsystems(context)¶ Find subsystems in /sys/dev.
- Parameters
context (Context) – the context
- Returns
a lis of available subsystems
- Return type
list of str
-
classmethod
lookup(context, key)¶ Lookup by the device number.
-
classmethod
-
class
pyudev.discover.DevicePathHypothesis¶ Bases:
pyudev.discover.HypothesisDiscover the device assuming the identifier is a device path.
-
classmethod
lookup(context, key)¶ Lookup by the path.
-
classmethod
-
class
pyudev.discover.Discovery¶ Bases:
objectProvides discovery methods for devices.
-
get_devices(context, value)¶ Get the devices corresponding to value.
-
-
class
pyudev.discover.Hypothesis¶ Bases:
objectRepresents a hypothesis about the meaning of the device identifier.
-
classmethod
get_devices(context, value)¶ Get any devices that may correspond to the given string.
-
abstract classmethod
lookup(context, key)¶ Lookup the given string according to the hypothesis.
- Parameters
context (Context) – the pyudev context
key (the type of match's return value if not None) – a key with which to lookup the device
- Returns
a list of Devices obtained
- Return type
frozenset of
Device
-
abstract classmethod
match(value)¶ Match the given string according to the hypothesis.
The purpose of this method is to obtain a value corresponding to
valueif that is possible. It may use a regular expression, but in general it should just returnvalueand let the lookup method sort out the rest.- Parameters
value (str) – the string to inspect
- Returns
the matched thing or None if unmatched
- Return type
the type of lookup’s key parameter or NoneType
-
classmethod
setup(context)¶ A potentially expensive method that may allow an
Hypothesisto find devices more rapidly or to find a device that it would otherwise miss.- Parameters
context (Context) – the pyudev context
-
classmethod
-
pyudev.discover.wrap_exception(func)¶ Allow Device discovery methods to return None instead of raising an exception.