<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<e                 @   sV   d dl jZddlmZ d dlZd dlZd dlmZm	Z	 ej
j ZG dd dejZdS )    N   )base)PopenPIPEc                   sb   e Zd ZdZedd Zdd Zdd Zdd	 Z fd
dZ	 fddZ
ejf fdd	Z  ZS )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
	----
	====
	c             C   s   dd iS )Nscript )selfr   r   #/usr/lib/python3.6/plugin_script.py_get_config_options6   s    z ScriptPlugin._get_config_optionsc             C   sF   d|_ d|_|jd d k	r<t|jd ts.t|jd |_ng |_d S )NTFr   )Z_has_static_tuningZ_has_dynamic_tuningZoptions
isinstancelistAssertionError_scripts)r	   instancer   r   r
   _instance_init<   s    zScriptPlugin._instance_initc             C   s   d S )Nr   )r	   r   r   r   r
   _instance_cleanupF   s    zScriptPlugin._instance_cleanupc       
      C   s  d}x|D  ]}t j}|j| jj  tjd|t|f  tjdtt	|j
   ytt|g| ttd|dt jj|d}|j \}}t|rtjd||d d
 f  |jrtjd||jf  d}W q ttfk
r
 }	 ztjd	||	f  d}W Y d d }	~	X qX qW |S )NTz'calling script '%s' with arguments '%s'zusing environment '%s')stdoutstderrZ	close_fdsenvZuniversal_newlinescwdzscript '%s' error output: '%s'r   z#script '%s' returned error code: %dFzscript '%s' error: %s)osenvironupdateZ
_variablesZget_envloginfostrdebugr   itemsr   r   pathdirnameZcommunicatelenerror
returncodeOSErrorIOError)
r	   scriptsZ	argumentsretr   r   procouterrer   r   r
   _call_scriptsI   s,    
zScriptPlugin._call_scriptsc                s$   t t| j| | j|jdg d S )Nstart)superr   _instance_apply_staticr-   r   )r	   r   )	__class__r   r
   r0   a   s    z#ScriptPlugin._instance_apply_staticc                st   d}t t| j|||dkr d}dg}|r4|dg7 }| j|j|dkrZtjtj|j  ntj	tj
|j  d}|S )NTFZverifyignore_missing)r/   r   _instance_verify_staticr-   r   r   r   constsZSTR_VERIFY_PROFILE_OKr#   ZSTR_VERIFY_PROFILE_FAIL)r	   r   r2   Zdevicesr(   args)r1   r   r
   r3   e   s    
z$ScriptPlugin._instance_verify_staticc                sB   dg}|t jkr|dg }| jt|j| tt| j|| d S )NstopZfull_rollback)r4   ZROLLBACK_FULLr-   reversedr   r/   r   _instance_unapply_static)r	   r   Zrollbackr5   )r1   r   r
   r8   t   s
    

z%ScriptPlugin._instance_unapply_static)__name__
__module____qualname____doc__classmethodr   r   r   r-   r0   r3   r4   ZROLLBACK_SOFTr8   __classcell__r   r   )r1   r
   r   	   s   +
r   )Ztuned.constsr4    r   Z
tuned.logsZtunedr   
subprocessr   r   Zlogsgetr   ZPluginr   r   r   r   r
   <module>   s   

