o
    _                     @   sP   d dl mZ d dlT ddlZddlmZ ddlZej	 Z
G dd dejZdS )   )base)*    N)commandsc                   @   sj   e Zd ZdZdd Zdd Zedd Zdd	 Zd
d Z	dd Z
eddddd ZeddddZdS )	USBPluginz7
	Plugin for tuning various options of USB subsystem.
	c                 C   sJ   d| _ t | _t | _| jdddD ]	}| j|j qt	 | _
d S )NTusbDEVTYPE
usb_device)_devices_supportedset_free_devices_assigned_devices_hardware_inventoryget_devicesmatch_propertyaddsys_namer   _cmdselfdevice r   :/usr/lib/python3/dist-packages/tuned/plugins/plugin_usb.py_init_devices   s   zUSBPlugin._init_devicesc                    s    fdd|D S )Nc                    s   g | ]	} j d |qS )r   )r   
get_device).0xr   r   r   
<listcomp>   s    z1USBPlugin._get_device_objects.<locals>.<listcomp>r   )r   devicesr   r   r   _get_device_objects   s   zUSBPlugin._get_device_objectsc                 C   s   dd iS )Nautosuspendr   r   r   r   r   _get_config_options   s   zUSBPlugin._get_config_optionsc                 C   s   d|_ d|_d S )NTF)_has_static_tuning_has_dynamic_tuningr   instancer   r   r   _instance_init!   s   
zUSBPlugin._instance_initc                 C   s   d S )Nr   r%   r   r   r   _instance_cleanup%   s   zUSBPlugin._instance_cleanupc                 C   s   d| S )Nz)/sys/bus/usb/devices/%s/power/autosuspendr   r   r   r   r   _autosuspend_sysfile(   s   zUSBPlugin._autosuspend_sysfiler!   T)
per_devicec                 C   sB   |  |}|d u rd S |rdnd}|s| |}| j|| |S )N10)_option_boolr)   r   write_to_file)r   valuer   simenablevalsys_filer   r   r   _set_autosuspend+   s   

zUSBPlugin._set_autosuspendFc                 C   s   |  |}| jj||d S )N)no_error)r)   r   	read_filestrip)r   r   ignore_missingr3   r   r   r   _get_autosuspend7   s   
zUSBPlugin._get_autosuspendN)F)__name__
__module____qualname____doc__r   r    classmethodr"   r'   r(   r)   command_setr4   command_getr9   r   r   r   r   r   	   s    



r   ) r   
decorators
tuned.logstunedtuned.utils.commandsr   globlogsgetlogPluginr   r   r   r   r   <module>   s    
