← Back
Editing: inventory.cpython-312.pyc
� �]�i� � � � d dl Z d dlZd dlmZ dgZej j � Z G d� de� Z G d� de� Z y)� N)�consts� Inventoryc �J � e Zd ZdZdd�Zd� Zd� Zd� Zd� Zd� Z d � Z d � Zd d�Zy)r z� Inventory object can handle information about available hardware devices. It also informs the plugins about related hardware events. Nc � � |�|| _ nt j � | _ |�t j }|j | j � | _ |�t j }|r | j j |� |� t � }|| _ d | _ i | _ y # t $ r t j d� Y �Bw xY w)Nz�cannot set udev monitor receive buffer size, we are probably running inside container or with limited capabilites, TuneD functionality may be limited)� _udev_context�pyudev�Context�Monitor�from_netlink� _udev_monitorr �CFG_DEF_UDEV_BUFFER_SIZE�set_receive_buffer_size�EnvironmentError�log�warning�_MonitorObserverFactory�_monitor_observer_factory�_monitor_observer�_subscriptions)�self�udev_context�udev_monitor_cls�monitor_observer_factory�buffer_sizer s �=/usr/lib/python3.12/site-packages/tuned/hardware/inventory.py�__init__zInventory.__init__ s� � ���$�4�����(�4�����n�n��'�4�4�T�5G�5G�H�$�����0�0�;��S����.�.�{�;� �%�5�7��#;�$� ��$���$��� � S��K�K� R� S�S�s �+B( �(C �C c �J � t j j | j ||� }|S # t j $ r d}Y |S w xY w# t $ rM t j j | j ||� }Y |S # t j $ r d}Y Y |S w xY ww xY w)z9Get a pyudev.Device object for the sys_name (e.g. 'sda').N)r �Devices� from_namer �DeviceNotFoundByNameError�AttributeError�Device)r � subsystem�sys_name�ds r � get_devicezInventory.get_device) s� � � � ���� � ��!3�!3�Y��I�A� �(�� � *� *� ��A� �(� �� � � �� � ���� 2� 2�I�x�H�A� �(�� � *� *� ��A� �(� �� �s? �+0 �A �A �A � A � B"�+B�B�B"�B�B"c �: � | j j |�� S )z)Get list of devices on a given subsystem.)r# )r �list_devices)r r# s r �get_deviceszInventory.get_devices8 s � � � � � (� (�9� (� =�=� c �Z � |j | j vry t j }|j sd|dkD r_t j d|t j fz � t j t j � d}|j s|dkD r�_|j st j d|z � | j |j D ] \ }} |||� � y # t $ r7}t j d|z � t j |� Y d }~�Nd }~ww xY w)Nr zLDevice '%s' is uninitialized, waiting '%.2f' seconds for its initialization.���zoUnsuccessfully waited for device '%s' initialization, continuing with uninitialized device, problems may occur.z+Exception occured in event handler of '%s'.)r# r r �!HOTPLUG_WAIT_FOR_DEV_INIT_RETRIES�is_initializedr �debug�HOTPLUG_WAIT_FOR_DEV_INIT_DELAY�time�sleep�warn� Exception�error� exception)r �event�device�retry�plugin�callback�es r �_handle_udev_eventzInventory._handle_udev_event<