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/plugins/__pycache__/plugin_script.cpython-39.pyc
a

Y��d�@sXddlmZddlmZddlZddlZddlmZm	Z	ej
��ZGdd�dej
�ZdS)�N�)�base)�Popen�PIPEcsbeZdZdZedd��Zdd�Zdd�Zdd	�Z�fd
d�Z	�fdd
�Z
ejf�fdd�	Z
�ZS)�ScriptPluginac
	`script`::
	
	Executes an external script or binary when the profile is loaded or
	unloaded. You can choose an arbitrary executable.
	+
	IMPORTANT: The `script` plug-in is provided mainly for compatibility
	with earlier releases. Prefer other *TuneD* plug-ins if they cover
	the required functionality.
	+
	*TuneD* calls the executable with one of the following arguments:
	+
	--
	** `start` when loading the profile
	** `stop` when unloading the profile
	--
	+
	You need to correctly implement the `stop` action in your executable
	and revert all settings that you changed during the `start`
	action. Otherwise, the roll-back step after changing your *TuneD*
	profile will not work.
	+
	Bash scripts can import the [filename]`/usr/lib/tuned/functions`
	Bash library and use the functions defined there. Use these
	functions only for functionality that is not natively provided
	by *TuneD*. If a function name starts with an underscore, such as
	`_wifi_set_power_level`, consider the function private and do not
	use it in your scripts, because it might change in the future.
	+
	Specify the path to the executable using the `script` parameter in
	the plug-in configuration.
	+
	.Running a Bash script from a profile
	====
	To run a Bash script named `script.sh` that is located in the profile
	directory, use:
	
	----
	[script]
	script=${i:PROFILE_DIR}/script.sh
	----
	====
	cCsddiS)N�script�)�selfrr�?/usr/lib/python3.9/site-packages/tuned/plugins/plugin_script.py�_get_config_options6s�z ScriptPlugin._get_config_optionscCsFd|_d|_|jddur<t|jdt�s.J�|jd|_ng|_dS)NTFr)Z_has_static_tuningZ_has_dynamic_tuning�options�
isinstance�list�_scripts�r	�instancerrr
�_instance_init<szScriptPlugin._instance_initcCsdS)Nrrrrr
�_instance_cleanupFszScriptPlugin._instance_cleanupc
Csd}|D�]}tj}|�|j���t�d|t|�f�t�dtt	|�
����ztt|g|ttd|dtj
�|�d�}|��\}}t|�r�t�d||dd�f�|jr�t�d||jf�d}Wqttf�y}	z"t�d	||	f�d}WYd}	~	qd}	~	00q|S)
NTz'calling script '%s' with arguments '%s'zusing environment '%s')�stdout�stderrZ	close_fds�envZuniversal_newlines�cwdzscript '%s' error output: '%s'���z#script '%s' returned error code: %dFzscript '%s' error: %s)�os�environ�updateZ
_variablesZget_env�log�info�str�debugr�itemsrr�path�dirnameZcommunicate�len�error�
returncode�OSError�IOError)
r	ZscriptsZ	arguments�retrr�proc�out�err�errr
�
_call_scriptsIs.


�zScriptPlugin._call_scriptscs$tt|��|�|�|jdg�dS)N�start)�superr�_instance_apply_staticr-rr��	__class__rr
r0asz#ScriptPlugin._instance_apply_staticcstd}tt|��|||�dkr d}dg}|r4|dg7}|�|j|�dkrZt�tj|j�nt�	tj
|j�d}|S)NTFZverify�ignore_missing)r/r�_instance_verify_staticr-rrr�constsZSTR_VERIFY_PROFILE_OKr$ZSTR_VERIFY_PROFILE_FAIL)r	rr3Zdevicesr(�argsr1rr
r4es��
z$ScriptPlugin._instance_verify_staticcsBdg}|tjkr|dg}|�t|j�|�tt|��||�dS)N�stopZ
full_rollback)r5Z
ROLLBACK_FULLr-�reversedrr/r�_instance_unapply_static)r	rZrollbackr6r1rr
r9ts


z%ScriptPlugin._instance_unapply_static)�__name__�
__module__�__qualname__�__doc__�classmethodrrrr-r0r4r5Z
ROLLBACK_SOFTr9�
__classcell__rrr1r
r	s,

r)Ztuned.constsr5�rZ
tuned.logsZtunedr�
subprocessrrZlogs�getrZPluginrrrrr
�<module>s