Your IP : 3.145.69.185


Current Path : /usr/lib/python3.6/site-packages/tuned/utils/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/utils/__pycache__/profile_recommender.cpython-36.pyc

3

�<�e3�	@s�ddlZddlZddlZddlZddlZddlmZmZyddlZ	dZ
WndZ
YnXddljZddl
ZddlmZejj�ZGdd�d�ZdS)�N)�ConfigParser�ErrorTF)�commandsc@s0eZdZddd�Zdd�Zd
dd�Zd	d
�ZdS)�ProfileRecommenderFcCs||_t�|_d|_dS)N)�
_is_hardcodedr�	_commands�
_chassis_type)�selfZis_hardcoded�r
�)/usr/lib/python3.6/profile_recommender.py�__init__szProfileRecommender.__init__c
Cstj}|jr|Stj�dk}|s*tjd�|jtj|d�}|dk	rF|Si}x�tj	D]|}g}ytj
|�}Wn@tk
r�}z$|jtj
kr�tjd||f�WYdd}~XnXx"|D]}tjj||�}	|	||<q�WqRWx6t|j��D]&}||}	|j|	|d�}|dk	r�|Sq�W|S)NrztProfile recommender is running without root privileges. Profiles with virt recommendation condition will be omitted.)�has_rootzerror accessing %s: %s)�constsZDEFAULT_PROFILEr�os�geteuid�logZwarning�process_configZRECOMMEND_CONF_FILEZRECOMMEND_DIRECTORIES�listdir�OSError�errno�ENOENT�error�path�join�sorted�keys)
r	Zprofiler
Zmatching�filesZ	directory�contents�e�namerr
r
r�	recommends6
$
zProfileRecommender.recommendTc!Cs�d}d}�y�tjj|�sdStdddd�}t|_t|��}|j||�WdQRX�x:|j�D�],}d}�x|j	|�D�]�}	|j
||	dd�}
|
dkr�d}
|	d	kr�|s�d}Ptj|
|j
jd
g�dtj�s�d}qt|	dk�r�tj|
|j
jtjdd
�tj��sjd}qt|	ddk�r<tjj|	��s6tj|
|j
j|	�tj��rjd}qt|	dd�dk�r~tj�}|j�t|jtj|
���dk�rjd}qt|	dk�r�|j�}tj|
|tj��sjd}qt|	dkrtd}
t�r:tjjtjjdd�}y|j�|j d}
WnRt!t"t#fk
�r6}z.t$|d��r&|j%t%j&k�r&t'j(d|�WYdd}~XnXn|�sRt'j(d|�d}tj|
|
tj�dkrtd}qtW|r\tjd�}|j)d|�}Pq\WWn<t!t"t*fk
�r�}zt'j(d||f�WYdd}~XnX|S)NF�=�#)Z
delimitersZinline_comment_prefixes�strictT)�raw�z^$Zvirtz	virt-what��system)Zno_errorr�/�Zprocess�chassis_typeZsyspurpose_role)Zraise_on_error�rolerz/Failed to load the syspurpose										file: %sz\Failed to process 'syspurpose_role' in '%s'									, the syspurpose module is not availablez,[^,]*$zerror processing '%s', %s)+rr�isfiler�strZoptionxform�openZ	read_fileZsectionsZoptions�get�re�matchrZexecute�SrZSYSTEM_RELEASE_FILE�exists�procfsZpidstatsZreload_threads�lenZ
find_by_regex�compile�_get_chassis_type�
IGNORECASE�have_syspurpose�
syspurposerZSyspurposeStoreZUSER_SYSPURPOSEr�IOErrorr�KeyError�hasattrrrrr�subr)r	Zfnamer
Zmatching_profileZsyspurpose_error_logged�config�fZsectionr1Zoption�valueZpsr*r+�sr�rr
r
rr9s�





$z!ProfileRecommender.process_configc%Cs�|jdk	r tjd|j�|jSdddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&g%}y0td'd(��}t|j��}WdQRX|||_WnTtk
r�tjd)|�Yn4tt	fk
r�}ztj
d*|�WYdd}~XnX|j�rtjd+|j�|jSyXtjd,d-d.gtj
tj
d/d0�}|j�\}}|j�rZtjd1|j|f�n|j�j�|_Wn6tt	fk
�r�}ztj
d2|�WYdd}~XnX|j�s�tjd3�d|_ntjd+|j�|jS)4Nz"returning cached chassis type '%s'r%ZOtherZUnknownZDesktopzLow Profile Desktopz	Pizza Boxz
Mini TowerZTowerZPortableZLaptopZNotebookz	Hand HeldzDocking Stationz
All In OnezSub NotebookzSpace-savingz	Lunch BoxzMain Server ChassiszExpansion ChassiszSub ChassiszBus Expansion ChassiszPeripheral ChassiszRAID ChassiszRack Mount ChassiszSealed-case PCzMulti-systemZ
CompactPCIZAdvancedTCAZBladezBlade EnclosingZTabletZConvertibleZ
DetachablezIoT GatewayzEmbedded PCzMini PCzStick PCz(/sys/devices/virtual/dmi/id/chassis_typerCz/Unknown chassis type id read from dmi sysfs: %dz"error accessing dmi sysfs file: %szchassis type - %sZ	dmidecodez-szchassis-typeT)�stdout�stderrZ	close_fdsz,dmidecode finished with error (ret %d): '%s'z#error executing dmidecode tool : %sz!could not determine chassis type.)rr�debugr.�int�read�
IndexErrorrrr;�warn�
subprocess�Popen�PIPEZcommunicate�
returncode�strip�decode)r	ZDMI_CHASSIS_TYPESZsysfs_chassis_typeZchassis_type_idrZp_dmiZ
dmi_outputZ	dmi_errorr
r
rr7�sF


  
z$ProfileRecommender._get_chassis_typeN)F)T)�__name__�
__module__�__qualname__rr rr7r
r
r
rrs

Ir)rr0rr4rKZtuned.utils.config_parserrrZsyspurpose.filesr:r9Ztuned.constsrZ
tuned.logsZtunedZtuned.utils.commandsrZlogsr/rrr
r
r
r�<module>s




?>