관리-도구
편집 파일: inventory.cpython-39.opt-1.pyc
a ,�g� � @ sP d dl Z d dlZd dlmZ dgZej�� ZG dd� de�Z G dd� de�Z dS )� N)�consts� Inventoryc @ s\ e Zd ZdZddd�Zdd� Zdd � Zd d� Zdd � Zdd� Z dd� Z dd� Zddd�ZdS )r z� Inventory object can handle information about available hardware devices. It also informs the plugins about related hardware events. NTc C s� |d ur|| _ n t�� | _ |d u r(tj}|�| j �| _|d u rDtj}|rvz| j�|� W n t yt t �d� Y n0 |d u r�t� }|| _ d | _i | _d S )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�pyudevZContextZMonitorZfrom_netlink� _udev_monitorr ZCFG_DEF_UDEV_BUFFER_SIZE�set_receive_buffer_size�EnvironmentError�logZwarning�_MonitorObserverFactory�_monitor_observer_factory�_monitor_observer�_subscriptions)�selfZudev_contextZudev_monitor_clsZmonitor_observer_factoryZbuffer_sizer � r �</usr/lib/python3.9/site-packages/tuned/hardware/inventory.py�__init__ s$ zInventory.__init__c C s| z4zt j�| j||�}W n t jy0 d}Y n0 W nB tyv zt j�| j||�}W n t jyp d}Y n0 Y n0 |S )z9Get a pyudev.Device object for the sys_name (e.g. 'sda').N)r ZDevices� from_namer ZDeviceNotFoundByNameError�AttributeErrorZDevice)r � subsystemZsys_name�dr r r � get_device) s zInventory.get_devicec C s | j j|d�S )z)Get list of devices on a given subsystem.)r )r Zlist_devices)r r r r r �get_devices8 s zInventory.get_devicesc C s� |j | jvrd S tj}|jsJ|dkrJt�d|tjf � t� tj� d}q|js^t� d| � | j|j D ]T\}}z|||� W qj ty� } z$t�d| � t� |� W Y d }~qjd }~0 0 qjd S )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 Z!HOTPLUG_WAIT_FOR_DEV_INIT_RETRIESZis_initializedr �debugZHOTPLUG_WAIT_FOR_DEV_INIT_DELAY�time�sleep�warn� Exception�error� exception)r ZeventZdeviceZretry�plugin�callback�er r r �_handle_udev_event<