pyudev.discover module¶
Tools to discover a device given limited information.
- class pyudev.discover.DeviceFileHypothesis¶
- Bases: - Hypothesis- Discover 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 return- valueand 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 
 
 
- class pyudev.discover.DeviceNameHypothesis¶
- Bases: - Hypothesis- Discover 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. 
 
- class pyudev.discover.DeviceNumberHypothesis¶
- Bases: - Hypothesis- Represents 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. 
 - classmethod lookup(context, key)¶
- Lookup by the device number. 
 
- class pyudev.discover.DevicePathHypothesis¶
- Bases: - Hypothesis- Discover the device assuming the identifier is a device path. - classmethod lookup(context, key)¶
- Lookup by the path. 
 
- class pyudev.discover.Discovery¶
- Bases: - object- Provides discovery methods for devices. - get_devices(context, value)¶
- Get the devices corresponding to value. 
 
- class pyudev.discover.Hypothesis¶
- Bases: - object- Represents 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 return- valueand 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 
 
 
- pyudev.discover.wrap_exception(func)¶
- Allow Device discovery methods to return None instead of raising an exception.