Ë
    œ¦ëc  ã                   ó6  — d dl Z 	 d dlmZmZ d dlZd dlZd dlZd dlZd dl	Z
d dlZ
	 d dlmZ d dlZ G d„ de j                   «      Zedk(  �r(e
j&                  j)                  «       Zej+                  e
j,                  j/                  «       «        ej0                  d«      Zej5                  «       j7                  «       Z e j:                  «       Zej?                  «        dej@                  jB                  ›d	ej@                  jD                  d    jB                  ›d
e›d�Z# e e$ej@                  jJ                  jM                  «       «      e# e j:                  «       e«      Z'e'jQ                  «        yy# e$ r d dlmZmZ Y �Œww xY w# e$ r
 d dlmZ Y �Œjw xY w)é    N)ÚEmptyÚQueue)Úurlopenc                   óp   — e Zd ZdZ G d„ dej
                  «      Zdd„Zd„ Zdd„Z	d„ Z
dd	„Z	 	 dd
„Zd„ Zy)Ú
MirrorTestz@Determines the best mirrors by perfoming ping and download test.c                   ó   — e Zd ZdZdd„Zd„ Zy)úMirrorTest.PingWorkerz¢Use the command line command ping to determine the server's
           response time. Using multiple threads allows to run several
           test simultaneously.c                 óÊ   — || _         || _        || _        || _        || _        || _        t        j                  d«      | _        t        j                  j                  | «       y )Nz^rtt .* = [\.\d]+/([\.\d]+)/.*)ÚbordersÚmodÚparentÚidÚjobsÚresultsÚreÚcompileÚmatch_resultÚ	threadingÚThreadÚ__init__)Úselfr   r   r   r   r   r   s          ú?/usr/lib/python3/dist-packages/softwareproperties/MirrorTest.pyr   zMirrorTest.PingWorker.__init__   sR   € Ø"ˆDŒLØˆDŒHØ ˆDŒKØˆDŒGØˆDŒIØ"ˆDŒLÜ "§
¡
Ð+LÓ MˆDÔÜ×Ñ×%Ñ% dÕ+ó    c                 óŽ  — d }| j                   j                  «       �sø| j                  j                  j	                  «       �rÒ	 | j                   j                  d«      }|j                  }| j                  j                  d|z  «       t        j                  ddddd|gt        j                  t        j                  d¬	«      j                  }	 |j                  «       }|sn!t        j                  | j                   |«      }Œ4	 t$        j&                  j)                  «        t$        xj*                  dz  c_        | j                  j-                  t$        j*                  t$        j.                  | j0                  | j2                  «       |r*| j4                  j7                  t9        |d   «      |g«       t$        j&                  j;                  «        | j                   j                  «       s'| j                  j                  j	                  «       r�ŒÐy y y y # t"        $ r Y y  | j                  j                  d
z  «       Y �Œ@xY w)NFzPinging %s...Úpingz-qz-c 2z-W 1z-i 0.5T)ÚstdoutÚstderrÚuniversal_newlineszSkipping %sé   r   )r   Úemptyr   ÚrunningÚisSetÚgetÚhostnameÚreport_actionÚ
subprocessÚPopenÚPIPEÚSTDOUTr   Úreadliner   Úfindallr   r   r   Úcompleted_lockÚacquireÚ	completedÚreport_progressÚtodor   r   r   ÚappendÚfloatÚrelease)r   ÚresultÚmirrorÚhostÚcommandoÚlines         r   ÚrunzMirrorTest.PingWorker.run#   sÂ  € ØˆFØ—i‘i—o‘oÕ'¨D¯K©K×,?Ñ,?×,EÑ,EÕ,GðDØ!ŸY™YŸ]™]¨5Ó1�FØ!Ÿ?™?�Dà—K‘K×-Ñ-¨oÀÑ.DÔEÜ)×/Ñ/°¸¸vÀvÈxÐY]Ð0^Ü7A·±Ü7A×7HÑ7HØCGô I÷ JPÉð ð Ø'×0Ñ0Ó2˜Ù#Ø!Ü!#§¡¨D×,=Ñ,=¸tÓ!D˜ð	 ð "ô ×)Ñ)×1Ñ1Ô3Ü×$Ò$¨Ñ)Õ$Ø—‘×+Ñ+¬J×,@Ñ,@Ü,6¯O©OØ,0¯L©LØ,0¯H©Hô6ñ Ø—L‘L×'Ñ'¬¨v°a©yÓ)9¸4ÀÐ(HÔIÜ×)Ñ)×1Ñ1Ô3ð9 —i‘i—o‘oÔ'¨D¯K©K×,?Ñ,?×,EÑ,E×,GÐ'Ð,GÐ'øô ò ÙðDØ—K‘K×-Ñ-¨m¸dÑ.B×Cús   ÁB?H È	IÈ"IN)©r   r   ©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r9   © r   r   Ú
PingWorkerr	      s   „ ñ	#ó	,ó	4r   rA   Nc                 ób  — t         j                  j                  | «       d| _        d| _        || _        d | _        || _        g | _        dt        _
        t        j                  «       t        _        t        |«      t        _        || _        |st        j                   «       | _        y || _        y )NÚ )r   r   g        r   )r   r   r   ÚactionÚprogressÚeventÚbestÚ	test_fileÚthreadsr   r.   ÚLockr,   Úlenr0   ÚmirrorsÚEventr!   )r   rL   rH   rF   r!   s        r   r   zMirrorTest.__init__C   s�   € Ü×Ñ×!Ñ! $Ô'ØˆŒØ#ˆŒØˆŒ
ØˆŒ	Ø"ˆŒØˆŒØ Œ
ÔÜ$-§N¡NÓ$4Œ
Ô!Ü˜g›,Œ
ŒØˆŒÙÜ$Ÿ?™?Ó,ˆD�Là"ˆD�Lr   c                 ó`   — || _         | j                  r| j                  j                  «        y y ©N)rD   rF   Úset)r   Útexts     r   r%   zMirrorTest.report_actionT   s#   € ØˆŒØ�:Š:Ø�J‰J�N‰NÕð r   c                 ó¨   — ||d   z   ||d   z   |d   |d   |d   z
  |z  |z  z   f| _         | j                  r| j                  j                  «        yy)zTSubclasses should override this method to receive
           progress status updatesr   r   N)rE   rF   rP   )r   ÚcurrentÚmaxr   r   s        r   r/   zMirrorTest.report_progressY   sd   € ð ! 3 q¡6Ñ)Ø˜s 1™v™Ø  ™ w¨q¡z°G¸A±JÑ'>À#Ñ&EÈÑ&OÑOðQˆŒð �:Š:Ø�J‰J�N‰NÕð r   c           
      ób  — | j                  ddd¬«      }t        | j                  «      }|dkD  rp|j                  dd| j                  t	        j
                  d|dz
  «         g«       |j                  dd| j                  t	        j
                  d|dz
  «         g«       | j                  |D �cg c]  }|d   ‘Œ	 c}dt        j                  t        j                  f¬	«      }|D ]   \  }}t        d
|j                  ›d|›�«       Œ" |sy |d   d   j                  }t        d|z  «       |S c c}w )Né   )r   ç      à?)r   é   )rT   r   r   é   r   r   ©rW   r   )r   r   zmirror: z	 - time: zand the winner is: %s)Úrun_ping_testrK   rL   r1   ÚrandomÚrandintÚrun_download_testr   r0   Úprintr$   )r   Úresults_pingÚsizeÚrr   ÚtÚhÚwinners           r   Úrun_full_testzMirrorTest.run_full_testb   s  € à×)Ñ)¨a¸ÀuÐ)ÓMˆä�4—<‘<Ó ˆØ�!Š8Ø×Ñ  A t§|¡|´F·N±NÀ1ÀdÈ1ÁfÓ4MÑ'NÐ OÔPØ×Ñ  A t§|¡|´F·N±NÀ1ÀdÈ1ÁfÓ4MÑ'NÐ OÔPØ×(Ñ(¸Ö)E°1¨!¨A«$Ò)EØ19Ü.8¯o©oÜ.8¯o©oð.?ð )ó @ˆð ò 	=‰FˆQ�Ý¨Q¯Z«Z¹Ð;Õ<ð	=áØà˜Q‘Z ‘]×+Ñ+ˆFÜÐ)¨FÑ2Ô3ØˆMùò *Fs   Â.D,c           	      ó‚  — |dk(  r| j                   }t        «       }|D ]  }|j                  |«       Œ g }t        d«      D ]G  }t        j                  |||| ||«      }	| j                  j                  |	«       |	j                  «        ŒI | j                  D ]  }	|	j                  «        Œ |j                  «        |d| S )zõPerforms 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.Né   r   )rL   r   ÚputÚranger   rA   rI   r1   ÚstartÚjoinÚsort)
r   rL   rT   r   r   r   Úmr   Úirc   s
             r   r[   zMirrorTest.run_ping_testw   s·   € ð
 �dŠ?Ø—l‘lˆGÜ‹wˆØò 	ˆAØ�H‰H�Q�Kð	àˆä�r“ò 	ˆAÜ×%Ñ% d¨G°Q¸¸gÀsÓKˆAØ�L‰L×Ñ Ô"Ø�G‰G�Ið	ð
 —‘ò 	ˆAØ�F‰F�Hð	ð 	�‰ŒØ�q˜ˆ~Ðr   c                 óB  ‡ — ˆ fd„}|dk(  r‰ j                   }g }|D ]m  }‰ j                  j                  «       s nQ ||«      }|dkD  r|j                  ||g«       ‰ j	                  |j                  |«      dz   t        |«      d|«       Œo |j                  «        |d| S )zùPerforms 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                 ó  •— | j                  «       d   ›d‰j                  ›�}‰j                  d|z  «       t        j                  «       }	 t	        |d¬«      j                  d«       t        j                  «       |z
  S #  Y yxY w)Nr   ú/zDownloading %s...rY   )Útimeouti � )Úget_repo_urlsrH   r%   Útimer   Úread)r5   Úurlrk   r   s      €r   Útest_download_speedz9MirrorTest.run_download_test.<locals>.test_download_speed”   sv   ø€ Ø#×1Ñ1Ó3°AÓ6Ø!Ÿ^š^ð-ˆCà×ÑÐ2°SÑ8Ô9Ü—I‘I“KˆEðÜ˜ QÔ'×,Ñ,¨VÔ4Ü—y‘y“{ UÑ*Ð*øðÙús   Á2B  Â BNr   r   rZ   )rL   r!   r"   r1   r/   ÚindexrK   rm   )	r   rL   rT   r   r   rx   r   rn   Údownload_times	   `        r   r^   zMirrorTest.run_download_testŽ   s£   ø€ ô		ð �dŠ?Ø—l‘lˆGØˆàò 	TˆAØ—<‘<×%Ñ%Ô'ÙÙ/°Ó2ˆMØ˜qÒ Ø—‘ ¨qÐ1Ô2Ø× Ñ  §¡¨qÓ!1°AÑ!5´s¸7³|ÀXÈsÕSð	Tð 	�‰ŒØ�q˜ˆ~Ðr   c                 ób   — | j                  «       | _        | j                  j                  «        y)z/Complete test exercise, set self.best when doneN)rf   rG   r!   Úclear)r   s    r   r9   zMirrorTest.run¬   s"   € à×&Ñ&Ó(ˆŒ	Ø�‰×ÑÕr   rO   ))r   éd   r;   )NNr:   r;   )r<   r=   r>   r?   r   r   rA   r   r%   r/   rf   r[   r^   r9   r@   r   r   r   r      sE   „ ÙJô+4�Y×%Ñ%ô +4óZ#ò"ó
òó*ð. AFØ#óó<r   r   Ú__main__zdpkg --print-architecturezdists/rr   z/binary-z/Packages.gz))r   Úqueuer   r   ÚImportErrorru   r   r&   ÚosÚaptsources.distroÚ
aptsourcesÚaptsources.sourceslistÚurllib.requestr   Úurllib2r\   r   r   r<   ÚdistroÚ
get_distroÚget_sourcesÚsourceslistÚSourcesListÚpopenÚpiperv   ÚstripÚarchrM   r!   rP   Úsource_templateÚnameÚ
componentsrH   ÚlistÚ
mirror_setÚvaluesÚapprf   r@   r   r   ú<module>r—      si  ðó ð#ß"ó Û 	Û Û 	Û Û ð Ý&ó ô[�×!Ñ!ô [ðz ˆzÓØ×Ñ×)Ñ)Ó+€FØ
×Ñ�z×-Ñ-×9Ñ9Ó;Ô<Øˆ2�8‰8Ð/Ó0€DØ�9‰9‹;×ÑÓ€DØˆi�o‰oÓ€GØ‡K�K…Mà×'Ñ'×,Ó,Ø×'Ñ'×2Ñ2°1Ñ5×:Ó:Úð€Iñ ‘T˜&×0Ñ0×;Ñ;×BÑBÓDÓEØ  	§¡Ó 1°7ó<€Cà×ÑÕð øðW ò #ß"Ò"ð#ûð ò  ßÐð ús"   †E5 §F	 Å5FÆFÆ	FÆF