a
8g+^?4 ã @ s¬ d Z ddlmZmZmZmZ ddlmZ ddlm Z ddl
mZ ddl
mZ ddl
mZ ddlmZ dd lmZ dd
lmZ ddlmZ G dd
„ d
eƒZG dd„ deƒZdS )z’
pyudev.core
===========
Core types and functions of :mod:`pyudev`.
.. moduleauthor:: Sebastian Wiesner
é )Úprint_functionÚdivisionÚunicode_literalsÚabsolute_import)ÚDevices)ÚDeviceNotFoundAtPathError)ÚERROR_CHECKERS)Ú
SIGNATURES)Úload_ctypes_library)Úensure_byte_string)Úensure_unicode_string)Úproperty_value_to_bytes)Úudev_list_iteratec @ sf e Zd ZdZdd„ Zdd„ Zedd„ ƒZedd „ ƒZed
d„ ƒZ edd
„ ƒZ
e
jdd
„ ƒZ
dd„ ZdS )ÚContexta
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.
:attr:`sys_path`, :attr:`device_path`), and provides device enumeration
(:meth:`list_devices()`).
Instances of this class can directly be given as ``udev *`` to functions
wrapped through :mod:`ctypes`.
c C s t dttƒ| _| j ¡ | _dS )z'
Create a new context.
ZudevN)r
r r Ú_libudevZudev_newÚ_as_parameter_©Úself© r ú//usr/lib/python3.9/site-packages/pyudev/core.pyÚ__init__9 s zContext.__init__c C s | j | ¡ d S ©N)r Z
udev_unrefr r r r Ú__del__@ s zContext.__del__c C s t | jdƒrt| j | ¡ƒS dS )zV
The ``sysfs`` mount point defaulting to ``/sys'`` as unicode string.
Úudev_get_sys_pathz/sys)Úhasattrr r r r r r r Úsys_pathC s zContext.sys_pathc C s t | jdƒrt| j | ¡ƒS dS )zU
The device directory path defaulting to ``/dev`` as unicode string.
Úudev_get_dev_pathz/dev)r r r r r r r r Údevice_pathL s zContext.device_pathc C s t | jdƒrt| j | ¡ƒS dS )z
The run runtime directory path defaulting to ``/run`` as unicode
string.
.. udevversion:: 167
.. versionadded:: 0.10
Úudev_get_run_pathz /run/udev)r r r r r r r r Úrun_pathU s
zContext.run_pathc C s | j | ¡S )a
The logging priority of the interal logging facitility of udev as
integer with a standard :mod:`syslog` priority. Assign to this
property to change the logging priority.
UDev uses the standard :mod:`syslog` priorities. Constants for these
priorities are defined in the :mod:`syslog` module in the standard
library:
>>> import syslog
>>> context = pyudev.Context()
>>> context.log_priority = syslog.LOG_DEBUG
.. versionadded:: 0.9
)r Zudev_get_log_priorityr r r r Úlog_priorityc s zContext.log_priorityc C s | j | |¡ dS )zT
Set the log priority.
:param int value: the log priority.
N)r Zudev_set_log_priority)r Úvaluer r r r v s c K s t | ƒjf i |¤ŽS )a"
List all available devices.
The arguments of this method are the same as for
:meth:`Enumerator.match()`. In fact, the arguments are simply passed
straight to method :meth:`~Enumerator.match()`.
This function creates and returns an :class:`Enumerator` object,
that can be used to filter the list of devices, and eventually
retrieve :class:`Device` objects representing matching devices.
.. versionchanged:: 0.8
Accept keyword arguments now for easy matching.
)Ú
EnumeratorÚmatch)r Úkwargsr r r Úlist_devices s zContext.list_devicesN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r r Úpropertyr r r r Úsetterr% r r r r r ) s
r c @ sl e Zd ZdZdd„ Zdd„ Zdd„ Zdd d
„Zdd„ Zd
d„ Z ddd„Z
dd„ Zdd„ Zdd„ Z
dd„ ZdS )r" aÒ
A filtered iterable of devices.
To retrieve devices, simply iterate over an instance of this class.
This operation yields :class:`Device` objects representing the available
devices.
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')
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 :mod:`ctypes`.
c C s2 t |tƒstdƒ‚|| _|j |¡| _|j| _dS )zú
Create a new enumerator with the given ``context`` (a
:class:`Context` instance).
While you can create objects of this class directly, this is not
recommended. Call :method:`Context.list_devices()` instead.
zInvalid context objectN)Ú
isinstancer Ú TypeErrorÚcontextr Zudev_enumerate_newr )r r. r r r r s
zEnumerator.__init__c C s | j | ¡ d S r )r Zudev_enumerate_unrefr r r r r » s zEnumerator.__del__c K sš | dd¡}|dur| |¡ | dd¡}|dur<| |¡ | dd¡}|durZ| |¡ | dd¡}|durx| |¡ | ¡ D ]\}}| ||¡ q€| S )a2
Include devices according to the rules defined by the keyword
arguments. These keyword arguments are interpreted as follows:
- The value for the keyword argument ``subsystem`` is forwarded to
:meth:`match_subsystem()`.
- The value for the keyword argument ``sys_name`` is forwared to
:meth:`match_sys_name()`.
- The value for the keyword argument ``tag`` is forwared to
:meth:`match_tag()`.
- The value for the keyword argument ``parent`` is forwared to
:meth:`match_parent()`.
- All other keyword arguments are forwareded one by one to
:meth:`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.
.. versionadded:: 0.8
.. versionchanged:: 0.13
Add ``parent`` keyword.
Ú subsystemNÚsys_nameÚtagÚparent)ÚpopÚmatch_subsystemÚmatch_sys_nameÚ match_tagÚmatch_parentÚitemsÚmatch_property)r r$ r/ r0 r1 r2 Úpropr! r r r r# ¾ s
zEnumerator.matchFc C s&