HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/softwareproperties/__pycache__/MirrorTest.cpython-38.pyc
U

��d�@sNddlZzddlmZmZWn$ek
r@ddlmZmZYnXddlZddlZddlZddlZddl	Z
ddlZ
zddlm
Z
Wn ek
r�ddlm
Z
YnXddlZGdd�dej�Zedk�rJe
j��Ze�e
j���e�d�Ze����Ze��Ze��dej j!ej j"dj!efZ#ee$ej j%�&��e#e��e�Z'e'�(�dS)	�N)�Empty�Queue)�urlopenc@sbeZdZdZGdd�dej�Zddd�Zdd�Zddd�Z	d
d�Z
ddd�Zddd�Zdd�Z
dS)�
MirrorTestz@Determines the best mirrors by perfoming ping and download test.c@s"eZdZdZd	dd�Zdd�ZdS)
zMirrorTest.PingWorkerz�Use the command line command ping to determine the server's
           response time. Using multiple threads allows to run several
           test simultaneously.�r��rrcCs@||_||_||_||_||_||_t�d�|_t	j
�|�dS)Nz^rtt .* = [\.\d]+/([\.\d]+)/.*)�borders�mod�parent�id�jobs�results�re�compile�match_result�	threading�Thread�__init__)�selfr
rrrr	r
�r�?/usr/lib/python3/dist-packages/softwareproperties/MirrorTest.pyrszMirrorTest.PingWorker.__init__cCsd}|j���s|jj���rzh|j�d�}|j}|j�d|�tj	ddddd|gtj
tjdd	�j}|�
�}|stq�t�|j|�}qfWn0tk
r�YdS|j�d
|�YnXtj��tjd7_|j�tjtj|j|j�|�r
|j�t|d�||g�tj��qdS)
NFz
Pinging %s...Zpingz-qz-c 2z-W 1z-i 0.5T)�stdout�stderrZuniversal_newlineszSkipping %srr)r
�emptyr�running�isSet�get�hostname�
report_action�
subprocess�Popen�PIPEZSTDOUTr�readliner�findallrrr�completed_lock�acquire�	completed�report_progress�todor	r
r�append�float�release)r�result�mirrorZhostZcommando�linerrr�run#s:�

�zMirrorTest.PingWorker.runN)rr)�__name__�
__module__�__qualname__�__doc__rr0rrrr�
PingWorkers
	r5NcCsjtj�|�d|_d|_||_d|_||_g|_dt	_
t��t	_t
|�t	_||_|s`t��|_n||_dS)N�)rrgr)rrr�action�progress�event�best�	test_file�threadsrr'ZLockr%�lenr)�mirrors�Eventr)rr>r;r9rrrrrCs

zMirrorTest.__init__cCs||_|jr|j��dS)N)r7r9�set)r�textrrrrTszMirrorTest.report_action�r�drcCsL||d||d|d|d|d||f|_|jrH|j��dS)zTSubclasses should override this method to receive
           progress status updatesrrN)r8r9r@)rZcurrent�maxr	r
rrrr(Ys

�zMirrorTest.report_progressc
Cs�|jdddd�}t|j�}|dkrf|�dd|jt�d|d�g�|�dd|jt�d|d�g�|jdd	�|D�d
tjtjfd�}|D]\}}t	d|j
|f�q�|s�dS|ddj
}t	d
|�|SdS)N�)r��?)r�)rDr	r
�rrcSsg|]}|d�qS)rHr)�.0�rrrr�
<listcomp>jsz,MirrorTest.run_full_test.<locals>.<listcomp>�rFr)r	r
zmirror: %s - time: %szand the winner is: %s)�
run_ping_testr=r>r*�randomZrandint�run_download_testrr)�printr)rZresults_ping�sizer�t�h�winnerrrr�
run_full_testbs$
""��zMirrorTest.run_full_testrc
	Cs�|dkr|j}t�}|D]}|�|�qg}td�D],}t�||||||�}	|j�|	�|	��q4|jD]}	|	�	�qh|�
�|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)r>rZput�rangerr5r<r*�start�join�sort)
rr>rDr	r
r
�mr�irRrrrrMws


zMirrorTest.run_ping_testc	s��fdd�}|dkr�j}g}|D]N}�j��s4qr||�}|dkrR|�||g���|�|�dt|�d|�q"|��|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.cs`d|��d�jf}��d|�t��}z t|dd��d�t��|WSYdSXdS)Nz%s/%srzDownloading %s...rH)Ztimeouti�)Z
get_repo_urlsr;r�timer�read)r.ZurlrX�rrr�test_download_speed�s�z9MirrorTest.run_download_test.<locals>.test_download_speedNrrrL)r>rrr*r(�indexr=rZ)	rr>rDr	r
r`rr[Z
download_timerr_rrO�s

 zMirrorTest.run_download_testcCs|��|_|j��dS)z/Complete test exercise, set self.best when doneN)rUr:r�clearr_rrrr0�s
zMirrorTest.run)N)rBr)NNrr)NNrr)r1r2r3r4rrr5rrr(rUrMrOr0rrrrrs-

	
�
r�__main__zdpkg --print-architecturez!dists/%s/%s/binary-%s/Packages.gz))rZqueuerr�ImportErrorr]rr �osZaptsources.distroZ
aptsourcesZaptsources.sourceslistZurllib.requestrZurllib2rNrrr1ZdistroZ
get_distroZget_sourcesZsourceslistZSourcesList�popen�piper^�stripZarchr?rr@Zsource_template�nameZ
componentsr;�listZ
mirror_set�valuesZapprUrrrr�<module>sH


���