ó BOZc@s@ddlZddlZddlZddlZdefd„ƒYZdddgZdd„Zd „Z d „Z d „Z d „Z d „Z ed„Zd„Zedkr<edƒZdZdZdZejƒZx3eeƒD]%ZejeƒZeeeƒ7ZqæWejƒZeeGHeeedGdGHndS(iÿÿÿÿNtRandomDataGeneratorcBsGeZdZd„Zd„Zdd„Zd„Zd„Zd„ZRS(sn A file-like object which generates random data. 1. Never actually keeps all the data in memory so can be used to generate huge files. 2. Actually generates random data to eliminate false metrics based on compression. It does this by generating data in 1MB blocks from np.random where each block is seeded with the block number. cCs[||_d|_d|_d|_d|_tjjdddtj d|jƒ|_ dS(Nitiitdtypetsizei( t bytes_totaltpostNonetcurrent_block_idtcurrent_block_datatBLOCK_SIZE_BYTEStnptrandomtrandinttuint8t block_random(tselfR((s../exampleutils.pyt__init__s     cCsdG|jGH|jS(Nttell(R(R((s../exampleutils.pyRs icCsndGdG|GdG|GH|dkr-||_n=|dkrK|j|7_n|dkrj|j||_ndS(Ntseekspos=swhence=iii(RR(RRtwhence((s../exampleutils.pyR!s    cCs<||jkr|jS||_||jjƒ|_|jS(N(RRRttostring(Rtblock_id((s../exampleutils.pyt get_block*s  cCs(||j}|||j}||fS(N(R (Rtabs_posRtwithin_block_pos((s../exampleutils.pytget_block_coords2s c CsÍ|j|j}|dkr dSt||ƒ}|j}d}d}xs||kr¹||}||}|j|ƒ\} } |j| ƒ} | | | |!} || 7}|t| ƒ7}qGW|j|7_|S(NiR(RRtminRRtlen( Rtbytes_requestedtremaining_bytest bytes_outt start_post byte_datatbyte_posRtbytes_remainingRRtblocktchunk((s../exampleutils.pytread8s"     ( t__name__t __module__t__doc__RRRRRR%(((s../exampleutils.pyRs    s time.mit.edusntp1.net.berkeley.edusntp2.net.berkeley.eduic Csˆddl}|jƒ}g}xct|ƒD]U}y8|j|ddƒ}|j}|j}|j|ƒWq+|jk rq+Xq+W|S(s; Returns a list of offsets for a particular server iÿÿÿÿNtversioni(tntplibt NTPClienttrangetrequesttoffsettdelaytappendt NTPException( tservertattemptsR*tctrestitrR.R/((s../exampleutils.pytget_time_offsetZs    cCs)tjd|tjƒjdƒ}|dS(Ns'.+?(HWaddr\s+(?P\S+))Rthardware_address(tretsearcht MULTILINEt groupdict(tsta((s../exampleutils.pytparse_ifconfig_hwaddrms!cCstjd|tjƒS(Ns".+?inet addr:(?P[\d.]+)(R:tfindallR<(R>((s../exampleutils.pytparse_ifconfig_inetaddrrscCstjdƒ}t|ƒ}|S(Ns/sbin/ifconfig(t subprocesst check_outputR@(t ifconfig_datathwaddr((s../exampleutils.pyt get_hwaddrus cCs1tjdƒ}t|ƒ}t|ƒ}||fS(Ns/sbin/ifconfig(RCRDR@RB(RERFt inet_addr((s../exampleutils.pyt get_ifconfigzs  cCs@tdƒjƒjƒ}|jƒ\}}t|ƒt|ƒfS(Ns /proc/uptime(topenR%tstriptsplittfloat(t uptime_strtup_strtidle_str((s../exampleutils.pyt get_uptime€scCsDg|jƒD]3\}}it|ƒd6t|ƒd6|d6^q S(s4 create an attributes list from a dictionar tNametValuetReplace(t iteritemststr(tdtreplacetktv((s../exampleutils.pytdict_to_sdb_attr†scCsd„|DƒS(NcSs!i|]}|d|d“qS(RSRR((t.0R?((s../exampleutils.pys s ((tattrs((s../exampleutils.pytsdb_attr_to_dictŽst__main__ii i€–˜ig€„.AsMB/secii@(tnumpyR ttimeR:RCtobjectRt NTP_SERVERSR8R@RBRGRIRQtFalseR[R^R&trdgt read_sizet read_countt bytes_readtt1R,R7R%R?Rtt2(((s../exampleutils.pyts6    P