pyudev.core module¶
Core types and functions of pyudev.
- class pyudev.core.Context¶
- Bases: - object- A device database connection. - This class represents a connection to the udev device database, and is really the central object to access udev. You need an instance of this class for almost anything else in pyudev. - This class itself gives access to various udev configuration data (e.g. - sys_path,- device_path), and provides device enumeration (- list_devices()).- Instances of this class can directly be given as - udev *to functions wrapped through- ctypes.- property device_path¶
- The device directory path defaulting to - /devas unicode string.
 - list_devices(**kwargs)¶
- List all available devices. - The arguments of this method are the same as for - Enumerator.match(). In fact, the arguments are simply passed straight to method- match().- This function creates and returns an - Enumeratorobject, that can be used to filter the list of devices, and eventually retrieve- Deviceobjects representing matching devices.- Changed in version 0.8: Accept keyword arguments now for easy matching. 
 - property log_priority¶
- The logging priority of the interal logging facitility of udev as integer with a standard - syslogpriority. Assign to this property to change the logging priority.- UDev uses the standard - syslogpriorities. Constants for these priorities are defined in the- syslogmodule in the standard library:- >>> import syslog >>> context = pyudev.Context() >>> context.log_priority = syslog.LOG_DEBUG - Added in version 0.9. 
 - property run_path¶
- The run runtime directory path defaulting to - /runas unicode string.- Required udev version: 167 - Added in version 0.10. 
 - property sys_path¶
- The - sysfsmount point defaulting to- /sys'as unicode string.
 
- class pyudev.core.Enumerator(context)¶
- Bases: - object- A filtered iterable of devices. - To retrieve devices, simply iterate over an instance of this class. This operation yields - Deviceobjects representing the available devices.- Before iteration the device list can be filtered by subsystem or by property values using - match_subsystem()and- 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') - Once added, a filter cannot be removed anymore. Create a new object instead. - Instances of this class can directly be given as given - udev_enumerate *to functions wrapped through- ctypes.- match(**kwargs)¶
- Include devices according to the rules defined by the keyword arguments. These keyword arguments are interpreted as follows: - The value for the keyword argument - subsystemis forwarded to- match_subsystem().
- The value for the keyword argument - sys_nameis forwared to- match_sys_name().
- The value for the keyword argument - tagis forwared to- match_tag().
- The value for the keyword argument - parentis forwared to- match_parent().
- All other keyword arguments are forwareded one by one to - match_property(). The keyword argument itself is interpreted as property name, the value of the keyword argument as the property value.
 - All keyword arguments are optional, calling this method without no arguments at all is simply a noop. - Return the instance again. - Added in version 0.8. - Changed in version 0.13: Add - parentkeyword.
 - match_attribute(attribute, value, nomatch=False)¶
- Include all devices, whose - attributehas the given- value.- attributeis either a unicode string or a byte string, containing the name of a sys attribute to match.- valueis an attribute value, being one of the following types:- int(),
- bool()
- A byte string 
- Anything convertable to a unicode string (including a unicode string itself) 
 - If - nomatchis- True(default is- False), the match is inverted: A device is include if the- attributedoes not match the given- value.- Note - If - nomatchis- True, devices which do not have the given- attributeat all are also included. In other words, with- nomatch=Truethe given- attributeis not guaranteed to exist on all returned devices.- Return the instance again. 
 - match_is_initialized()¶
- Include only devices, which are initialized. - Initialized devices have properly set device node permissions and context, and are (in case of network devices) fully renamed. - Currently this will not affect devices which do not have device nodes and are not network interfaces. - Return the instance again. - See also - Device.is_initialized- Required udev version: 165 - Added in version 0.8. 
 - match_parent(parent)¶
- Include all devices on the subtree of the given - parentdevice.- The - parentdevice itself is also included.- parentis a- Device.- Return the instance again. - Required udev version: 172 - Added in version 0.13. 
 - match_property(prop, value)¶
- Include all devices, whose - prophas the given- value.- propis either a unicode string or a byte string, containing the name of the property to match.- valueis a property value, being one of the following types:- int()
- bool()
- A byte string 
- Anything convertable to a unicode string (including a unicode string itself) 
 - Return the instance again. 
 - match_subsystem(subsystem, nomatch=False)¶
- Include all devices, which are part of the given - subsystem.- subsystemis either a unicode string or a byte string, containing the name of the subsystem. If- nomatchis- True(default is- False), the match is inverted: A device is only included if it is not part of the given- subsystem.- Note that, if a device has no subsystem, it is not included either with value of - nomatchTrue or with value of- nomatchFalse.- Return the instance again. 
 - match_sys_name(sys_name)¶
- Include all devices with the given name. - sys_nameis a byte or unicode string containing the device name.- Return the instance again. - Added in version 0.8. 
 - match_tag(tag)¶
- Include all devices, which have the given - tagattached.- tagis a byte or unicode string containing the tag name.- Return the instance again. - Required udev version: 154 - Added in version 0.6.