c6ddlZ ddlmZmZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddlZGddej Zedk(r(e j&j)Zej+e j,j/ej0dZej5j7Zej:Zej?dej@jBd ej@jDdjBd ed Z#ee$ej@jJjMe#ej:eZ'e'jQyy#e$r ddlmZmZYwwxYw#e$r ddlm Z YjwxYw) N)EmptyQueue)urlopencpeZdZdZGddej Zd dZdZd dZ dZ dd Z dd Z d Z y) MirrorTestz@Determines the best mirrors by perfoming ping and download test.ceZdZdZddZdZy)MirrorTest.PingWorkerzUse the command line command ping to determine the server's response time. Using multiple threads allows to run several test simultaneously.c||_||_||_||_||_||_t jd|_tjj|y)Nz^rtt .* = [\.\d]+/([\.\d]+)/.*) bordersmodparentidjobsresultsrecompile match_result threadingThread__init__)selfrrrr r r s ?/usr/lib/python3/dist-packages/softwareproperties/MirrorTest.pyrzMirrorTest.PingWorker.__init__sR"DLDH DKDGDI"DL " +L MD     % %d +cd}|jjs|jjj r |jj d}|j }|jjd|ztjddddd|gtjtjd j} |j}|sn!tj|j |}4 t$j&j)t$xj*d z c_|jj-t$j*t$j.|j0|j2|r*|j4j7t9|d |gt$j&j;|jjs'|jjj ryyyy#t"$rYy|jjd zY@xYw) NFz Pinging %s...pingz-qz-c 2z-W 1z-i 0.5T)stdoutstderruniversal_newlinesz Skipping %sr)remptyr runningisSetgethostname report_action subprocessPopenPIPESTDOUTrreadlinerfindallrrrcompleted_lockacquire completedreport_progresstodor r rappendfloatrelease)rresultmirrorhostcommandolines rrunzMirrorTest.PingWorker.run#sFiioo'DKK,?,?,E,E,GD!YY]]51F!??DKK--o.DE)//vvxY]0^7A7A7H7HCG IJP'002#!!#D,=,=t!D "))113$$)$ ++J,@,@,6OO,0LL,0HH6LL''vay)94(HI))1139iioo'DKK,?,?,E,E,G',G'DKK--md.BCsB?H I"IN)rrrr)__name__ __module__ __qualname____doc__rr9rr PingWorkerr s # , 4rrANcbtjj|d|_d|_||_d|_||_g|_dt_ tjt_ t|t_||_|stj |_y||_y)N)rrgr)rrractionprogresseventbest test_filethreadsrr.Lockr,lenr0mirrorsEventr!)rrLrHrFr!s rrzMirrorTest.__init__Cs!!$' #   "  $-NN$4 !g,  $??,DL"DLrc`||_|jr|jjyyN)rDrFset)rtexts rr%zMirrorTest.report_actionTs# :: JJNN  rc||dz||dz|d|d|dz |z |zzf|_|jr|jjyy)zTSubclasses should override this method to receive progress status updatesrrN)rErFrP)rcurrentmaxr r s rr/zMirrorTest.report_progressYsd!3q6)s1v wqzGAJ'>#&E&OOQ  :: JJNN  rc b|jddd}t|j}|dkDrp|jdd|jt j d|dz g|jdd|jt j d|dz g|j |Dcgc]}|d c}dtjtjf }|D] \}}td |jd |"|sy|ddj}td |z|Scc}w) N)r?)r)rTr r rrrWr)r r zmirror: z - time: zand the winner is: %s) run_ping_testrKrLr1randomrandintrun_download_testrr0printr$)r results_pingsizerrthwinners r run_full_testzMirrorTest.run_full_testbs))au)M 4<<  !8   At||FNN1d1f4M'N O P   At||FNN1d1f4M'N O P(( )E1!A$)E19.8oo.8oo.?)@ =FQ QZZ; < =QZ]++F )F2 3M*Fs. D,c |dk(r |j}t}|D]}|j|g}tdD]G}tj ||||||} |j j| | jI|j D]} | j|j|d|S)zPerforms ping tests of the given mirrors and returns the best results (specified by max). Mod and borders could be used to tweak the reported result if the download test is only a part of a whole series of tests.Nr) rLrputrangerrArIr1startjoinsort) rrLrTr r rmrircs rr[zMirrorTest.run_ping_testws d?llGw A HHQK r A%%dGQgsKA LL   " GGI   A FFH   q~rcBfd}|dk(r j}g}|D]m}jjsnQ||}|dkDr|j||gj |j |dzt |d|o|j|d|S)zPerforms download tests of the given mirrors and returns the best results (specified by max). Mod and borders could be used to tweak the reported result if the download test is only a part of a whole series of tests.c|jddj}jd|ztj} t |dj dtj|z S#YyxYw)Nr/zDownloading %s...rY)timeouti) get_repo_urlsrHr%timerread)r5urlrkrs rtest_download_speedz9MirrorTest.run_download_test..test_download_speedsv#113A6!^^-C   2S8 9IIKE Q',,V4yy{U** s 2BBNrrrZ)rLr!r"r1r/indexrKrm) rrLrTr r rxrrn download_times ` rr^zMirrorTest.run_download_tests  d?llG TA<<%%'/2Mq  q12  q!1A!5s7|Xs S  T  q~rcb|j|_|jjy)z/Complete test exercise, set self.best when doneN)rfrGr!clear)rs rr9zMirrorTest.runs"&&(  rrO))rdr;)NNr:r;)r<r=r>r?rrrArr%r/rfr[r^r9r@rrrrsEJ+4Y%%+4Z#" *.AF#<rr__main__zdpkg --print-architecturezdists/rrz/binary-z /Packages.gz))rqueuerr ImportErrorrurr&osaptsources.distro aptsourcesaptsources.sourceslisturllib.requestrurllib2r\rrr<distro get_distro get_sources sourceslist SourcesListpopenpipervstriparchrMr!rPsource_templatename componentsrHlist mirror_setvaluesapprfr@rrrsi#"   &[!![z z    ) ) +F z--99;< 288/ 0D 99;   DiooG KKM'',,''2215::I T&00;;BBDE  17