Current File : /home/mmdealscpanel/yummmdeals.com/admin.zip
PK#v[�L|NN__init__.pynu�[���from .admin import *
from .exceptions import *
from .dbus_controller import *
PK#v[ϐ��__
exceptions.pynu�[���import tuned.exceptions

class TunedAdminDBusException(tuned.exceptions.TunedException):
	pass
PK#v[ VsBB __pycache__/admin.cpython-36.pycnu�[���3

�<�e�>�@s�ddlmZddlZddlmZddlmZddl	m
Z
ddlmZddl
jZddlmZddlZddlZddlZddlZddlZddlZGd	d
�d
e�ZdS)�)�print_functionN)�commands)�Locator�)�TunedAdminDBusException)�TunedException)�ProfileRecommenderc@s�eZdZdddejejfdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdfd d!�Zdgd"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,dhdQdR�Z-didSdT�Z.djdUdV�Z/dkdWdX�Z0dYdZ�Z1d[d\�Z2d]d^�Z3d_d`�Z4dadb�Z5dcdd�Z6deS)l�AdminTFcCs�||_||_||_||_t|�|_ttj�|_	t
j�|_d|_
d|_d|_d|_d|_||_t�|_|jr�tjjtjtjtj|�|_y|jjtj|j�Wn2tk
r�}z|j|�d|_WYdd}~XnXdS)N�TF) �_dbusZ_debug�_async�_timeoutr�_cmd�profiles_locator�constsZLOAD_DIRECTORIES�_profiles_locator�	threadingZEvent�_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"�/usr/lib/python3.6/admin.py�__init__s*


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

z Admin._signal_profile_changed_cbcCsnytjt|jjtj��d�WnJtk
rF}z|jtj	kSd}~Xn$t
tfk
rh}zdSd}~XnXdS)NrFT)�os�kill�intrZ	read_filerZPID_FILE�OSError�errnoZEPERM�
ValueError�IOError)rr!r"r"r#�_tuned_is_running6szAdmin._tuned_is_runningc-Os6|dks|dkrdSd}d}d}yt|d|�}Wn(tk
rZ}zd|_WYdd}~XnXyt|d|�}WnBtk
r�}z&|js�|jt|�d|�dSWYdd}~XnX|j�r y0|jj|j�|jj|f|�|�|jj	�}Wn4t
k
�r}z|j|�d|_WYdd}~XnX|j�s2|||�}|S)Nr
FZ
_action_dbus_Z_action_z , action '%s' is not implemented)�getattr�AttributeErrorrr�strrZset_on_exit_action�_log_capture_finish�
set_actionZrunr)rZaction_name�args�kwargs�actionZaction_dbus�resr!r"r"r#r<@s6

zAdmin.actioncCshtd�xZ|D]R}|ddk	rP|ddkrPt|jjd|ddd|d��qtd|d�qWdS)NzAvailable profiles:rr
z- %sr�)r&rZ	align_str)r�
profile_names�profiler"r"r#�_print_profiles^s

&zAdmin._print_profilescCsdy|jj�}Wn6tk
rD}zdd�|jj�D�}WYdd}~XnX|j|�|j�|jjd�S)NcSsg|]}|df�qS)r
r")�.0r@r"r"r#�
<listcomp>ksz4Admin._action_dbus_list_profiles.<locals>.<listcomp>T)rZ	profiles2r�profilesrA�_action_dbus_active�exit)rr?r!r"r"r#�_action_dbus_list_profilesfs&
z Admin._action_dbus_list_profilescCs|j|jj��|j�dS)NT)rArZget_known_names_summary�_action_active)rr"r"r#�_action_list_profilespszAdmin._action_list_profilescCs&|jj�}|dkrd}|jjd�|S)Nr
T)r�active_profilerF)rr+r"r"r#�_dbus_get_active_profileus

zAdmin._dbus_get_active_profilecCs|jj�\}}|S)N)r�get_active_profile)rr+�manualr"r"r#�_get_active_profile|szAdmin._get_active_profilecCs.|jj�\}}|dkr|dk	}|r(tjStjS)N)rrLrZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rr@rMr"r"r#�_get_profile_mode�szAdmin._get_profile_modecCs|jj�}|dkrd}|S)Nr
)r�post_loaded_profile)rr+r"r"r#�_dbus_get_post_loaded_profile�s
z#Admin._dbus_get_post_loaded_profilecCs|jj�}|S)N)rZget_post_loaded_profile)rr+r"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&)rr@�profile_infor"r"r#�_print_profile_info�szAdmin._print_profile_infor
cCsB|dkr|j�}|r*|j||jj|��}ntd�d}|jj|�S)Nr
zNo current active profile.F)rKrVrrUr&rF)rr@r=r"r"r#�_action_dbus_profile_info�szAdmin._action_dbus_profile_infocCs||dkrXy |j�}|dkr&td�dSWn.tk
rV}z|jt|��dSd}~XnX|j||jj|tj	tj
gddg��S)Nr
zNo current active profile.F)rNr&rrr7rVrZget_profile_attrsrZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTION)rr@r!r"r"r#�_action_profile_info�szAdmin._action_profile_infocCs$|dkrtd�dStd|�dS)NzNo current active profile.FzCurrent active profile: %sT)r&)rr+r"r"r#�_print_profile_name�s
zAdmin._print_profile_namecCs|rtd|�dS)NzCurrent post-loaded profile: %s)r&)rr+r"r"r#�_print_post_loaded_profile�sz Admin._print_post_loaded_profilecCs4|j�}|j|�}|r(|j�}|j|�|jj|�S)N)rKrYrQrZrrF)rrJr=rPr"r"r#rE�s

zAdmin._action_dbus_activecCs�y2|j�}|j�}|r0|r$|d7}nd}||7}Wn.tk
r`}z|jt|��dSd}~XnX|dk	r�|j�r�td�td|�|r�td|�dS|j|�}|j|�|S)N� r
FzKIt seems that tuned daemon is not running, preset profile is not activated.zPreset profile: %szPreset post-loaded profile: %sT)	rNrRrrr7r4r&rYrZ)rr+rPr!r=r"r"r#rH�s(


zAdmin._action_activecCstd|�dS)NzProfile selection mode: )r&)r�moder"r"r#�_print_profile_mode�szAdmin._print_profile_modecCsB|jj�\}}|j|�|dkr6|j|�|jjd�S|jjd�S)Nr
FT)rZprofile_moder]rrF)rr\�errorr"r"r#�_action_dbus_profile_mode�s

zAdmin._action_dbus_profile_modecCsJy|j�}|j|�dStk
rD}z|jt|��dSd}~XnXdS)NTF)rOr]rrr7)rr\r!r"r"r#�_action_profile_mode�s
zAdmin._action_profile_modecCs>|r,|jj�r:|jj�r:|jd�d}n|jd|�|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_statuscCsrtj�|j|jkr.td|j�|jjd�S|jj�rn|j|krn|j	sbtd|j
�|jjd�S|jjd�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&rrFrZisSetrrr)rr+r"r"r#�_action_dbus_wait_profile�s

zAdmin._action_dbus_wait_profilecCs||jdks|jdkrdSy2|jj|j�}d|_t|dtjd�tjj�Wn,tk
rv}z|jd�WYdd}~XnXdS)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#r8szAdmin._log_capture_finishcCs�t|�dkr|j�Sdj|�}|dkr2|jjd�S|jj�|jrn|jdk	rn|j	dd}|jj
|j|�|_|jj|�\}}|js�|r�|jj|j
||��Stj�|_|jj|j|�|j
||�S)Nrr[r
F��)�len�_action_dbus_list�joinrrFr�clearrrr
�log_capture_startrZswitch_profilerdrerfr9rg)rrDr+r rbrcr"r"r#�_action_dbus_profiles 


zAdmin._action_dbus_profilecCs<td�|jjdddg�\}}|dkr0td�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&rZexecute)rrbrcr"r"r#�_restart_tuned+s

zAdmin._restart_tunedcCsz||jj�krdy|jj||�|j�dStk
r`}z|jt|��|jd�dSd}~XqvXn|jd|�dSdS)NTzUnable to switch profile.Fz%Requested profile '%s' doesn't exist.)rZget_known_namesrZsave_active_profilerrrrr7)rr+rMr!r"r"r#�_set_profile3s
zAdmin._set_profilecCs6t|�dkr|j�Sdj|�}|dkr*dS|j|d�S)Nrr[r
FT)rlrIrnrs)rrDr+r"r"r#�_action_profileAs
zAdmin._action_profilecCs�|jj�}|jj�|jrF|jdk	rF|jdd}|jj|j|�|_|jj	�\}}|js`|rt|jj
|j||��Stj�|_
|jj|j|�|j||�S)Nrjrk)r�recommend_profilerrorrr
rprZauto_profilerFrdrerfr9rg)rr+r rbrcr"r"r#�_action_dbus_auto_profileIs


zAdmin._action_dbus_auto_profilecCs|jj�}|j|d�S)NF)r�	recommendrs)rr+r"r"r#�_action_auto_profileYs
zAdmin._action_auto_profilecCst|jj��|jjd�S)NT)r&rrurF)rr"r"r#�_action_dbus_recommend_profile]sz$Admin._action_dbus_recommend_profilecCst|jj��dS)NT)r&rrw)rr"r"r#�_action_recommend_profileaszAdmin._action_recommend_profilecCsr|r|jj�}n
|jj�}|r(td�n0td�td�td�td�td�td�tdtj�|jj|�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_FILErF)r�ignore_missingrbr"r"r#�_action_dbus_verify_profilees

z!Admin._action_dbus_verify_profilecCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr|r"r"r#�_action_verify_profilevszAdmin._action_verify_profilecCs:d}|jj|j|�|_|jj�}|s.|jd�|jj|�S)NrjrkzCannot disable active profile.r>)rrprrZoffrrF)rr rbr"r"r#�_action_dbus_offzs

zAdmin._action_dbus_offcCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr"r"r#�_action_off�szAdmin._action_offrDcCs(|dkr|j�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
		rD�plugins)�verboseN)rG�_action_dbus_list_plugins)r�list_choicer�r"r"r#rm�s	zAdmin._action_dbus_listcCs(|dkr|j�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
		rDr�)r�N)rI�_action_list_plugins)rr�r�r"r"r#�_action_list�s	zAdmin._action_listcCs�|jj�}xv|j�D]j}t|�|st||�dkr8q|jj|�}x8||D],}td|�|j|d�}|rNtd|�qNWqW|jjd�S)zvPrint accessible plugins

		Keyword arguments:
		verbose -- if is set to True then parameters and hints are printed
		rz	%sNz		%sT)rZget_plugins�keysr&rlZget_plugin_hints�getrF)rr�r��pluginZhintsZ	parameterZhintr"r"r#r��s
zAdmin._action_dbus_list_pluginscCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r"r"r#r��szAdmin._action_list_pluginscCs0|jj||�\}}|s$|jd|�|jj|�S)NzUnable to acquire devices: %s)rZinstance_acquire_devicesrrF)r�devices�instancerbrcr"r"r#�%_action_dbus_instance_acquire_devices�sz+Admin._action_dbus_instance_acquire_devicescCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r�r"r"r#� _action_instance_acquire_devices�sz&Admin._action_instance_acquire_devicescCs^|jj|�\}}}|s0|jd|�|jjd�Sx |D]\}}td||f�q6W|jjd�S)NzUnable to list instances: %sFz%s (%s)T)rZ
get_instancesrrFr&)r�plugin_namerbrcZpairsr�r�r"r"r#�_action_dbus_get_instances�sz Admin._action_dbus_get_instancescCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r"r"r#�_action_get_instances�szAdmin._action_get_instancescCsR|jj|�\}}}|s0|jd|�|jjd�Sx|D]}t|�q6W|jjd�S)NzUnable to list devices: %sFT)rZinstance_get_devicesrrFr&)rr�rbrcr�Zdevicer"r"r#�!_action_dbus_instance_get_devices�s
z'Admin._action_dbus_instance_get_devicescCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r"r"r#�_action_instance_get_devices�sz"Admin._action_instance_get_devicesN)r
)r
)rDF)rDF)F)F)7�__name__�
__module__�__qualname__rZ
ADMIN_TIMEOUT�loggingZERRORr$rrr4r<rArGrIrKrNrOrQrRrVrWrXrYrZrErHr]r_r`rdrgr8rqrrrsrtrvrxryrzr}r~rr�rmr�r�r�r�r�r�r�r�r�r"r"r"r#r	sd




		




		r	)Z
__future__rZtuned.adminrZtuned.utils.commandsrZtuned.profilesrr�
exceptionsrZtuned.exceptionsrZtuned.constsrZtuned.utils.profile_recommenderrr-r'r1rerr��objectr	r"r"r"r#�<module>s
PK#v[ϨA�^^%__pycache__/exceptions.cpython-36.pycnu�[���3

�<�e_�@s ddlZGdd�dejj�ZdS)�Nc@seZdZdS)�TunedAdminDBusExceptionN)�__name__�
__module__�__qualname__�rr� /usr/lib/python3.6/exceptions.pyrsr)Ztuned.exceptionsZtuned�
exceptionsZTunedExceptionrrrrr�<module>sPK#v[�D��*__pycache__/dbus_controller.cpython-36.pycnu�[���3

�<�eW�@sZddlZddlZddlZddlmZddlmZmZddlm	Z	dgZ
Gdd�de�ZdS)�N)�
DBusGMainLoop)�GLib�GObject�)�TunedAdminDBusException�DBusControllerc@seZdZdCdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBS)DrFcCsL||_||_||_d|_d|_||_d|_d|_d|_d|_	d|_
d|_dS)NTF)�	_bus_name�_interface_name�_object_name�_proxy�
_interface�_debug�
_main_loop�_action�_on_exit_action�_ret�_exit�
_exception)�selfZbus_nameZinterface_nameZobject_name�debug�r�%/usr/lib/python3.6/dbus_controller.py�__init__szDBusController.__init__cCsvyP|jdkrNtdd�tj�|_tj�}|j|j|j	�|_tj
|j|jd�|_Wn tj
jk
rptd��YnXdS)NT)Zset_as_default)Zdbus_interfacez>Cannot talk to TuneD daemon via DBus. Is TuneD daemon running?)rrrZMainLoopr�dbusZ	SystemBusZ
get_objectrr
Z	Interfacer	r�
exceptions�
DBusExceptionr)rZbusrrr�_init_proxys


zDBusController._init_proxycCs�|jdk	rPy|j|j|j�|_Wn.tk
rN}z||_d|_WYdd}~XnX|jr~|jdk	rp|j|j|j	�|j
j�dStj
d�dS)NTFr)r�_action_args�_action_kwargsZ_action_exit_coderrrr�_on_exit_action_args�_on_exit_action_kwargsr�quit�timeZsleep)r�errr�_idle$s



zDBusController._idlecOs||_||_||_dS)N)rrr )r�action�args�kwargsrrr�set_on_exit_action7sz!DBusController.set_on_exit_actioncOs||_||_||_dS)N)rrr)rr%r&r'rrr�
set_action<szDBusController.set_actioncCs2d|_tj|j�|jj�|jdk	r,|j�|jS)N)rrZidle_addr$r�runr)rrrrr*As

zDBusController.runcOsp|j�y|jj|�}||ddi�Stjjk
rj}z(d}|jrR|dt|�7}t|��WYdd}~XnXdS)N�timeout�(z DBus call to TuneD daemon failedz (%s))	rrZget_dbus_methodrrrr
�strr)rZmethod_namer&r'�methodZdbus_exceptionZerr_strrrr�_callJszDBusController._callcCs|j�|jj||�dS)N)rrZconnect_to_signal)r�signal�cbrrr�set_signal_handlerVsz!DBusController.set_signal_handlercCs
|jd�S)N�
is_running)r/)rrrrr3ZszDBusController.is_runningcCs
|jd�S)N�start)r/)rrrrr4]szDBusController.startcCs
|jd�S)N�stop)r/)rrrrr5`szDBusController.stopcCs
|jd�S)N�profiles)r/)rrrrr6cszDBusController.profilescCs
|jd�S)N�	profiles2)r/)rrrrr7fszDBusController.profiles2cCs|jd|�S)N�profile_info)r/)rZprofile_namerrrr8iszDBusController.profile_infocCs|jd||�S)N�log_capture_start)r/)rZ	log_levelr+rrrr9lsz DBusController.log_capture_startcCs|jd|�S)N�log_capture_finish)r/)r�tokenrrrr:osz!DBusController.log_capture_finishcCs
|jd�S)N�active_profile)r/)rrrrr<rszDBusController.active_profilecCs
|jd�S)N�profile_mode)r/)rrrrr=uszDBusController.profile_modecCs
|jd�S)N�post_loaded_profile)r/)rrrrr>xsz"DBusController.post_loaded_profilecCs|dkrdS|jd|�S)N�F�No profile specified�switch_profile)Fr@)r/)rZnew_profilerrrrA{szDBusController.switch_profilecCs
|jd�S)N�auto_profile)r/)rrrrrB�szDBusController.auto_profilecCs
|jd�S)N�recommend_profile)r/)rrrrrC�sz DBusController.recommend_profilecCs
|jd�S)N�verify_profile)r/)rrrrrD�szDBusController.verify_profilecCs
|jd�S)N�verify_profile_ignore_missing)r/)rrrrrE�sz,DBusController.verify_profile_ignore_missingcCs
|jd�S)N�disable)r/)rrrr�off�szDBusController.offcCs
|jd�S)zzReturn dict with plugin names and their hints

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		Zget_all_plugins)r/)rrrr�get_plugins�szDBusController.get_pluginscCs|jd|�S)z"Return docstring of plugin's class�get_plugin_documentation)r/)r�plugin_namerrrrI�sz'DBusController.get_plugin_documentationcCs|jd|�S)z�Return dictionary with parameters of plugin and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		�get_plugin_hints)r/)rrJrrrrK�s	zDBusController.get_plugin_hintscCs|jd||�S)N�instance_acquire_devices)r/)rZdevices�instancerrrrL�sz'DBusController.instance_acquire_devicescCs|jd|�S)N�
get_instances)r/)rrJrrrrN�szDBusController.get_instancescCs|jd|�S)N�instance_get_devices)r/)rrMrrrrO�sz#DBusController.instance_get_devicescCs|jd�||_d|_|S)NT)r)rr)r�retrrr�exit�s
zDBusController.exitN)F)#�__name__�
__module__�__qualname__rrr$r(r)r*r/r2r3r4r5r6r7r8r9r:r<r=r>rArBrCrDrErGrHrIrKrLrNrOrQrrrrr
s@
	)
rZdbus.exceptionsr"Zdbus.mainloop.glibrZ
gi.repositoryrrrr�__all__�objectrrrrr�<module>sPK#v[ϨA�^^+__pycache__/exceptions.cpython-36.opt-1.pycnu�[���3

�<�e_�@s ddlZGdd�dejj�ZdS)�Nc@seZdZdS)�TunedAdminDBusExceptionN)�__name__�
__module__�__qualname__�rr� /usr/lib/python3.6/exceptions.pyrsr)Ztuned.exceptionsZtuned�
exceptionsZTunedExceptionrrrrr�<module>sPK#v[ VsBB&__pycache__/admin.cpython-36.opt-1.pycnu�[���3

�<�e�>�@s�ddlmZddlZddlmZddlmZddl	m
Z
ddlmZddl
jZddlmZddlZddlZddlZddlZddlZddlZGd	d
�d
e�ZdS)�)�print_functionN)�commands)�Locator�)�TunedAdminDBusException)�TunedException)�ProfileRecommenderc@s�eZdZdddejejfdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdfd d!�Zdgd"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,dhdQdR�Z-didSdT�Z.djdUdV�Z/dkdWdX�Z0dYdZ�Z1d[d\�Z2d]d^�Z3d_d`�Z4dadb�Z5dcdd�Z6deS)l�AdminTFcCs�||_||_||_||_t|�|_ttj�|_	t
j�|_d|_
d|_d|_d|_d|_||_t�|_|jr�tjjtjtjtj|�|_y|jjtj|j�Wn2tk
r�}z|j|�d|_WYdd}~XnXdS)N�TF) �_dbusZ_debug�_async�_timeoutr�_cmd�profiles_locator�constsZLOAD_DIRECTORIES�_profiles_locator�	threadingZEvent�_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"�/usr/lib/python3.6/admin.py�__init__s*


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

z Admin._signal_profile_changed_cbcCsnytjt|jjtj��d�WnJtk
rF}z|jtj	kSd}~Xn$t
tfk
rh}zdSd}~XnXdS)NrFT)�os�kill�intrZ	read_filerZPID_FILE�OSError�errnoZEPERM�
ValueError�IOError)rr!r"r"r#�_tuned_is_running6szAdmin._tuned_is_runningc-Os6|dks|dkrdSd}d}d}yt|d|�}Wn(tk
rZ}zd|_WYdd}~XnXyt|d|�}WnBtk
r�}z&|js�|jt|�d|�dSWYdd}~XnX|j�r y0|jj|j�|jj|f|�|�|jj	�}Wn4t
k
�r}z|j|�d|_WYdd}~XnX|j�s2|||�}|S)Nr
FZ
_action_dbus_Z_action_z , action '%s' is not implemented)�getattr�AttributeErrorrr�strrZset_on_exit_action�_log_capture_finish�
set_actionZrunr)rZaction_name�args�kwargs�actionZaction_dbus�resr!r"r"r#r<@s6

zAdmin.actioncCshtd�xZ|D]R}|ddk	rP|ddkrPt|jjd|ddd|d��qtd|d�qWdS)NzAvailable profiles:rr
z- %sr�)r&rZ	align_str)r�
profile_names�profiler"r"r#�_print_profiles^s

&zAdmin._print_profilescCsdy|jj�}Wn6tk
rD}zdd�|jj�D�}WYdd}~XnX|j|�|j�|jjd�S)NcSsg|]}|df�qS)r
r")�.0r@r"r"r#�
<listcomp>ksz4Admin._action_dbus_list_profiles.<locals>.<listcomp>T)rZ	profiles2r�profilesrA�_action_dbus_active�exit)rr?r!r"r"r#�_action_dbus_list_profilesfs&
z Admin._action_dbus_list_profilescCs|j|jj��|j�dS)NT)rArZget_known_names_summary�_action_active)rr"r"r#�_action_list_profilespszAdmin._action_list_profilescCs&|jj�}|dkrd}|jjd�|S)Nr
T)r�active_profilerF)rr+r"r"r#�_dbus_get_active_profileus

zAdmin._dbus_get_active_profilecCs|jj�\}}|S)N)r�get_active_profile)rr+�manualr"r"r#�_get_active_profile|szAdmin._get_active_profilecCs.|jj�\}}|dkr|dk	}|r(tjStjS)N)rrLrZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rr@rMr"r"r#�_get_profile_mode�szAdmin._get_profile_modecCs|jj�}|dkrd}|S)Nr
)r�post_loaded_profile)rr+r"r"r#�_dbus_get_post_loaded_profile�s
z#Admin._dbus_get_post_loaded_profilecCs|jj�}|S)N)rZget_post_loaded_profile)rr+r"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&)rr@�profile_infor"r"r#�_print_profile_info�szAdmin._print_profile_infor
cCsB|dkr|j�}|r*|j||jj|��}ntd�d}|jj|�S)Nr
zNo current active profile.F)rKrVrrUr&rF)rr@r=r"r"r#�_action_dbus_profile_info�szAdmin._action_dbus_profile_infocCs||dkrXy |j�}|dkr&td�dSWn.tk
rV}z|jt|��dSd}~XnX|j||jj|tj	tj
gddg��S)Nr
zNo current active profile.F)rNr&rrr7rVrZget_profile_attrsrZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTION)rr@r!r"r"r#�_action_profile_info�szAdmin._action_profile_infocCs$|dkrtd�dStd|�dS)NzNo current active profile.FzCurrent active profile: %sT)r&)rr+r"r"r#�_print_profile_name�s
zAdmin._print_profile_namecCs|rtd|�dS)NzCurrent post-loaded profile: %s)r&)rr+r"r"r#�_print_post_loaded_profile�sz Admin._print_post_loaded_profilecCs4|j�}|j|�}|r(|j�}|j|�|jj|�S)N)rKrYrQrZrrF)rrJr=rPr"r"r#rE�s

zAdmin._action_dbus_activecCs�y2|j�}|j�}|r0|r$|d7}nd}||7}Wn.tk
r`}z|jt|��dSd}~XnX|dk	r�|j�r�td�td|�|r�td|�dS|j|�}|j|�|S)N� r
FzKIt seems that tuned daemon is not running, preset profile is not activated.zPreset profile: %szPreset post-loaded profile: %sT)	rNrRrrr7r4r&rYrZ)rr+rPr!r=r"r"r#rH�s(


zAdmin._action_activecCstd|�dS)NzProfile selection mode: )r&)r�moder"r"r#�_print_profile_mode�szAdmin._print_profile_modecCsB|jj�\}}|j|�|dkr6|j|�|jjd�S|jjd�S)Nr
FT)rZprofile_moder]rrF)rr\�errorr"r"r#�_action_dbus_profile_mode�s

zAdmin._action_dbus_profile_modecCsJy|j�}|j|�dStk
rD}z|jt|��dSd}~XnXdS)NTF)rOr]rrr7)rr\r!r"r"r#�_action_profile_mode�s
zAdmin._action_profile_modecCs>|r,|jj�r:|jj�r:|jd�d}n|jd|�|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_statuscCsrtj�|j|jkr.td|j�|jjd�S|jj�rn|j|krn|j	sbtd|j
�|jjd�S|jjd�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&rrFrZisSetrrr)rr+r"r"r#�_action_dbus_wait_profile�s

zAdmin._action_dbus_wait_profilecCs||jdks|jdkrdSy2|jj|j�}d|_t|dtjd�tjj�Wn,tk
rv}z|jd�WYdd}~XnXdS)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#r8szAdmin._log_capture_finishcCs�t|�dkr|j�Sdj|�}|dkr2|jjd�S|jj�|jrn|jdk	rn|j	dd}|jj
|j|�|_|jj|�\}}|js�|r�|jj|j
||��Stj�|_|jj|j|�|j
||�S)Nrr[r
F��)�len�_action_dbus_list�joinrrFr�clearrrr
�log_capture_startrZswitch_profilerdrerfr9rg)rrDr+r rbrcr"r"r#�_action_dbus_profiles 


zAdmin._action_dbus_profilecCs<td�|jjdddg�\}}|dkr0td�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&rZexecute)rrbrcr"r"r#�_restart_tuned+s

zAdmin._restart_tunedcCsz||jj�krdy|jj||�|j�dStk
r`}z|jt|��|jd�dSd}~XqvXn|jd|�dSdS)NTzUnable to switch profile.Fz%Requested profile '%s' doesn't exist.)rZget_known_namesrZsave_active_profilerrrrr7)rr+rMr!r"r"r#�_set_profile3s
zAdmin._set_profilecCs6t|�dkr|j�Sdj|�}|dkr*dS|j|d�S)Nrr[r
FT)rlrIrnrs)rrDr+r"r"r#�_action_profileAs
zAdmin._action_profilecCs�|jj�}|jj�|jrF|jdk	rF|jdd}|jj|j|�|_|jj	�\}}|js`|rt|jj
|j||��Stj�|_
|jj|j|�|j||�S)Nrjrk)r�recommend_profilerrorrr
rprZauto_profilerFrdrerfr9rg)rr+r rbrcr"r"r#�_action_dbus_auto_profileIs


zAdmin._action_dbus_auto_profilecCs|jj�}|j|d�S)NF)r�	recommendrs)rr+r"r"r#�_action_auto_profileYs
zAdmin._action_auto_profilecCst|jj��|jjd�S)NT)r&rrurF)rr"r"r#�_action_dbus_recommend_profile]sz$Admin._action_dbus_recommend_profilecCst|jj��dS)NT)r&rrw)rr"r"r#�_action_recommend_profileaszAdmin._action_recommend_profilecCsr|r|jj�}n
|jj�}|r(td�n0td�td�td�td�td�td�tdtj�|jj|�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_FILErF)r�ignore_missingrbr"r"r#�_action_dbus_verify_profilees

z!Admin._action_dbus_verify_profilecCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr|r"r"r#�_action_verify_profilevszAdmin._action_verify_profilecCs:d}|jj|j|�|_|jj�}|s.|jd�|jj|�S)NrjrkzCannot disable active profile.r>)rrprrZoffrrF)rr rbr"r"r#�_action_dbus_offzs

zAdmin._action_dbus_offcCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr"r"r#�_action_off�szAdmin._action_offrDcCs(|dkr|j�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
		rD�plugins)�verboseN)rG�_action_dbus_list_plugins)r�list_choicer�r"r"r#rm�s	zAdmin._action_dbus_listcCs(|dkr|j�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
		rDr�)r�N)rI�_action_list_plugins)rr�r�r"r"r#�_action_list�s	zAdmin._action_listcCs�|jj�}xv|j�D]j}t|�|st||�dkr8q|jj|�}x8||D],}td|�|j|d�}|rNtd|�qNWqW|jjd�S)zvPrint accessible plugins

		Keyword arguments:
		verbose -- if is set to True then parameters and hints are printed
		rz	%sNz		%sT)rZget_plugins�keysr&rlZget_plugin_hints�getrF)rr�r��pluginZhintsZ	parameterZhintr"r"r#r��s
zAdmin._action_dbus_list_pluginscCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r"r"r#r��szAdmin._action_list_pluginscCs0|jj||�\}}|s$|jd|�|jj|�S)NzUnable to acquire devices: %s)rZinstance_acquire_devicesrrF)r�devices�instancerbrcr"r"r#�%_action_dbus_instance_acquire_devices�sz+Admin._action_dbus_instance_acquire_devicescCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r�r"r"r#� _action_instance_acquire_devices�sz&Admin._action_instance_acquire_devicescCs^|jj|�\}}}|s0|jd|�|jjd�Sx |D]\}}td||f�q6W|jjd�S)NzUnable to list instances: %sFz%s (%s)T)rZ
get_instancesrrFr&)r�plugin_namerbrcZpairsr�r�r"r"r#�_action_dbus_get_instances�sz Admin._action_dbus_get_instancescCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r"r"r#�_action_get_instances�szAdmin._action_get_instancescCsR|jj|�\}}}|s0|jd|�|jjd�Sx|D]}t|�q6W|jjd�S)NzUnable to list devices: %sFT)rZinstance_get_devicesrrFr&)rr�rbrcr�Zdevicer"r"r#�!_action_dbus_instance_get_devices�s
z'Admin._action_dbus_instance_get_devicescCstd�dS)Nz Not supported in no_daemon mode.F)r&)rr�r"r"r#�_action_instance_get_devices�sz"Admin._action_instance_get_devicesN)r
)r
)rDF)rDF)F)F)7�__name__�
__module__�__qualname__rZ
ADMIN_TIMEOUT�loggingZERRORr$rrr4r<rArGrIrKrNrOrQrRrVrWrXrYrZrErHr]r_r`rdrgr8rqrrrsrtrvrxryrzr}r~rr�rmr�r�r�r�r�r�r�r�r�r"r"r"r#r	sd




		




		r	)Z
__future__rZtuned.adminrZtuned.utils.commandsrZtuned.profilesrr�
exceptionsrZtuned.exceptionsrZtuned.constsrZtuned.utils.profile_recommenderrr-r'r1rerr��objectr	r"r"r"r#�<module>s
PK#v[�D��0__pycache__/dbus_controller.cpython-36.opt-1.pycnu�[���3

�<�eW�@sZddlZddlZddlZddlmZddlmZmZddlm	Z	dgZ
Gdd�de�ZdS)�N)�
DBusGMainLoop)�GLib�GObject�)�TunedAdminDBusException�DBusControllerc@seZdZdCdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBS)DrFcCsL||_||_||_d|_d|_||_d|_d|_d|_d|_	d|_
d|_dS)NTF)�	_bus_name�_interface_name�_object_name�_proxy�
_interface�_debug�
_main_loop�_action�_on_exit_action�_ret�_exit�
_exception)�selfZbus_nameZinterface_nameZobject_name�debug�r�%/usr/lib/python3.6/dbus_controller.py�__init__szDBusController.__init__cCsvyP|jdkrNtdd�tj�|_tj�}|j|j|j	�|_tj
|j|jd�|_Wn tj
jk
rptd��YnXdS)NT)Zset_as_default)Zdbus_interfacez>Cannot talk to TuneD daemon via DBus. Is TuneD daemon running?)rrrZMainLoopr�dbusZ	SystemBusZ
get_objectrr
Z	Interfacer	r�
exceptions�
DBusExceptionr)rZbusrrr�_init_proxys


zDBusController._init_proxycCs�|jdk	rPy|j|j|j�|_Wn.tk
rN}z||_d|_WYdd}~XnX|jr~|jdk	rp|j|j|j	�|j
j�dStj
d�dS)NTFr)r�_action_args�_action_kwargsZ_action_exit_coderrrr�_on_exit_action_args�_on_exit_action_kwargsr�quit�timeZsleep)r�errr�_idle$s



zDBusController._idlecOs||_||_||_dS)N)rrr )r�action�args�kwargsrrr�set_on_exit_action7sz!DBusController.set_on_exit_actioncOs||_||_||_dS)N)rrr)rr%r&r'rrr�
set_action<szDBusController.set_actioncCs2d|_tj|j�|jj�|jdk	r,|j�|jS)N)rrZidle_addr$r�runr)rrrrr*As

zDBusController.runcOsp|j�y|jj|�}||ddi�Stjjk
rj}z(d}|jrR|dt|�7}t|��WYdd}~XnXdS)N�timeout�(z DBus call to TuneD daemon failedz (%s))	rrZget_dbus_methodrrrr
�strr)rZmethod_namer&r'�methodZdbus_exceptionZerr_strrrr�_callJszDBusController._callcCs|j�|jj||�dS)N)rrZconnect_to_signal)r�signal�cbrrr�set_signal_handlerVsz!DBusController.set_signal_handlercCs
|jd�S)N�
is_running)r/)rrrrr3ZszDBusController.is_runningcCs
|jd�S)N�start)r/)rrrrr4]szDBusController.startcCs
|jd�S)N�stop)r/)rrrrr5`szDBusController.stopcCs
|jd�S)N�profiles)r/)rrrrr6cszDBusController.profilescCs
|jd�S)N�	profiles2)r/)rrrrr7fszDBusController.profiles2cCs|jd|�S)N�profile_info)r/)rZprofile_namerrrr8iszDBusController.profile_infocCs|jd||�S)N�log_capture_start)r/)rZ	log_levelr+rrrr9lsz DBusController.log_capture_startcCs|jd|�S)N�log_capture_finish)r/)r�tokenrrrr:osz!DBusController.log_capture_finishcCs
|jd�S)N�active_profile)r/)rrrrr<rszDBusController.active_profilecCs
|jd�S)N�profile_mode)r/)rrrrr=uszDBusController.profile_modecCs
|jd�S)N�post_loaded_profile)r/)rrrrr>xsz"DBusController.post_loaded_profilecCs|dkrdS|jd|�S)N�F�No profile specified�switch_profile)Fr@)r/)rZnew_profilerrrrA{szDBusController.switch_profilecCs
|jd�S)N�auto_profile)r/)rrrrrB�szDBusController.auto_profilecCs
|jd�S)N�recommend_profile)r/)rrrrrC�sz DBusController.recommend_profilecCs
|jd�S)N�verify_profile)r/)rrrrrD�szDBusController.verify_profilecCs
|jd�S)N�verify_profile_ignore_missing)r/)rrrrrE�sz,DBusController.verify_profile_ignore_missingcCs
|jd�S)N�disable)r/)rrrr�off�szDBusController.offcCs
|jd�S)zzReturn dict with plugin names and their hints

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		Zget_all_plugins)r/)rrrr�get_plugins�szDBusController.get_pluginscCs|jd|�S)z"Return docstring of plugin's class�get_plugin_documentation)r/)r�plugin_namerrrrI�sz'DBusController.get_plugin_documentationcCs|jd|�S)z�Return dictionary with parameters of plugin and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		�get_plugin_hints)r/)rrJrrrrK�s	zDBusController.get_plugin_hintscCs|jd||�S)N�instance_acquire_devices)r/)rZdevices�instancerrrrL�sz'DBusController.instance_acquire_devicescCs|jd|�S)N�
get_instances)r/)rrJrrrrN�szDBusController.get_instancescCs|jd|�S)N�instance_get_devices)r/)rrMrrrrO�sz#DBusController.instance_get_devicescCs|jd�||_d|_|S)NT)r)rr)r�retrrr�exit�s
zDBusController.exitN)F)#�__name__�
__module__�__qualname__rrr$r(r)r*r/r2r3r4r5r6r7r8r9r:r<r=r>rArBrCrDrErGrHrIrKrLrNrOrQrrrrr
s@
	)
rZdbus.exceptionsr"Zdbus.mainloop.glibrZ
gi.repositoryrrrr�__all__�objectrrrrr�<module>sPK#v[����#__pycache__/__init__.cpython-36.pycnu�[���3

�<�eN�@sddlTddlTddlTdS)�)�*N)Zadmin�
exceptionsZdbus_controller�rr�/usr/lib/python3.6/__init__.py�<module>sPK#v[����)__pycache__/__init__.cpython-36.opt-1.pycnu�[���3

�<�eN�@sddlTddlTddlTdS)�)�*N)Zadmin�
exceptionsZdbus_controller�rr�/usr/lib/python3.6/__init__.py�<module>sPK#v[϶c�>�>admin.pynu�[���
from __future__ import print_function
import tuned.admin
from tuned.utils.commands import commands
from tuned.profiles import Locator as profiles_locator
from .exceptions import TunedAdminDBusException
from tuned.exceptions import TunedException
import tuned.consts as consts
from tuned.utils.profile_recommender import ProfileRecommender
import os
import sys
import errno
import time
import threading
import logging

class Admin(object):
	def __init__(self, dbus = True, debug = False, asynco = False,
			timeout = consts.ADMIN_TIMEOUT,
			log_level = logging.ERROR):
		self._dbus = dbus
		self._debug = debug
		self._async = asynco
		self._timeout = timeout
		self._cmd = commands(debug)
		self._profiles_locator = profiles_locator(consts.LOAD_DIRECTORIES)
		self._daemon_action_finished = threading.Event()
		self._daemon_action_profile = ""
		self._daemon_action_result = True
		self._daemon_action_errstr = ""
		self._controller = None
		self._log_token = None
		self._log_level = log_level
		self._profile_recommender = ProfileRecommender()
		if self._dbus:
			self._controller = tuned.admin.DBusController(consts.DBUS_BUS, consts.DBUS_INTERFACE, consts.DBUS_OBJECT, debug)
			try:
				self._controller.set_signal_handler(consts.SIGNAL_PROFILE_CHANGED, self._signal_profile_changed_cb)
			except TunedAdminDBusException as e:
				self._error(e)
				self._dbus = False

	def _error(self, message):
		print(message, file=sys.stderr)

	def _signal_profile_changed_cb(self, profile_name, result, errstr):
		# ignore successive signals if the signal is not yet processed
		if not self._daemon_action_finished.is_set():
			self._daemon_action_profile = profile_name
			self._daemon_action_result = result
			self._daemon_action_errstr = errstr
			self._daemon_action_finished.set()

	def _tuned_is_running(self):
		try:
			os.kill(int(self._cmd.read_file(consts.PID_FILE)), 0)
		except OSError as e:
			return e.errno == errno.EPERM
		except (ValueError, IOError) as e:
			return False
		return True

	# run the action specified by the action_name with args
	def action(self, action_name, *args, **kwargs):
		if action_name is None or action_name == "":
			return False
		action = None
		action_dbus = None
		res = False
		try:
			action_dbus = getattr(self, "_action_dbus_" + action_name)
		except AttributeError as e:
			self._dbus = False
		try:
			action = getattr(self, "_action_" + action_name)
		except AttributeError as e:
			if not self._dbus:
				self._error(str(e) + ", action '%s' is not implemented" % action_name)
				return False
		if self._dbus:
			try:
				self._controller.set_on_exit_action(
						self._log_capture_finish)
				self._controller.set_action(action_dbus, *args, **kwargs)
				res = self._controller.run()
			except TunedAdminDBusException as e:
				self._error(e)
				self._dbus = False

		if not self._dbus:
			res = action(*args, **kwargs)
		return res

	def _print_profiles(self, profile_names):
		print("Available profiles:")
		for profile in profile_names:
			if profile[1] is not None and profile[1] != "":
				print(self._cmd.align_str("- %s" % profile[0], 30, "- %s" % profile[1]))
			else:
				print("- %s" % profile[0])

	def _action_dbus_list_profiles(self):
		try:
			profile_names = self._controller.profiles2()
		except TunedAdminDBusException as e:
			# fallback to older API
			profile_names = [(profile, "") for profile in self._controller.profiles()]
		self._print_profiles(profile_names)
		self._action_dbus_active()
		return self._controller.exit(True)

	def _action_list_profiles(self):
		self._print_profiles(self._profiles_locator.get_known_names_summary())
		self._action_active()
		return True

	def _dbus_get_active_profile(self):
		profile_name = self._controller.active_profile()
		if profile_name == "":
			profile_name = None
		self._controller.exit(True)
		return profile_name

	def _get_active_profile(self):
		profile_name, manual = self._cmd.get_active_profile()
		return profile_name

	def _get_profile_mode(self):
		(profile, manual) = self._cmd.get_active_profile()
		if manual is None:
			manual = profile is not None
		return consts.ACTIVE_PROFILE_MANUAL if manual else consts.ACTIVE_PROFILE_AUTO

	def _dbus_get_post_loaded_profile(self):
		profile_name = self._controller.post_loaded_profile()
		if profile_name == "":
			profile_name = None
		return profile_name

	def _get_post_loaded_profile(self):
		profile_name = self._cmd.get_post_loaded_profile()
		return profile_name

	def _print_profile_info(self, profile, profile_info):
		if profile_info[0] == True:
			print("Profile name:")
			print(profile_info[1])
			print()
			print("Profile summary:")
			print(profile_info[2])
			print()
			print("Profile description:")
			print(profile_info[3])
			return True
		else:
			print("Unable to get information about profile '%s'" % profile)
			return False

	def _action_dbus_profile_info(self, profile = ""):
		if profile == "":
			profile = self._dbus_get_active_profile()
		if profile:
			res = self._print_profile_info(profile, self._controller.profile_info(profile))
		else:
			print("No current active profile.")
			res = False
		return self._controller.exit(res)

	def _action_profile_info(self, profile = ""):
		if profile == "":
			try:
				profile = self._get_active_profile()
				if profile is None:
					print("No current active profile.")
					return False
			except TunedException as e:
				self._error(str(e))
				return False
		return self._print_profile_info(profile, self._profiles_locator.get_profile_attrs(profile, [consts.PROFILE_ATTR_SUMMARY, consts.PROFILE_ATTR_DESCRIPTION], ["", ""]))

	def _print_profile_name(self, profile_name):
		if profile_name is None:
			print("No current active profile.")
			return False
		else:
			print("Current active profile: %s" % profile_name)
		return True

	def _print_post_loaded_profile(self, profile_name):
		if profile_name:
			print("Current post-loaded profile: %s" % profile_name)

	def _action_dbus_active(self):
		active_profile = self._dbus_get_active_profile()
		res = self._print_profile_name(active_profile)
		if res:
			post_loaded_profile = self._dbus_get_post_loaded_profile()
			self._print_post_loaded_profile(post_loaded_profile)
		return self._controller.exit(res)

	def _action_active(self):
		try:
			profile_name = self._get_active_profile()
			post_loaded_profile = self._get_post_loaded_profile()
			# The result of the DBus call active_profile includes
			# the post-loaded profile, so add it here as well
			if post_loaded_profile:
				if profile_name:
					profile_name += " "
				else:
					profile_name = ""
				profile_name += post_loaded_profile
		except TunedException as e:
			self._error(str(e))
			return False
		if profile_name is not None and not self._tuned_is_running():
			print("It seems that tuned daemon is not running, preset profile is not activated.")
			print("Preset profile: %s" % profile_name)
			if post_loaded_profile:
				print("Preset post-loaded profile: %s" % post_loaded_profile)
			return True
		res = self._print_profile_name(profile_name)
		self._print_post_loaded_profile(post_loaded_profile)
		return res

	def _print_profile_mode(self, mode):
		print("Profile selection mode: " + mode)

	def _action_dbus_profile_mode(self):
		mode, error = self._controller.profile_mode()
		self._print_profile_mode(mode)
		if error != "":
			self._error(error)
			return self._controller.exit(False)
		return self._controller.exit(True)

	def _action_profile_mode(self):
		try:
			mode = self._get_profile_mode()
			self._print_profile_mode(mode)
			return True
		except TunedException as e:
			self._error(str(e))
			return False

	def _profile_print_status(self, ret, msg):
		if ret:
			if not self._controller.is_running() and not self._controller.start():
				self._error("Cannot enable the tuning.")
				ret = False
		else:
			self._error("Unable to switch profile: %s" % msg)
		return ret

	def _action_dbus_wait_profile(self, profile_name):
		if time.time() >= self._timestamp + self._timeout:
			print("Operation timed out after waiting %d seconds(s), you may try to increase timeout by using --timeout command line option or using --async." % self._timeout)
			return self._controller.exit(False)
		if self._daemon_action_finished.isSet():
			if self._daemon_action_profile == profile_name:
				if not self._daemon_action_result:
					print("Error changing profile: %s" % self._daemon_action_errstr)
					return self._controller.exit(False)
				return self._controller.exit(True)
		return False

	def _log_capture_finish(self):
		if self._log_token is None or self._log_token == "":
			return
		try:
			log_msgs = self._controller.log_capture_finish(
					self._log_token)
			self._log_token = None
			print(log_msgs, end = "", file = sys.stderr)
			sys.stderr.flush()
		except TunedAdminDBusException as e:
			self._error("Error: Failed to stop log capture. Restart the TuneD daemon to prevent a memory leak.")

	def _action_dbus_profile(self, profiles):
		if len(profiles) == 0:
			return self._action_dbus_list()
		profile_name = " ".join(profiles)
		if profile_name == "":
			return self._controller.exit(False)
		self._daemon_action_finished.clear()
		if not self._async and self._log_level is not None:
			# 25 seconds default DBus timeout + 5 secs safety margin
			timeout = self._timeout + 25 + 5
			self._log_token = self._controller.log_capture_start(
					self._log_level, timeout)
		(ret, msg) = self._controller.switch_profile(profile_name)
		if self._async or not ret:
			return self._controller.exit(self._profile_print_status(ret, msg))
		else:
			self._timestamp = time.time()
			self._controller.set_action(self._action_dbus_wait_profile, profile_name)
		return self._profile_print_status(ret, msg)

	def _restart_tuned(self):
		print("Trying to (re)start tuned...")
		(ret, msg) = self._cmd.execute(["service", "tuned", "restart"])
		if ret == 0:
			print("TuneD (re)started, changes applied.")
		else:
			print("TuneD (re)start failed, you need to (re)start TuneD by hand for changes to apply.")

	def _set_profile(self, profile_name, manual):
		if profile_name in self._profiles_locator.get_known_names():
			try:
				self._cmd.save_active_profile(profile_name, manual)
				self._restart_tuned()
				return True
			except TunedException as e:
				self._error(str(e))
				self._error("Unable to switch profile.")
				return False
		else:
			self._error("Requested profile '%s' doesn't exist." % profile_name)
			return False

	def _action_profile(self, profiles):
		if len(profiles) == 0:
			return self._action_list_profiles()
		profile_name = " ".join(profiles)
		if profile_name == "":
			return False
		return self._set_profile(profile_name, True)

	def _action_dbus_auto_profile(self):
		profile_name = self._controller.recommend_profile()
		self._daemon_action_finished.clear()
		if not self._async and self._log_level is not None:
			# 25 seconds default DBus timeout + 5 secs safety margin
			timeout = self._timeout + 25 + 5
			self._log_token = self._controller.log_capture_start(
					self._log_level, timeout)
		(ret, msg) = self._controller.auto_profile()
		if self._async or not ret:
			return self._controller.exit(self._profile_print_status(ret, msg))
		else:
			self._timestamp = time.time()
			self._controller.set_action(self._action_dbus_wait_profile, profile_name)
		return self._profile_print_status(ret, msg)

	def _action_auto_profile(self):
		profile_name = self._profile_recommender.recommend()
		return self._set_profile(profile_name, False)

	def _action_dbus_recommend_profile(self):
		print(self._controller.recommend_profile())
		return self._controller.exit(True)

	def _action_recommend_profile(self):
		print(self._profile_recommender.recommend())
		return True

	def _action_dbus_verify_profile(self, ignore_missing):
		if ignore_missing:
			ret = self._controller.verify_profile_ignore_missing()
		else:
			ret = self._controller.verify_profile()
		if ret:
			print("Verification succeeded, current system settings match the preset profile.")
		else:
			print("Verification failed, current system settings differ from the preset profile.")
			print("You can mostly fix this by restarting the TuneD daemon, e.g.:")
			print("  systemctl restart tuned")
			print("or")
			print("  service tuned restart")
			print("Sometimes (if some plugins like bootloader are used) a reboot may be required.")
		print("See TuneD log file ('%s') for details." % consts.LOG_FILE)
		return self._controller.exit(ret)

	def _action_verify_profile(self, ignore_missing):
		print("Not supported in no_daemon mode.")
		return False

	def _action_dbus_off(self):
		# 25 seconds default DBus timeout + 5 secs safety margin
		timeout = 25 + 5
		self._log_token = self._controller.log_capture_start(
				self._log_level, timeout)
		ret = self._controller.off()
		if not ret:
			self._error("Cannot disable active profile.")
		return self._controller.exit(ret)

	def _action_off(self):
		print("Not supported in no_daemon mode.")
		return False

	def _action_dbus_list(self, list_choice="profiles", verbose=False):
		"""Print 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
		"""
		if list_choice == "profiles":
			return self._action_dbus_list_profiles()
		elif list_choice == "plugins":
			return self._action_dbus_list_plugins(verbose=verbose)

	def _action_list(self, list_choice="profiles", verbose=False):
		"""Print 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
		"""
		if list_choice == "profiles":
			return self._action_list_profiles()
		elif list_choice == "plugins":
			return self._action_list_plugins(verbose=verbose)

	def _action_dbus_list_plugins(self, verbose=False):
		"""Print accessible plugins

		Keyword arguments:
		verbose -- if is set to True then parameters and hints are printed
		"""
		plugins = self._controller.get_plugins()
		for plugin in plugins.keys():
			print(plugin)
			if not verbose or len(plugins[plugin]) == 0:
				continue
			hints = self._controller.get_plugin_hints(plugin)
			for parameter in plugins[plugin]:
				print("\t%s" %(parameter))
				hint = hints.get(parameter, None)
				if hint:
					print("\t\t%s" %(hint))
		return self._controller.exit(True)

	def _action_list_plugins(self, verbose=False):
		print("Not supported in no_daemon mode.")
		return False

	def _action_dbus_instance_acquire_devices(self, devices, instance):
		(ret, msg) = self._controller.instance_acquire_devices(devices, instance)
		if not ret:
			self._error("Unable to acquire devices: %s" % msg)
		return self._controller.exit(ret)

	def _action_instance_acquire_devices(self, devices, instance):
		print("Not supported in no_daemon mode.")
		return False

	def _action_dbus_get_instances(self, plugin_name):
		(ret, msg, pairs) = self._controller.get_instances(plugin_name)
		if not ret:
			self._error("Unable to list instances: %s" % msg)
			return self._controller.exit(False)
		for instance, plugin in pairs:
			print("%s (%s)" % (instance, plugin))
		return self._controller.exit(True)

	def _action_get_instances(self, plugin_name):
		print("Not supported in no_daemon mode.")
		return False

	def _action_dbus_instance_get_devices(self, instance):
		(ret, msg, devices) = self._controller.instance_get_devices(instance)
		if not ret:
			self._error("Unable to list devices: %s" % msg)
			return self._controller.exit(False)
		for device in devices:
			print(device)
		return self._controller.exit(True)

	def _action_instance_get_devices(self, instance):
		print("Not supported in no_daemon mode.")
		return False
PK#v[�A
CWWdbus_controller.pynu�[���import dbus
import dbus.exceptions
import time
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib, GObject
from .exceptions import TunedAdminDBusException

__all__ = ["DBusController"]

class DBusController(object):
	def __init__(self, bus_name, interface_name, object_name, debug = False):
		self._bus_name = bus_name
		self._interface_name = interface_name
		self._object_name = object_name
		self._proxy = None
		self._interface = None
		self._debug = debug
		self._main_loop = None
		self._action = None
		self._on_exit_action = None
		self._ret = True
		self._exit = False
		self._exception = None

	def _init_proxy(self):
		try:
			if self._proxy is None:
				DBusGMainLoop(set_as_default=True)
				self._main_loop = GLib.MainLoop()
				bus = dbus.SystemBus()
				self._proxy = bus.get_object(self._bus_name, self._object_name)
				self._interface = dbus.Interface(self._proxy, dbus_interface = self._interface_name)
		except dbus.exceptions.DBusException:
			raise TunedAdminDBusException("Cannot talk to TuneD daemon via DBus. Is TuneD daemon running?")

	def _idle(self):
		if self._action is not None:
			# This may (and very probably will) run in child thread, so catch and pass exceptions to the main thread
			try:
				self._action_exit_code = self._action(*self._action_args, **self._action_kwargs)
			except TunedAdminDBusException as e:
				self._exception = e
				self._exit = True

		if self._exit:
			if self._on_exit_action is not None:
				self._on_exit_action(*self._on_exit_action_args,
						**self._on_exit_action_kwargs)
			self._main_loop.quit()
			return False
		else:
			time.sleep(1)
		return True

	def set_on_exit_action(self, action, *args, **kwargs):
		self._on_exit_action = action
		self._on_exit_action_args = args
		self._on_exit_action_kwargs = kwargs

	def set_action(self, action, *args, **kwargs):
		self._action = action
		self._action_args = args
		self._action_kwargs = kwargs

	def run(self):
		self._exception = None
		GLib.idle_add(self._idle)
		self._main_loop.run()
		# Pass exception happened in child thread to the caller
		if self._exception is not None:
			raise self._exception
		return self._ret

	def _call(self, method_name, *args, **kwargs):
		self._init_proxy()

		try:
			method = self._interface.get_dbus_method(method_name)
			return method(*args, timeout=40)
		except dbus.exceptions.DBusException as dbus_exception:
			err_str = "DBus call to TuneD daemon failed"
			if self._debug:
				err_str += " (%s)" % str(dbus_exception)
			raise TunedAdminDBusException(err_str)

	def set_signal_handler(self, signal, cb):
		self._init_proxy()
		self._proxy.connect_to_signal(signal, cb)

	def is_running(self):
		return self._call("is_running")

	def start(self):
		return self._call("start")

	def stop(self):
		return self._call("stop")

	def profiles(self):
		return self._call("profiles")

	def profiles2(self):
		return self._call("profiles2")

	def profile_info(self, profile_name):
		return self._call("profile_info", profile_name)

	def log_capture_start(self, log_level, timeout):
		return self._call("log_capture_start", log_level, timeout)

	def log_capture_finish(self, token):
		return self._call("log_capture_finish", token)

	def active_profile(self):
		return self._call("active_profile")

	def profile_mode(self):
		return self._call("profile_mode")

	def post_loaded_profile(self):
		return self._call("post_loaded_profile")

	def switch_profile(self, new_profile):
		if new_profile == "":
			return (False, "No profile specified")
		return self._call("switch_profile", new_profile)

	def auto_profile(self):
		return self._call("auto_profile")

	def recommend_profile(self):
		return self._call("recommend_profile")

	def verify_profile(self):
		return self._call("verify_profile")

	def verify_profile_ignore_missing(self):
		return self._call("verify_profile_ignore_missing")

	def off(self):
		return self._call("disable")

	def get_plugins(self):
		"""Return dict with plugin names and their hints

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		"""
		return self._call("get_all_plugins")

	def get_plugin_documentation(self, plugin_name):
		"""Return docstring of plugin's class"""
		return self._call("get_plugin_documentation", plugin_name)

	def get_plugin_hints(self, plugin_name):
		"""Return dictionary with parameters of plugin and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		"""
		return self._call("get_plugin_hints", plugin_name)

	def instance_acquire_devices(self, devices, instance):
		return self._call("instance_acquire_devices", devices, instance)

	def get_instances(self, plugin_name):
		return self._call("get_instances", plugin_name)

	def instance_get_devices(self, instance):
		return self._call("instance_get_devices", instance)

	def exit(self, ret):
		self.set_action(None)
		self._ret = ret
		self._exit = True
		return ret
PK#v[�L|NN__init__.pynu�[���PK#v[ϐ��__
�exceptions.pynu�[���PK#v[ VsBB %__pycache__/admin.cpython-36.pycnu�[���PK#v[ϨA�^^%�C__pycache__/exceptions.cpython-36.pycnu�[���PK#v[�D��*8E__pycache__/dbus_controller.cpython-36.pycnu�[���PK#v[ϨA�^^+a__pycache__/exceptions.cpython-36.opt-1.pycnu�[���PK#v[ VsBB&�b__pycache__/admin.cpython-36.opt-1.pycnu�[���PK#v[�D��09�__pycache__/dbus_controller.cpython-36.opt-1.pycnu�[���PK#v[����#!�__pycache__/__init__.cpython-36.pycnu�[���PK#v[����),�__pycache__/__init__.cpython-36.opt-1.pycnu�[���PK#v[϶c�>�>=�admin.pynu�[���PK#v[�A
CWWdbus_controller.pynu�[���PKn�