HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3.9/site-packages/tuned/admin/__pycache__/admin.cpython-39.pyc
a

Y��d�9�@s�ddlmZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZddlZddlZddlZddlZddlZddlZGd	d
�d
e�ZdS)�)�print_functionN)�commands)�Locator�)�TunedAdminDBusException)�TunedException)�ProfileRecommenderc@sxeZdZdddejejfdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdZd d!�Zd[d"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Z d8d9�Z!d:d;�Z"d<d=�Z#d>d?�Z$d@dA�Z%dBdC�Z&dDdE�Z'dFdG�Z(dHdI�Z)dJdK�Z*dLdM�Z+dNdO�Z,d\dQdR�Z-d]dSdT�Z.d^dUdV�Z/d_dWdX�Z0dYS)`�AdminTFc
Cs�||_||_||_||_t|�|_ttj�|_	t
��|_d|_
d|_d|_d|_d|_||_t�|_|jr�tj�tjtjtj|�|_z|j�tj|j�Wn4ty�}z|�|�d|_WYd}~n
d}~00dS)N�TF) �_dbusZ_debug�_async�_timeoutr�_cmd�profiles_locator�constsZLOAD_DIRECTORIES�_profiles_locator�	threading�Event�_daemon_action_finished�_daemon_action_profile�_daemon_action_result�_daemon_action_errstr�_controller�
_log_token�
_log_levelr�_profile_recommender�tunedZadminZDBusControllerZDBUS_BUSZDBUS_INTERFACEZDBUS_OBJECTZset_signal_handlerZSIGNAL_PROFILE_CHANGED�_signal_profile_changed_cbr�_error)�selfZdbus�debugZasynco�timeoutZ	log_level�e�r#�5/usr/lib/python3.9/site-packages/tuned/admin/admin.py�__init__s*


zAdmin.__init__cCst|tjd�dS)N)�file)�print�sys�stderr)r�messager#r#r$r+szAdmin._errorcCs*|j��s&||_||_||_|j��dS�N)r�is_setrrr�set)r�profile_name�resultZerrstrr#r#r$r.s

z Admin._signal_profile_changed_cbc
Cs|zt�t|j�tj��d�WnXtyN}z|jtj	kWYd}~Sd}~0t
tfyv}zWYd}~dSd}~00dS)NrFT)�os�kill�intrZ	read_filerZPID_FILE�OSError�errno�EPERM�
ValueError�IOError)rr"r#r#r$�_tuned_is_running6s zAdmin._tuned_is_runningc
OsP|dus|dkrdSd}d}d}zt|d|�}Wn*ty\}zd|_WYd}~n
d}~00zt|d|�}WnNty�}z6|js�|�t|�d|�WYd}~dSWYd}~n
d}~00|j�r6z6|j�|j�|jj|g|�Ri|��|j�	�}Wn6t
�y4}z|�|�d|_WYd}~n
d}~00|j�sL||i|��}|S)Nr
FZ
_action_dbus_Z_action_z , action '%s' is not implemented)�getattr�AttributeErrorrr�strrZset_on_exit_action�_log_capture_finish�
set_action�runr)r�action_name�args�kwargs�actionZaction_dbus�resr"r#r#r$rB@s8$�
zAdmin.actionc	Csdtd�|D]R}|ddurN|ddkrNt|j�d|ddd|d��qtd|d�qdS)NzAvailable profiles:rr
z- %sr�)r'rZ	align_str)r�
profile_names�profiler#r#r$�_print_profiles^s
&zAdmin._print_profilesc
Csfz|j��}Wn8tyF}z dd�|j��D�}WYd}~n
d}~00|�|�|��|j�d�S)NcSsg|]}|df�qS)r
r#)�.0rFr#r#r$�
<listcomp>k�z4Admin._action_dbus_list_profiles.<locals>.<listcomp>T)rZ	profiles2r�profilesrG�_action_dbus_active�exit)rrEr"r#r#r$�_action_dbus_list_profilesfs*
z Admin._action_dbus_list_profilescCs|�|j���|��dS�NT)rGrZget_known_names_summary�_action_active�rr#r#r$�_action_list_profilespszAdmin._action_list_profilescCs&|j��}|dkrd}|j�d�|S)Nr
T)r�active_profilerM�rr.r#r#r$�_dbus_get_active_profileus

zAdmin._dbus_get_active_profilecCs|j��\}}|Sr+)r�get_active_profile)rr.�manualr#r#r$�_get_active_profile|szAdmin._get_active_profilecCs.|j��\}}|dur|du}|r(tjStjSr+)rrVrZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rrFrWr#r#r$�_get_profile_mode�szAdmin._get_profile_modecCs|j��}|dkrd}|S)Nr
)r�post_loaded_profilerTr#r#r$�_dbus_get_post_loaded_profile�s
z#Admin._dbus_get_post_loaded_profilecCs|j��}|Sr+)rZget_post_loaded_profilerTr#r#r$�_get_post_loaded_profile�s
zAdmin._get_post_loaded_profilecCsl|ddkrXtd�t|d�t�td�t|d�t�td�t|d�dStd	|�d
SdS)NrTz
Profile name:rzProfile summary:�zProfile description:�z,Unable to get information about profile '%s'F�r')rrF�profile_infor#r#r$�_print_profile_info�szAdmin._print_profile_infor
cCsB|dkr|��}|r*|�||j�|��}ntd�d}|j�|�S�Nr
�No current active profile.F)rUrarr`r'rM)rrFrCr#r#r$�_action_dbus_profile_info�szAdmin._action_dbus_profile_infoc
Cs�|dkr`z"|��}|dur(td�WdSWn4ty^}z|�t|��WYd}~dSd}~00|�||j�|tj	tj
gddg��Srb)rXr'rrr;rarZget_profile_attrsrZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTION)rrFr"r#r#r$�_action_profile_info�s
zAdmin._action_profile_infocCs$|durtd�dStd|�dS)NrcFzCurrent active profile: %sTr_rTr#r#r$�_print_profile_name�s
zAdmin._print_profile_namecCs|rtd|�dS)NzCurrent post-loaded profile: %sr_rTr#r#r$�_print_post_loaded_profile�sz Admin._print_post_loaded_profilecCs4|��}|�|�}|r(|��}|�|�|j�|�Sr+)rUrfr[rgrrM)rrSrCrZr#r#r$rL�s

zAdmin._action_dbus_activec
Cs�z2|��}|��}|r0|r$|d7}nd}||7}Wn4tyf}z|�t|��WYd}~dSd}~00|dur�|��s�td�td|�|r�td|�dS|�|�}|�|�|S)N� r
FzKIt seems that tuned daemon is not running, preset profile is not activated.zPreset profile: %szPreset post-loaded profile: %sT)	rXr\rrr;r8r'rfrg)rr.rZr"rCr#r#r$rP�s(


zAdmin._action_activecCstd|�dS)NzProfile selection mode: r_)r�moder#r#r$�_print_profile_mode�szAdmin._print_profile_modecCsB|j��\}}|�|�|dkr6|�|�|j�d�S|j�d�S)Nr
FT)rZprofile_moderjrrM)rri�errorr#r#r$�_action_dbus_profile_mode�s

zAdmin._action_dbus_profile_modec
CsRz|��}|�|�WdStyL}z|�t|��WYd}~dSd}~00dS)NTF)rYrjrrr;)rrir"r#r#r$�_action_profile_mode�s
zAdmin._action_profile_modecCs:|r(|j��s6|j��s6|�d�d}n|�d|�|S)NzCannot enable the tuning.FzUnable to switch profile: %s)rZ
is_running�startr�r�ret�msgr#r#r$�_profile_print_status�s
zAdmin._profile_print_statuscCsrt��|j|jkr.td|j�|j�d�S|j��rn|j|krn|j	sbtd|j
�|j�d�S|j�d�SdS)Nz�Operation timed out after waiting %d seconds(s), you may try to increase timeout by using --timeout command line option or using --async.FzError changing profile: %sT)�time�
_timestampr
r'rrMr�isSetrrrrTr#r#r$�_action_dbus_wait_profile�s

zAdmin._action_dbus_wait_profilec
Cs~|jdus|jdkrdSz2|j�|j�}d|_t|dtjd�tj��Wn.tyx}z|�d�WYd}~n
d}~00dS)Nr
)�endr&zUError: Failed to stop log capture. Restart the TuneD daemon to prevent a memory leak.)	rrZlog_capture_finishr'r(r)�flushrr)rZlog_msgsr"r#r#r$r<s�zAdmin._log_capture_finishcCs�t|�dkr|��Sd�|�}|dkr2|j�d�S|j��|jsl|jdurl|j	dd}|j�
|j|�|_|j�|�\}}|js�|s�|j�|�
||��St��|_|j�|j|�|�
||�S)Nrrhr
F��)�len�_action_dbus_list�joinrrMr�clearrrr
�log_capture_startrZswitch_profilerrrsrtr=rv)rrKr.r!rprqr#r#r$�_action_dbus_profiles"

�

zAdmin._action_dbus_profilecCs:td�|j�gd��\}}|dkr.td�ntd�dS)NzTrying to (re)start tuned...)ZservicerZrestartrz#TuneD (re)started, changes applied.zQTuneD (re)start failed, you need to (re)start TuneD by hand for changes to apply.)r'rZexecuteror#r#r$�_restart_tuned+s

zAdmin._restart_tunedc
Cs�||j��vrlz|j�||�|��WdStyh}z&|�t|��|�d�WYd}~dSd}~00n|�d|�dSdS)NTzUnable to switch profile.Fz%Requested profile '%s' doesn't exist.)rZget_known_namesrZsave_active_profiler�rrr;)rr.rWr"r#r#r$�_set_profile3s
zAdmin._set_profilecCs6t|�dkr|��Sd�|�}|dkr*dS|�|d�S)Nrrhr
FT)r{rRr}r�)rrKr.r#r#r$�_action_profileAs
zAdmin._action_profilecCs�|j��}|j��|jsD|jdurD|jdd}|j�|j|�|_|j�	�\}}|js\|sp|j�
|�||��St��|_
|j�|j|�|�||�S)Nryrz)r�recommend_profilerr~rrr
rrZauto_profilerMrrrsrtr=rv)rr.r!rprqr#r#r$�_action_dbus_auto_profileIs

�

zAdmin._action_dbus_auto_profilecCs|j��}|�|d�S)NF)r�	recommendr�rTr#r#r$�_action_auto_profileYs
zAdmin._action_auto_profilecCst|j���|j�d�SrO)r'rr�rMrQr#r#r$�_action_dbus_recommend_profile]sz$Admin._action_dbus_recommend_profilecCst|j���dSrO)r'rr�rQr#r#r$�_action_recommend_profileaszAdmin._action_recommend_profilecCsr|r|j��}n
|j��}|r(td�n0td�td�td�td�td�td�tdtj�|j�|�S)	NzIVerification succeeded, current system settings match the preset profile.zLVerification failed, current system settings differ from the preset profile.z=You can mostly fix this by restarting the TuneD daemon, e.g.:z  systemctl restart tuned�orz  service tuned restartzNSometimes (if some plugins like bootloader are used) a reboot may be required.z&See TuneD log file ('%s') for details.)rZverify_profile_ignore_missingZverify_profiler'rZLOG_FILErM)r�ignore_missingrpr#r#r$�_action_dbus_verify_profilees

z!Admin._action_dbus_verify_profilecCstd�dS�Nz Not supported in no_daemon mode.Fr_)rr�r#r#r$�_action_verify_profilevszAdmin._action_verify_profilecCs:d}|j�|j|�|_|j��}|s.|�d�|j�|�S)NrDzCannot disable active profile.)rrrrZoffrrM)rr!rpr#r#r$�_action_dbus_offzs�

zAdmin._action_dbus_offcCstd�dSr�r_rQr#r#r$�_action_off�szAdmin._action_offrKcCs(|dkr|��S|dkr$|j|d�SdS)aDPrint accessible profiles or plugins got from TuneD dbus api

		Keyword arguments:
		list_choice -- argument from command line deciding what will be listed
		verbose -- if True then list plugin's config options and their hints
			if possible. Functional only with plugin listing, with profiles
			this argument is omitted
		rK�plugins��verboseN)rN�_action_dbus_list_plugins�rZlist_choicer�r#r#r$r|�s	zAdmin._action_dbus_listcCs(|dkr|��S|dkr$|j|d�SdS)aaPrint accessible profiles or plugins with no daemon mode

		Keyword arguments:
		list_choice -- argument from command line deciding what will be listed
		verbose -- Plugins cannot be listed in this mode, so verbose argument
			is here only because argparse module always supplies verbose
			option and if verbose was not here it would result in error
		rKr�r�N)rR�_action_list_pluginsr�r#r#r$�_action_list�s	zAdmin._action_listcCs�|j��}|��D]d}t|�|rt||�dkr4q|j�|�}||D],}td|�|�|d�}|rHtd|�qHq|j�d�S)zvPrint accessible plugins

		Keyword arguments:
		verbose -- if is set to True then parameters and hints are printed
		rz	%sNz		%sT)rZget_plugins�keysr'r{Zget_plugin_hints�getrM)rr�r�Zplugin�hintsZ	parameter�hintr#r#r$r��s
zAdmin._action_dbus_list_pluginscCstd�dSr�r_)rr�r#r#r$r��szAdmin._action_list_pluginsN)r
)r
)rKF)rKF)F)F)1�__name__�
__module__�__qualname__rZ
ADMIN_TIMEOUT�loggingZERRORr%rrr8rBrGrNrRrUrXrYr[r\rardrerfrgrLrPrjrlrmrrrvr<r�r�r�r�r�r�r�r�r�r�r�r�r|r�r�r�r#r#r#r$r	sZ�





		



r	)Z
__future__rZtuned.adminrZtuned.utils.commandsrZtuned.profilesrr�
exceptionsrZtuned.exceptionsrZtuned.constsrZtuned.utils.profile_recommenderrr0r(r4rsrr��objectr	r#r#r#r$�<module>s