ó æ ”\c@s—ddlZddlZddlZddlZddlZddljZddlZddl Tddl m Z ej j ƒZddd„ƒYZdS(iÿÿÿÿN(t*(tTunedExceptiontcommandscBsšeZed„Zd„Zd„Zd„Zd„Zd„Zddd„Z dd„Z d „Z d „Z d „Z d(d d „Zd(d„Zeed„Zded„Zed„Zed„Zed„Zed„Zd„Zd„Zed„Zed„Zed(iged„Zed„Zd„Zd„Zd„Z d„Z!d „Z"d!„Z#d"„Z$d#„Z%d$„Z&d%„Z'd&„Z(d'„Z)RS()cCs ||_dS(N(t_logging(tselftlogging((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt__init__scCs|jrtj|ƒndS(N(Rtlogterror(Rtmsg((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt_errors cCs|jrtj|ƒndS(N(RRtdebug(RR ((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt_debugs cCs`t|ƒjƒjƒ}idd6dd6dd6dd6dd6dd6dd 6dd 6j||ƒS( Nt1tYtYEStTtTRUEt0tNtNOtFtFALSE(tstrtuppertstriptget(Rtvaluetv((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytget_boolscCstjddt|ƒƒjƒS(Ns\s+t (tretsubRR(Rts((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt remove_wsscCstjdd|ƒS(Ns^"(.*)"$s\1(RR (RR((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytunquote!ss\cCs|j|d||fƒS(Ns%s%s(treplace(RR!t what_escapet escape_by((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytescape%scCs|j|dƒS(Nt(R$(RR!t escape_char((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytunescape)scCs|d|t|ƒ|S(NR(tlen(Rts1tposts2((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt align_str-scCsFg}|dk rBx-t|jƒƒD]}|t|ƒ7}q%Wn|S(N(tNonetsortedtitemstlist(Rtdtlti((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt dict2list3s  cCs6|dkrdStjddjt|jƒƒƒƒS(Ns(%s)s)|((R0RtcompiletjoinR3tkeys(RR4((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytre_lookup_compile;s ics{ˆdkr|dkrA|Sn"tˆƒdks=|dkrA|S|dkr_|jˆƒ}n|j‡fd†||ƒS(Nicstˆjƒƒ|jdS(Ni(R3tvaluest lastindex(tmo(R4(s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytLs(R0R+R;R (RR4R!trtflags((R4s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytmultiple_re_replaceCs   cCstt|ƒdks|dkr"dS|dkr@|j|ƒ}n|j|ƒ}|rpt|jƒƒ|jdSdS(Nii(R+R0R;tsearchR3R<R=(RR4R!R@R>((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt re_lookupRs c Csß|jd||fƒ|rMtjj|ƒ}tjj|ƒrMt}qMnyL|rftj|ƒnt|dƒ}|jt |ƒƒ|j ƒt }Wn?t t fk rÚ}t}|sÛ|jd||fƒqÛnX|S(NsWriting to file: '%s' < '%s'tws Writing to file '%s' error: '%s'(R tostpathtdirnametisdirtFalsetmakedirstopentwriteRtclosetTruetOSErrortIOErrorR ( Rtftdatatmakedirtno_errorR4tfdtrcte((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt write_to_file\s"   R(cCs†|}y)t|dƒ}|jƒ}|jƒWn9ttfk rj}|sk|jd||fƒqknX|jd||fƒ|S(NR@s"Error when reading file '%s': '%s's Read data from file: '%s' > '%s'(RLtreadRNRPRQR R (RRRterr_retRUt old_valueRX((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt read_fileos cCs{|jd|ƒtjj|ƒrwytj||ƒWqwtk rs}|sotjd|t |ƒfƒnt SXnt S(NsRemoving tree: '%s'scannot remove tree '%s': '%s'( R RFRGtexiststshutiltrmtreeRPRRRRJRO(RRRRUR((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyR`{s cCsx|jd|ƒtjj|ƒrtytj|ƒWqttk rp}|sltjd|t|ƒfƒnt SXnt S(NsRemoving file: '%s'scannot remove file '%s': '%s'( R RFRGR^tunlinkRPRRRRJRO(RRRRUR((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyRa†s cCso|jd||fƒytj||ƒWn=tk rj}|sftjd||t|ƒfƒntSXtS(NsRenaming file '%s' to '%s's%cannot rename file '%s' to '%s': '%s'( R RFtrenameRPRRRRJRO(RtsrctdstRUR((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyRb‘s#cCsmy/tjd||fƒtj||ƒtSWn7tk rh}|sdtjd|||fƒntSXdS(Nscopying file '%s' to '%s's!cannot copy file '%s' to '%s': %s(RR R_tcopyRORQRRJ(RRcRdRURX((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyRe›scCsM|j|ƒ}t|ƒdkr%tS|j|tj|||dtjƒƒS(NiRA(R]R+RJRYRR t MULTILINE(RRRtpatterntreplRS((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytreplace_in_file¥scCsJ|j|ƒ}t|ƒdkr%tS|j||j||dtjƒƒS(NiRA(R]R+RJRYRBRRf(RRRR4RS((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytmultiple_replace_in_file­scCsò|j|ƒ}xÐ|D]È}t|ƒ}t||ƒ}tjd|d|dtjƒdkr°|rÞt|ƒdkr–|ddkr–|d7}n|d||f7}qÞqtjd|d d |d |dtjƒ}qW|j||ƒS( Ns\bs\s*=.*$RAiiÿÿÿÿs s%s="%s" s\b(s\s*=).*$s\1s"s\1"( R]RRRCRfR0R+R RY(RRRR4taddRStopttoR((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytadd_modify_option_in_file·s  )" 2cCs|jtj|ƒjƒS(N(R]tconststMACHINE_ID_FILER(RRU((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytget_machine_idÇscCs¿d}tjjƒ}d|d<|j|ƒ|jdt|ƒƒd} d} yÉt|dtdtd|d |d |d t d t ƒ} | j ƒ\} } | j }|r||krd|kr| d } t | ƒdkrê| d } nd|d| f} |s|j | ƒqnWnƒttfk r}|jdk rI|j nd }t|ƒ|kržd|kržd|d|f} |sš|j | ƒqšqžnX|r±|| | fS|| fSdS(NitCtLC_ALLs Executing %s.R(tstdouttstderrtenvtshelltcwdt close_fdstuniversal_newlinesiÿÿÿÿsExecuting %s error: %s(RFtenvironRetupdateR RR0tPopentPIPEROt communicatet returncodeR+R RPRQterrnotabs(RtargsRwRxRvt no_errorst return_errtretcodet _environmenttoutterr_msgtprocterrterr_outRX((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytexecuteÍs>        cCs=tjd|ƒ}|r%|jdƒS|r9|jƒdS|S(Ns.*\[([^\]]+)\].*ii(Rtmatchtgrouptsplit(Rtoptionstdosplittm((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytget_active_optionôs  cCs;t|ƒ}|dkp:|jd|dtƒjƒdkS(NRs$/sys/devices/system/cpu/cpu%s/onlineRUR (RR]ROR(Rtcputscpu((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt is_cpu_onlineýs cCst|dkrdSt|ƒjddƒ}yt|dƒ}Wn)tk rftjdt|ƒƒgSX|j|ƒS(Nt,R(isinvalid hexadecimal mask '%s'(R0RR$tintt ValueErrorRRtbitmask2cpulist(RtmaskR“((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt hex2cpulists  cCsQd}g}x>|dkrL|d@r5|j|ƒn|dL}|d7}qW|S(Nii(tappend(RRœR•tcpus((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyR›s  c Csèg}|dkr|St|ƒtkr1|}nt|ƒjdƒ}g}g}t}d}xW|D]O}t|ƒ} |r¸t| ƒdkr«t}|j|ƒd}q´|| 7}qe| dd!jƒdkràt }| }qe| r’| ddks| ddkr’| djd ƒ} yat| ƒdkrb|tt t | dƒt | dƒdƒƒ7}n|jt | dƒƒWq´t k rŽgSXqet| ƒdkre|j| ƒqeqeWt|ƒdkrÚ|j|ƒnxÂ|D]º}|jd ƒ} |dd!jƒdkr%||j |ƒ7}qáyat| ƒdkrn|tt t | dƒt | dƒdƒƒ7}n|jt | dƒƒWqát k ršgSXqáWttt|ƒƒƒ} x*|D]"} | | kr¾| j| ƒq¾q¾W| S( NR˜R(iit0xt^t!it-(R0ttypeR3RRRJR+RžtlowerROtrangeR™RšRR1tsettremove(RR5trltlltll2t negation_listthexmaskthvRtsvtnltvltcpu_listR•((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytcpulist_unpacksd        &    4    cCs?|j|ƒ}|dks-t|ƒdkr1|Sd}|}g}xœ|dt|ƒkrá||d||dkrÔ||kr°|jt||ƒdt||ƒƒn|jt||ƒƒ|d}n|d7}qFW|dt|ƒkr$|jt||ƒdt|dƒƒn|jt|dƒƒ|S(NiiR£iÿÿÿÿ(R³R0R+RžR(RR5R6tjR©((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt cpulist_packbs" , ,cCsA|j|ƒ}|j|jdƒƒ}tt|ƒt|ƒƒS(Ns/sys/devices/system/cpu/online(R³R]R3R§(RR5RŸtonline((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytcpulist_invertxscs·|dkrdS|j|ƒ}|dkr/dS|j|ƒ}d|‰tˆƒ}|ddkry|d|d7}nˆj|ƒ‰dj‡fd†tdtˆƒdƒDƒƒS(Ns%xiiR˜c3s |]}ˆ||d!VqdS(iN((t.0R6(R!(s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pys Šs(R0R³tcpulist2bitmaskR+tzfillR9R¦(RR5tulR“tls((R!s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyt cpulist2hex~s    cCs.d}x!|D]}|td|ƒO}q W|S(Nii(tpow(RR5R“R((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyR¹Œs cCs,y|j|tƒSWn|j|ƒSXdS(N(twaitRJ(Rt terminatettime((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyR¿•scCsñt|ƒjƒjƒ}xÒddddgD]¾}|j|ƒ}|dkrRq+ny‚t|| ƒ}||}|dkrˆ|d9}nG|dkr¡|d9}n.|dkrº|d 9}n|dkrÏd}n|SWq+tk rèdSXq+WdS( NtKBtMBtGBR(iÿÿÿÿiiii@(RRRtrfindR™R0Rš(RR!tunittunit_ixtvaltu((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytget_size›s&           c Cs¨d}d}y1ttjdƒ}|jƒjƒ}WdQXWn`tk rw}|jtjkr td|ƒ‚q n)t t fk rŸ}td|ƒ‚nXybttj dƒJ}|jƒjƒ}|dtj tj gkrûtdtj ƒ‚nWdQXWn`tk r<}|jtjkretd|ƒ‚qen)t t fk rd}td|ƒ‚nX|dkrzd}n|tj k}|dkržd}n||fS(NR(R@s!Failed to read active profile: %ssInvalid value in file %s.sFailed to read profile mode: %s(RLRotACTIVE_PROFILE_FILERZRRQRtENOENTRRPtEOFErrortPROFILE_MODE_FILEtACTIVE_PROFILE_AUTOtACTIVE_PROFILE_MANUALR0(Rt profile_nametmodeRRRXtmanual((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytget_active_profile°s4     cCséy?ttjdƒ'}|dk r8|j|dƒnWdQXWn,ttfk rm}td|jƒ‚nXyHttj dƒ0}|r•tj ntj }|j|dƒWdQXWn,ttfk rä}td|jƒ‚nXdS(NREs s!Failed to save active profile: %ssFailed to save profile mode: %s( RLRoRËR0RMRPRQRtstrerrorRÎRÐRÏ(RRÑRÓRRRXRÒ((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pytsave_active_profileÍs N(*t__name__t __module__RORR R RR"R#R'R*R/R7R;R0RBRDRJRYR]R`RaRbReRiRjRnRqRR”R—RR›R³RµR·R½R¹R¿RÊRÔRÖ(((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyR sJ              '   C      ((Rt tuned.logsttunedReRFR_t tuned.constsRoRt subprocessttuned.exceptionsRtlogsRRR(((s8/usr/lib/python2.7/site-packages/tuned/utils/commands.pyts