3 À<×eFã@sHdgZddlZddlTddlZejjƒZGdd„dƒZdd„Z ie _ dS)ÚethcardéN)Ú*c@s~eZdZddgddgddgddgdd gd d œZd Zd d„Zdd„Zdd„Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dS) ÚNettooléééééé ri€ié?)é édièiÄ i'ÚautoFcCsb||_|jƒtjd||j|j|j|jfƒtjd||j|j fƒtjd||j |j fƒdS)Nz1%s: speed %s, full duplex %s, autoneg %s, link %sz"%s: supports: autoneg %s, modes %sz$%s: advertises: autoneg %s, modes %s) Ú _interfaceÚupdateÚlogÚdebugÚspeedÚ full_duplexÚautonegÚlinkÚsupported_autonegÚsupported_modesÚadvertised_autonegÚadvertised_modes)ÚselfÚ interface©rú/usr/lib/python3.6/nettool.pyÚ__init__s  zNettool.__init__cCs4d|_d|_d|_d|_g|_d|_g|_d|_dS)NrF)rrrrrrrr)rrrrÚ _clean_status"szNettool._clean_statuscCs8d}x.|D]&}||j|d|dr(dnd7}q W|S)Nrr)Ú_advertise_values)rZmodesÚmodeÚmrrrÚ_calculate_mode.s &zNettool._calculate_modecCs<|j|krdS|jsdSdtdd|jd|r.dndgdd kS) NTFrÚethtoolz-srÚonZoff)Ú close_fds)rrÚcallr)rÚenablerrrÚ_set_autonegotiation5s  zNettool._set_autonegotiationcCs.|jdƒsdSdtdd|jdd|gddkS) NTFrr%z-sZ advertisez0x%03x)r')r*r(r)rÚvaluerrrÚ_set_advertise>s zNettool._set_advertisecCs<d}x"|jD]}|d|kr |d}q W|dkr4|SdSdS)Nriè)r)rÚmaxr"rrrÚ get_max_speedDs  zNettool.get_max_speedcCs6|js|j rdS|j|jdƒr.|jƒdSdSdS)NFrT)Ú _disabledrr,r!r)rrrrÚ set_max_speedNs zNettool.set_max_speedcCs |js|j rdSd}xD|jD]:}|dkr,q||kr||j|d7}||j|d7}qW||j|jƒ@}tjd|j||fƒ|j|ƒr˜|j ƒdSdSdS)NFrrrz)%s: set_speed(%d) - effective_mode 0x%03xT) r/rr!r$rrrrr,r)rrr"ZamZeffective_moderrrÚ set_speedYs  zNettool.set_speedc Cs"|jr dStd|jgttddd}tddg|jtddd}|jƒd}|jƒd}|d kr˜tjd |jƒtjd |j|j d d ƒfƒ|j ƒd|_dS|j ƒt j dƒ}t j dƒ}d}xb|j d ƒD]R}|jdƒrj|dd)…} | dkròd}nt| dkrd}nd| dkrd}nT| dkr"d}nD| dkr2d}n4| dkrBd}n$| dkrRd}n| d krbd!}nd}~ qÆ|dkr¤y|j|ƒjdƒ|_Wnd"|_YnXd}qÆ|dkr¾|d#k|_d}qÆ|dkrâ|d$kpØ|d%k|_d}qÆ|dkrü|d$k|_d}qÆ|dkrnyLx@|j ƒD]4} |j| ƒjdd&ƒ\} } |jjt| ƒ| d#kfƒqW~ ~ ~ Wn|jjd*ƒYnXqÆ|dkrˆ|d'k|_d}qÆ|dkryV|d(kræx@|j ƒD]4} |j| ƒjdd&ƒ\} } |jjt| ƒ| d#kfƒq¨W~ ~ ~ Wn|jjd+ƒYnXqÆ|d!krÆ|d'k|_d}qÆWdS),Nr%T)ÚstdoutÚstderrr'Úuniversal_newlinesZsedzs/^\s*//;s/:\s*/:\n/g)Ústdinr2r4r'rrÚz*%s: some errors were reported by 'ethtool'z%s: %sÚ z\nz(\d+)z(\d+)baseT/(Half|Full)Úwaitú:ZSpeedrZDuplexZduplexzAuto-negotiationrz Link detectedrzSupported link modesrzSupports auto-negotiationrzAdvertised link modesrzAdvertised auto-negotiationréèZFullÚyesr&rZYesz Not reportedéÿÿÿÿ)r:T)r:T)r/ÚPopenrÚPIPEr2Z communicaterZwarningrÚreplacer ÚreÚcompileÚsplitÚendswithÚmatchÚgrouprrrrrÚappendÚintrrr) rZ p_ethtoolZp_filterÚoutputÚerrorsZre_speedZre_modeÚstateÚlineZsectionr#ÚsÚdrrrrns                              zNettool.updateN)Ú__name__Ú __module__Ú __qualname__r!r/rr r$r*r,r.r0r1rrrrrr s      rcCs"|tjkrt|ƒtj|<tj|S)N)rÚlistr)rrrrrÐs ) Ú__all__Z tuned.logsZtunedÚ subprocessr@ZlogsÚgetrrrrQrrrrÚs H