\c@sddlmZddlZddlmZddlmZddl m Z ddl m Z ddl jZddlmZddlZddlZddlZddlZddlZddlZd efd YZdS( i(tprint_functionN(tcommands(tLocatori(tTunedAdminDBusException(tTunedException(tProfileRecommendertAdmincBseZeeeejejdZdZ dZ dZ dZ dZ dZdZdZd Zd Zd Zd d Zd dZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&d Z'd!Z(d"Z)d#Z*d$ed%Z+d$ed&Z,ed'Z-ed(Z.RS()cCs||_||_||_||_t||_ttj|_ t j |_ d|_ t|_d|_d|_d|_||_t|_|jrtjjtjtjtj||_y|jjtj|jWqt k r}|j!|t"|_qXndS(Nt(#t_dbust_debugt_asynct_timeoutRt_cmdtprofiles_locatortconststLOAD_DIRECTORIESt_profiles_locatort threadingtEventt_daemon_action_finishedt_daemon_action_profiletTruet_daemon_action_resultt_daemon_action_errstrtNonet _controllert _log_tokent _log_levelRt_profile_recommenderttunedtadmintDBusControllertDBUS_BUStDBUS_INTERFACEt DBUS_OBJECTtset_signal_handlertDBUS_SIGNAL_PROFILE_CHANGEDt_signal_profile_changed_cbRt_errortFalse(tselftdbustdebugtasyncottimeoutt log_levelte((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt__init__s*            ' cCst|dtjdS(Ntfile(tprinttsyststderr(R(tmessage((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyR&+scCs>|jjs:||_||_||_|jjndS(N(Rtis_setRRRtset(R(t profile_nametresultterrstr((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyR%.s    cCsiy)tjt|jjtjdWn9tk rK}|jtj kSt t fk rd}t SXt S(Ni(tostkilltintR t read_fileRtPID_FILEtOSErrorterrnotEPERMt ValueErrortIOErrorR'R(R(R.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_tuned_is_running6s)cOsL|dks|dkrtSd}d}t}yt|d|}Wntk rc}t|_nXyt|d|}Wn;tk r}|js|jt|d|tSnX|jr-y<|jj|j |jj ||||jj }Wq-t k r)}|j|t|_q-Xn|jsH|||}n|S(NRt _action_dbus_t_action_s , action '%s' is not implemented( RR'tgetattrtAttributeErrorRR&tstrRtset_on_exit_actiont_log_capture_finisht set_actiontrunR(R(t action_nametargstkwargstactiont action_dbustresR.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRQ@s6       c Cstdxo|D]g}|ddk rf|ddkrft|jjd|ddd|dqtd|dqWdS(NsAvailable profiles:iRs- %sii(R1RR t align_str(R(t profile_namestprofile((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_print_profiles^s    /cCsxy|jj}Wn;tk rP}g|jjD]}|df^q5}nX|j||j|jjtS(NR(Rt profiles2RtprofilesRWt_action_dbus_activetexitR(R(RUR.RV((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_list_profilesfs,  cCs$|j|jj|jtS(N(RWRtget_known_names_summaryt_action_activeR(R(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_list_profilesps cCs8|jj}|dkr$d}n|jjt|S(NR(Rtactive_profileRR[R(R(R7((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_dbus_get_active_profileus   cCs|jj\}}|S(N(R tget_active_profile(R(R7tmanual((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_get_active_profile|scCsD|jj\}}|dkr0|dk }n|r=tjStjS(N(R RbRRtACTIVE_PROFILE_MANUALtACTIVE_PROFILE_AUTO(R(RVRc((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_get_profile_modes cCs|dtkrjtdt|dttdt|dttdt|dtStd|tSdS( Nis Profile name:isProfile summary:isProfile description:is,Unable to get information about profile '%s'(RR1R'(R(RVt profile_info((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_print_profile_infos   RcCsC|dkr|j}n|jj|j||jj|S(NR(RaRR[RiRh(R(RV((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_profile_infos cCs|dkrcy*|j}|dkr5tdtSWqctk r_}|jt|tSXn|j||jj |t j t j gddgS(NRsNo current active profile.( RdRR1R'RR&RIRiRtget_profile_attrsRtPROFILE_ATTR_SUMMARYtPROFILE_ATTR_DESCRIPTION(R(RVR.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_profile_infos    cCs,|dkrtdtStd|tS(NsNo current active profile.sCurrent active profile: %s(RR1R'R(R(R7((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_print_profile_names   cCs|jj|j|jS(N(RR[RoRa(R(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRZscCs|y|j}Wn'tk r9}|jt|tSX|dk ro|j rotdtd|tS|j |S(NsKIt seems that tuned daemon is not running, preset profile is not activated.sPreset profile: %s( RdRR&RIR'RRDR1RRo(R(R7R.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyR^s cCstd|dS(NsProfile selection mode: (R1(R(tmode((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_print_profile_modescCs[|jj\}}|j||dkrK|j||jjtS|jjtS(NR(Rt profile_modeRqR&R[R'R(R(Rpterror((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_profile_modes    cCsOy!|j}|j|tSWn'tk rJ}|jt|tSXdS(N(RgRqRRR&RIR'(R(RpR.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_profile_modes  cCsP|r?|jj rL|jj rL|jdt}qLn |j||S(NsCannot enable the tuning.(Rt is_runningtstartR&R'(R(trettmsg((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_profile_print_statuss     cCstj|j|jkr=td|j|jjtS|jjr|j |kr|j std|j |jjtS|jjt SntS(NsOperation timed out after waiting %d seconds(s), you may try to increase timeout by using --timeout command line option or using --async.sError changing profile: %s( ttimet _timestampR R1RR[R'RtisSetRRRR(R(R7((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_wait_profiles cCs|jdks|jdkr"dSyH|jj|j}d|_t|dddtjtjjWn tk r}|j dnXdS(NRtendR0sUError: Failed to stop log capture. Restart the Tuned daemon to prevent a memory leak.( RRRtlog_capture_finishR1R2R3tflushRR&(R(tlog_msgsR.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRKs   cCst|dkr|jSdj|}|dkrG|jjtS|jj|j r|j dk r|j dd}|jj |j ||_ n|jj|\}}|js| r|jj|j||Stj|_|jj|j||j||S(Nit Rii(tlent_action_dbus_listtjoinRR[R'RtclearR RRR tlog_capture_startRtswitch_profileRzR{R|RLR~(R(RYR7R,RxRy((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_profiles     cCsRtd|jjdddg\}}|dkrDtdn tddS(NsTrying to (re)start tuned...tserviceRtrestartis#Tuned (re)started, changes applied.sQTuned (re)start failed, you need to (re)start tuned by hand for changes to apply.(R1R texecute(R(RxRy((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_restart_tuneds  !  cCs||jjkrty%|jj|||jtSWqtk rp}|jt||jdt SXn|jd|t SdS(NsUnable to switch profile.s%Requested profile '%s' doesn't exist.( Rtget_known_namesR tsave_active_profileRRRR&RIR'(R(R7RcR.((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt _set_profiles  cCsKt|dkr|jSdj|}|dkr;tS|j|tS(NiRR(RR_RR'RR(R(RYR7((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_profiles   cCs|jj}|jj|j rd|jdk rd|jdd}|jj|j||_ n|jj \}}|js| r|jj |j ||St j |_|jj|j||j ||S(Nii(Rtrecommend_profileRRR RRR RRt auto_profileR[RzR{R|RLR~(R(R7R,RxRy((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_auto_profile$s  cCs|jj}|j|tS(N(Rt recommendRR'(R(R7((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_auto_profile4scCs#t|jj|jjtS(N(R1RRR[R(R(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_recommend_profile8scCst|jjtS(N(R1RRR(R(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_recommend_profile<scCs|r|jj}n|jj}|r:tdn<tdtdtdtdtdtdtdtj|jj|S( NsHVerfication succeeded, current system settings match the preset profile.sLVerification failed, current system settings differ from the preset profile.s=You can mostly fix this by restarting the Tuned daemon, e.g.:s systemctl restart tunedtors service tuned restartsNSometimes (if some plugins like bootloader are used) a reboot may be required.s&See tuned log file ('%s') for details.(Rtverify_profile_ignore_missingtverify_profileR1RtLOG_FILER[(R(tignore_missingRx((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_verify_profile@s       cCstdtS(Ns Not supported in no_daemon mode.(R1R'(R(R((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_verify_profileQs cCsVd}|jj|j||_|jj}|sF|jdn|jj|S(NiisCannot disable active profile.i(RRRRtoffR&R[(R(R,Rx((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt_action_dbus_offUs cCstdtS(Ns Not supported in no_daemon mode.(R1R'(R(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt _action_off_s RYcCs6|dkr|jS|dkr2|jd|SdS(sDPrint 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 RYtpluginstverboseN(R\t_action_dbus_list_plugins(R(t list_choiceR((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRcs   cCs6|dkr|jS|dkr2|jd|SdS(saPrint 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 RYRRN(R_t_action_list_plugins(R(RR((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyt _action_listqs   cCs|jj}x|jD]}t|| st||dkrOqn|jj|}xI||D]=}td||j|d}|rltd|qlqlWqW|jjt S(svPrint accessible plugins Keyword arguments: verbose -- if is set to True then parameters and hints are printed is %ss %sN( Rt get_pluginstkeysR1Rtget_plugin_hintstgetRR[R(R(RRtpluginthintst parameterthint((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRs cCstdtS(Ns Not supported in no_daemon mode.(R1R'(R(R((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRs (/t__name__t __module__RR'Rt ADMIN_TIMEOUTtloggingtERRORR/R&R%RDRQRWR\R_RaRdRgRiRjRnRoRZR^RqRtRuRzR~RKRRRRRRRRRRRRRRRR(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyRsR                           (t __future__Rt tuned.adminRttuned.utils.commandsRttuned.profilesRR t exceptionsRttuned.exceptionsRt tuned.constsRttuned.utils.profile_recommenderRR:R2R@R{RRtobjectR(((s5/usr/lib/python2.7/site-packages/tuned/admin/admin.pyts