MINI MINI MANI MO

Path : /usr/lib/python2.7/site-packages/tuned/plugins/
File Upload :
Current File : //usr/lib/python2.7/site-packages/tuned/plugins/base.pyo


=[c@sddlZddljZddlZddlZddlZddlmZddl	Z	ddl
mZmZej
jZdefdYZdS(iN(tcommands(tPopentPIPEtPlugincBsKeZdZdZdZedZedZedZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZdZdZdZdZdZdZedZdZdZdZedZ dZ!dZ"edZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d:d:d:d%Z+d:d&Z,d:d'Z-d:d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d:ed.Z4d:d:d/Z5d0Z6d1Z7d2Z8d:d3Z9d4Z:d5Z;d6Z<d7Z=d8Z>d9Z?RS(;s
	Base class for all plugins.

	Plugins change various system settings in order to get desired performance or power
	saving. Plugins use Monitor objects to get information from the running system.

	Intentionally a lot of logic is included in the plugin to increase plugin flexibility.
	c		Cs|j|jj|_||_||_||_||_||_t	j
|_|j|j
||_||_t|_|j|_t|_dS(sPlugin constructor.N(tcreatet	__class__t__name__t_storaget_monitors_repositoryt_hardware_inventoryt_device_matchert_device_matcher_udevt_instance_factorytcollectionstOrderedDictt
_instancest_init_commandst
_init_devicest_global_cfgt
_variablestFalset_has_dynamic_optionst#_get_config_options_used_by_dynamict_options_used_by_dynamicRt_cmd(	tselftmonitors_repositorytstorage_factorythardware_inventorytdevice_matchertdevice_matcher_udevtinstance_factoryt
global_cfgt	variables((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt__init__s					

			cCs|jdS(N(tdestroy_instances(R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytcleanup,scCs'|jjjddjdddS(Nt.it_i(Rt
__module__tsplit(R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytname/scCsiS(s-Default configuration options for the plugin.((R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_get_config_options7scCsgS(snList of config options used by dynamic tuning. Their previous values will be automatically saved and restored.((R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR<scCsj|jj}xQ|D]I}||ks4|jrE||||<qtjd||jjfqW|S(s3Merge provided options with plugin default options.s$Unknown option '%s' for plugin '%s'.(R*tcopyRtlogtwarnRR(Rtoptionst	effectivetkey((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_get_effective_optionsAs
!cCs>t|tkr|St|j}|dkp=|dkS(Nttruet1(ttypetbooltstrtlower(Rtvalue((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_option_boolLsc	Csf||jkr"td|n|j|}|jj|||||||}||j|<|S(s8Create new instance of the plugin and seize the devices.s.Plugin instance with name '%s' already exists.(Rt	ExceptionR1RR(	RR)tdevices_expressiontdevices_udev_regext
script_pretscript_postR.teffective_optionstinstance((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytcreate_instanceVs
cCs{|j|kr(td||fn|j|jkrMtd|n|j|j}|j||j|j=dS(sDestroy existing instance.s9Plugin instance '%s' does not belong to this plugin '%s'.s+Plugin instance '%s' was already destroyed.N(t_pluginR:R)Rt_destroy_instance(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytdestroy_instancebs
cCs.tjd|j|jf|j|dS(sInitialize an instance.sinitializing instance %s (%s)N(R,tdebugR)t_instance_init(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytinitialize_instancemscCs[xGt|jjD]0}tjd|j|jf|j|qW|jjdS(sDestroy all instances.sdestroying instance %s (%s)N(tlistRtvaluesR,RER)RCtclear(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR#rscCs|j||j|dS(N(trelease_devicest_instance_cleanup(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRCys
cCs
tdS(N(tNotImplementedError(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRF}scCs
tdS(N(RM(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRLscCs%t|_t|_t|_dS(N(Rt_devices_supportedtsett_assigned_devicest
_free_devices(R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs	cCsdS(sOverride this in a subclass to transform a list of device names (e.g. ['sda'])
		   to a list of pyudev.Device objects, if your plugin supports itN(tNone(Rtdevices((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_get_device_objectsscCs|jdkr+t|jj|j|S|j|}|dkr`tjd|j	tS|j
j|j|}tg|D]}|j^qSdS(Ns<Plugin '%s' does not support the 'devices_udev_regex' option(R<RRROR
t
match_listR;RTR,terrorR)Rtsys_name(RR@RStudev_devicestx((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_get_matching_devicesscCs|js
dStjd|j|j||j}t|dk|_|jsktjd|jn}|j}|j|jkr|d|j7}ntj	d|dj
|f|jj||j
|O_
|j|8_dS(Ns assigning devices to instance %sis*instance %s: no matching devices availables (%s)s!instance %s: assigning devices %ss, (RNR,RER)RZRQtlentactiveR-tinfotjoinRStupdateRP(RR@t	to_assignR)((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytassign_free_devicess			 cCsU|js
dS|j|j@}t|_|jj|j|8_|j|O_dS(N(RNRSRPRR\RJRQ(RR@t
to_release((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRKs		
cCs@|jr|j}n	dg}x|D]}|||q%WdS(N(RNRSRR(RR@tcallbackRStdevice((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_run_for_each_devices
		
cCsdS(N((RR@tenabling((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_instance_pre_staticscCsdS(N((RR@Rf((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_instance_post_staticscCs|dkrdSt|dkr@tjd|j|fdS|jdsdtjddtStj	j
|}t}xR|D]J}tj}	|	j
|jj|g}
|r|
jdn|
j|tjd|t|
ftjdtt|	jyt|g|
d	td
tdtd|	d
|dt}|j\}}
|jrtjd||j|
d ft}nWqttfk
r}tjd||ft}qXqW|S(Nis1Instance '%s': no device to call script '%s' for.t/s<Relative paths cannot be used in script_pre or script_post. sUse ${i:PROFILE_DIR}.t
full_rollbacks'calling script '%s' with arguments '%s'susing environment '%s'tstdouttstderrt	close_fdstenvtcwdtuniversal_newlinessscript '%s' error: %d, '%s'isscript '%s' error: %s(RRR[R,R-R)t
startswithRVRtostpathtdirnametTruetenvironR_Rtget_envtappendR]R6RERHtitemsRRtcommunicatet
returncodetOSErrortIOError(RR@tscripttopRSRjtdir_nametrettdevRvt	argumentstproctoutterrte((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_call_device_scriptsB	
		
#	!
cCs|js
dS|jr~|j||jd|j|j|t|j||j|t|j||j	d|jn|j
r|jjt
jt
jr|j||jndS(sG
		Apply static and dynamic tuning if the plugin instance is active.
		Ntapply(R\thas_static_tuningRR=RSRgRut_instance_apply_staticRhR>thas_dynamic_tuningRtgettconststCFG_DYNAMIC_TUNINGtCFG_DEF_DYNAMIC_TUNINGRet_instance_apply_dynamic(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytinstance_apply_tunings		
$cCs|js
dS|jr|j||jd|jtkr>tS|j||tkrZtS|j||jd|jtkrtSt	SdSdS(s<
		Verify static tuning if the plugin instance is active.
		tverifyN(
R\RRRRR=RSRt_instance_verify_staticR>Ru(RR@tignore_missing((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytinstance_verify_tunings		$$cCsK|js
dS|jrG|jjtjtjrG|j||jndS(s<
		Apply dynamic tuning if the plugin instance is active.
		N(	R\RRRRRRRet_instance_update_dynamic(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytinstance_update_tunings	$cCs|jr:|jjtjtjr:|j||jn|jr|j	||j
d|jd||j|t
|j|||j|t
|j	||jd|jd|ndS(s8
		Remove all tunings applied by the plugin instance.
		tunapplyRjN(RRRRRRRet_instance_unapply_dynamicRRR>RSRgRt_instance_unapply_staticRhR=(RR@Rj((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pytinstance_unapply_tunings$	"cCs$|j||j||jdS(N(t _execute_all_non_device_commandst_execute_all_device_commandsRS(RR@((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR's
cCsRt}|j||tkr't}n|j||j|tkrNt}n|S(N(Rut_verify_all_non_device_commandsRt_verify_all_device_commandsRS(RR@RR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR+s		cCs$|j||j|j|dS(N(t_cleanup_all_device_commandsRSt _cleanup_all_non_device_commands(RR@Rj((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR3scCswx`g|jD].}|j||j||dkr
|^q
D] }|j||j||q?W|j||dS(N(Rt_storage_gett	_commandsRRt_check_and_save_valueR(RR@Rdtopttoption((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR7sEcCs
tdS(N(RM(RR@Rd((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR=scCs
tdS(N(RM(RR@Rd((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR@scCs'tj|_|j|jdS(s
		Initialize commands.
		N(R
RRt_autoregister_commandst_check_commands(R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRGs
cCs\x%|jjD]}|jdr(q
nt||}t|dsLq
n|jd}|jj|i|d6}d|jkrd|d<||d<|jd|d<|jd|d<nZd|jkr||d<n>d|jkr||d<|jd|d<|jd|d<n||j|<q
Wt	j
tt|jj
d	d
|_dS(sd
		Register all commands marked using @command_set, @command_get, and @command_custom decorators.
		t__t_commandR)ROtcustomt
per_devicetpriorityRR0cSs|ddS(NiR((t	name_info((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt<lambda>lsN(Rt__dict__RqtgetattrthasattrRRRRRR
RtsortedtiterRy(Rtmember_nametmembertcommand_nameR]((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyROs*




cCsmxft|jjD]O\}}|jdtr:qnd|ksRd|krtd|qqWdS(s2
		Check if all commands are defined correctly.
		RRROs,Plugin command '%s' is not defined correctlyN(RHRRyRRt	TypeError(RRtcommand((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRns
"cCskt|j}|dkr!dn|}|dkr9dn|}|dkrQdn|}d||||fS(Nts%s/%s/%s/%s(R4RRR(Rt
instance_nameRtdevice_namet
class_name((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_storage_key~s	cCs3|j|j|d|}|jj||dS(NR)(RR)RRO(RR@RR8RR0((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_storage_setscCs,|j|j|d|}|jj|S(NR)(RR)RR(RR@RRR0((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRscCs,|j|j|d|}|jj|S(NR)(RR)Rtunset(RR@RRR0((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_storage_unsetscCsxgt|jjD]}|ds|^qD]M}|jj|jj|dd}|dk	r3|j|||q3q3WdS(NRR)(	RHRRIRtexpandR.RRRt_execute_non_device_command(RR@Rt	new_value((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs9%cCsxgt|jjD]}|dr|^qD]d}|jj|jj|dd}|dkrpq3nx$|D]}|j||||qwWq3WdS(NRR)(	RHRRIRRR.RRRt_execute_device_command(RR@RSRRRd((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs9%
cCst}xgt|jjD]}|ds|^qD]a}|jj|jj|dd}|dk	r9|j	||||t
krt
}qq9q9W|S(NRR)(RuRHRRIRRR.RRRt_verify_non_device_commandR(RR@RRRR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs9%cCst}xgt|jjD]}|dr|^qD]l}|jj|dd}|dkrjq9nx8|D]0}|j|||||tkrqt}qqqqWq9W|S(NRR)(	RuRHRRIR.RRRt_verify_device_commandR(RR@RSRRRRRd((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs9
!cCs|dk	rt|}t|dkr.|S|d }|d}|dkrb|dkr^|S|Syb|dkrt|t|kr|SdSn/|dkrt|t|kr|SdSnWqtk
rtjd||||fqXn|S(Nit<t>shcannot compare new value '%s' with current value '%s' by operator '%s', using '%s' directly as new value(RR(RRR6R[tintt
ValueErrorR,R-(RRt
current_valuetnwsRtval((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_process_assignment_modifierss(


$cCs/|dk	r |d|d|S|dSdS(NRR(RR(RRRdR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_get_current_valuescCsY|j||}|j||}|dk	rU|dk	rU|j||||n|S(N(RRRRR(RR@RRdRR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs
cCso|ddk	r-|dt||ttn>|j||||}|dk	rk|d||dtndS(NRROtsim(RRRuRR(RR@RRdR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs
cCsi|ddk	r*|dt|ttn;|j||d|}|dk	re|d|dtndS(NRROR(RRRuRR(RR@RR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRs
cCsA|jjt|}tjd|r=tjdd|S|S(Ns\s*(0+,?)+([\da-fA-F]*,?)*\s*$s^\s*(0+,?)+R(RtunquoteR6tretmatchtsub(RR8tv((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt_norm_valuesc	CsQ|dkrdSt}|dkri|ri|dkrKtjtj|ntjtj||ftS|dk	re|j|}|j|}yt	|t	|k}Wqet
k
ray"t	|dt	|dk}Wqbt
k
r]t|t|k}|s^t|jd}x3|D](}|j
}||k}|r+Pq+q+Wq^qbXqeXn|r|dkrtjtj|t|j
fn)tjtj||t|j
ftS|dkrtjtj|t|j
t|j
fn8tjtj||t|j
t|j
ftSdS(Nit|(RRRR,R]Rt STR_VERIFY_PROFILE_VALUE_MISSINGt'STR_VERIFY_PROFILE_DEVICE_VALUE_MISSINGRuRRRR6R(tstriptSTR_VERIFY_PROFILE_VALUE_OKt"STR_VERIFY_PROFILE_DEVICE_VALUE_OKRVtSTR_VERIFY_PROFILE_VALUE_FAILt$STR_VERIFY_PROFILE_DEVICE_VALUE_FAIL(	RR)RRRRdRtvalsR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt
_verify_valuesD
"

))88cCs|ddk	r*|dt||t|S|j||d|}|j||}|dkrddS|d||t}|j|d||||S(NRRROR)(RRRuRRR(RR@RRdRRR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRscCs|ddk	r'|dt|t|S|j|}|j||}|dkrXdS|d|t}|j|d|||S(NRROR)(RRRuRRR(RR@RRRR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR'scCsxtgt|jjD]}|ds|^qD]K}|jj|dddk	sq|d|jkr9|j||q9q9WdS(NRR)(	treversedRHRRIR.RRRRt_cleanup_non_device_command(RR@R((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR1s?2cCsxtgt|jjD]}|dr|^qD]_}|jj|dddk	sq|d|jkr9x$|D]}|j|||qxWq9q9WdS(NRR)(	RRHRRIR.RRRRt_cleanup_device_command(RR@RSRRd((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR6s?2
cCs|ddk	r-|dtd|ttnN|j|||}|dk	rh|d||dtn|j|||dS(NRROR(RRRRR(RR@RRdt	old_value((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyR<scCss|ddk	r*|dtdttnE|j||}|dk	r_|d|dtn|j||dS(NRROR(RRRRR(RR@RR((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyREsN(@RR't__doc__R"R$tpropertyR)tclassmethodR*RR1R9RARDRGR#RCRFRLRRTRZRaRKReRgRhRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyRsv				
																#				
																	)	
	
				(Rttuned.constsRttuned.profiles.variablesttunedt
tuned.logsR
ttuned.utils.commandsRRrt
subprocessRRtlogsRR,tobjectR(((s6/usr/lib/python2.7/site-packages/tuned/plugins/base.pyt<module>s

OHA YOOOO