Spade
Mini Shell
| Directory:~$ /proc/self/root/lib/yum-plugins/ |
| [Home] [System Details] [Kill Me] |
�
}κ^c@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
mZdZefZ
eaeadaiadadaeadadadadaeaeae�Zd �Z
d
�Z!d�Z"d�Z#d
�Z$d�Z%d�Z&d�Z'd�Z(ddd��YZ)dej*fd��YZ+d�Z,e-dkr�e,�ndS(s|
B{FastestMirror} is a Yum plugin which sorts each repository's
mirrorlist
according to connection speed prior to download.
i����N(t TYPE_COREs2.5iti
icCst|d�r|jd�n|jdddt�a|jdddt�a|jdddd�a|j dd dd
�a
|jdddd�a|jdd
dd�a|j dddd�a|j dddd�a|j dddd�a|jdddt�adS(sD
This function initiliazes the variables required for running
B{fastestmirror}
module. The variables are initiliazed from the main section of the
plugin file.
There are no parameteres for this function. It uses global variables to
communicate with other functions.
This function refers:
- L{get_hostfile_age}
@param verbose : Verbosity of output.
@type verbose : Boolean
@param socket_timeout : The default timeout for a socket connection.
@type socket_timeout : Integer
@param hostfilepath : Absolute path to the plugin's cache file.
@type hostfilepath : String
@param maxhostfileage : Maximum age of the plugin's cache file.
@type maxhostfileage : Integer
@param loadcache : Fastest Mirrors to be loaded from plugin's
cache or not.
@type loadcache : Boolean
tregisterPackageNamesyum-plugin-fastestmirrortmaintverbosetdefaulttalways_print_best_hosttsocket_timeoutithostfilepatht
timedhoststmaxhostfileagei
t
maxthreadstexcludetinclude_onlytprefersno.prefer.mirrort
downgrade_ftpN(thasattrRtconfBooltFalseRtTrueRtconfIntRt
confStringRR
RtNoneRR
RR(tconduit((s%/usr/lib/yum-plugins/fastestmirror.pyt init_hookHs cCs�tr0tddkr0|jjjdtantjjt�r�|jdd�ytjt�Wq�t k
r�}|jdd|�q�XndS(s�
This function cleans the plugin cache file if exists. The function is
called
when C{yum [options] clean [plugins | all ]} is executed.
it/is#Cleaning up list of fastest mirrorssCleanup failed: %sN(
Rt_basetconftcachedirtostpathtexiststinfotunlinkt Exception(Rte((s%/usr/lib/yum-plugins/fastestmirror.pyt
clean_hookpscCs|jd�djd�dS(NRit@i����(tsplit(tmirror((s%/usr/lib/yum-plugins/fastestmirror.pyt<lambda>�scCsJtjj|�s7yttd�}tSWq7tSXntj|tj�S(Ntw( RRRtfileRRRtaccesstW_OK(tfnamethostfile((s%/usr/lib/yum-plugins/fastestmirror.pyt_can_write_results�scCs:d}x-|D]%}|jd�r(q
n|d7}q
W|S(s-
Count the number of urls, which aren't ftp. isftp:i(t
startswith(turlstnumturl((s%/usr/lib/yum-plugins/fastestmirror.pyt_len_non_ftp�s
c
s_tr0tddkr0�jjjdtantjjt�rZt�tkrZt a
n�j�\}}�jjjs�t
t�r�dStr��jdd�n0t
r��jdd�t�n�jdd�i}�j�}g}xu|j�D]g}|jtkrq�ntr6t|j�dkr6q�nt|j�dkrQq�n|j|j�q�Wt|�j�}x�|j�D]�}|jtkr�q�ntr�t|j�dkr�t|jd t �|_q�nt|j�dkr�q�nt|�|kr't|j�j�|t|�<ntrb�fd
�}t||t|��|t|�<n;tr��fd�}t||t|��|t|�<n|t|�|_t|j�rd} t
r�d} n�j| d
t|�t!|jd�f�nd|_"|j#�|j$�tj%|j�q�Wt&rKt'j(d�nt
s[t*�ndS(s}
This function is called after Yum has initiliazed all the repository
information.
If cache file exists, this function will load the mirror speeds from
the file,
else it will determine the fastest mirrors afresh and write them back
to the cache
file.
There are no parameteres for this function. It uses global variables to
communicate with other functions.
This function refers:
- L{read_timedhosts()}
- L{FastestMirror.get_mirrorlist()}
- L{write_timedhosts()}
@param loadcache : Fastest Mirrors to be loaded from plugin's
cache file or not.
@type loadcache : Boolean
iRNis"Checking for new repos for mirrorss*Loading mirror speeds
from cached hostfilesDetermining fastest
mirrorsitreversecsLt�fd�tjdd�j��rH�jddt���tStS(Ncstj|t���S(N(tretsearchthost(texp(R'(s%/usr/lib/yum-plugins/fastestmirror.pyR(�st,t
isIncluding mirror: %s(tfilterR
treplaceR&R
R8RR(R'(R(R's%/usr/lib/yum-plugins/fastestmirror.pytincludeCheck�s
csLt�fd�tjdd�j��rH�jddt���tStS(Ncstj|t���S(N(R6R7R8(R9(R'(s%/usr/lib/yum-plugins/fastestmirror.pyR(�sR:R;isExcluding
mirror: %s(R<RR=R&R
R8RR(R'(R(R's%/usr/lib/yum-plugins/fastestmirror.pytexcludeCheck�s
is * %s: %stpriority(+RRRRRRRtget_hostfile_ageR
Rt loadcachet
getCmdLinetcacheR/t
done_reposR
tread_timedhoststgetRepostlistEnabledtidRR4R1tlentextendt
FastestMirrortget_mirrorlisttsortedtstrR
R<RRR8tfailovermethodtcheckt setupGrabtaddtdone_sock_timeouttsockettsetdefaulttimeoutRtwrite_timedhosts(
Rtoptstcommandstrepomirrorstrepostall_urlstrepoR>R?tlvl((Rs%/usr/lib/yum-plugins/fastestmirror.pytprereposetup_hook�sn!
"&& 0
cCskyStt�}x6|j�D](}|j�\}}t|�t|<qW|j�Wntk
rfnXdS(s�
This function reads the time and hostname from the plugin's cache
file and
store them in C{timedhosts}.
There are no parameteres for this function. It uses global variables to
communicate with other functions.
This function is referred by:
- L{prereposetup_hook()}
@param timedhosts : A list of time intervals to reach different hosts
corresponding to the mirrors. The index of the list are hostnames.
C{timedhosts[host] = time}.
@type timedhosts : List
N(R*Rt readlinesR&tfloatR tclosetIOError(R.tlineR8ttime((s%/usr/lib/yum-plugins/fastestmirror.pyRF�s
cCsayIttd�}x)tD]!}|jd|t|f�qW|j�Wntk
r\nXdS(s�
This function writes the plugin's cache file with the entries in
the
C{timedhosts} list.
There are no parameteres for this function. It uses global variables to
communicate with other functions.
This function is referred by:
- L{prereposetup_hook()}
@param timedhosts : A list of time intervals to reach different hosts
corresponding to the mirrors. The index of the list are hostnames.
C{timedhosts[host] = time}.
@type timedhosts : List
R)s%s %s
N(R*RR twriteRbRc(R.R8((s%/usr/lib/yum-plugins/fastestmirror.pyRWs
cCs2tjjtjjt��}tjj�|jS(s�
This function returns the current age of the plugin's cache file.
There are no parameteres for this function. It uses global variables to
communicate with other functions.
This function is referred by:
- L{init_hook()}
@param hostfilepath : Absolute path to the plugin's cache file.
@type hostfilepath : String
@rtype: Integer
@return: The age of the plugin's cache file.
(tdatetimet
fromtimestampRRtgetmtimeRtnowtdays(t timestamp((s%/usr/lib/yum-plugins/fastestmirror.pyRA,sRLcBsMeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z RS(s�
This is the helper class of B{fastestmirror} module. This class does
all the processing of the response time calculation for all the mirrors
of all the enabled Yum repositories.
cCs||_i|_g|_dS(s�
This is the initiliazer function of the B{L{FastestMirror}} class.
@param mirrorlist : A list of mirrors for an enabled repository.
@type mirrorlist : List
N(t
mirrorlisttresultstthreads(tselfRm((s%/usr/lib/yum-plugins/fastestmirror.pyt__init__Fs cCs8t|d�s4tj�|_tatjt�ndS(Nt
_results_lock( Rt threadingtLockRrRRTRURVR(Rp((s%/usr/lib/yum-plugins/fastestmirror.pyt
_init_lockRscCs#t|d�r|jj�ndS(NRr(RRrtacquire(Rp((s%/usr/lib/yum-plugins/fastestmirror.pyt
_acquire_lockYscCs#t|d�r|jj�ndS(NRr(RRrtrelease(Rp((s%/usr/lib/yum-plugins/fastestmirror.pyt
_release_lock\scCs�|j�tsAg|jj�D]\}}||f^q
}n:g|jj�D]$\}}|jd�||f^qQ}|j�g|D]}|d^q�S(s�
This function pings/polls all the mirrors in the list
C{FastestMirror.mirrorlist} and returns the sorted list of mirrors
according to the increasing response time of the mirrors.
This function refers:
- L{FastestMirror._poll_mirrors()}
This function is referred by:
- L{prereposetup_hook()}
- L{main()}
@rtype: List
@return: The list of mirrors sorted according to the increasing
response time.
tftpi����(t
_poll_mirrorsRRntitemsR0tsort(Rptktvtmirrorstx((s%/usr/lib/yum-plugins/fastestmirror.pyRM`s
17
cCswx#|jD]}t|j�tkrY|jdj�rL|jdj�n|jd=n|jd�rqd}nt|�}|tkr�t|}t r�d||fGHn|j
|||�q
|dddtfkr�|j
||d�q
|j�t
||�}|j�|jj|�q
WxJt|j�dkrr|jdj�re|jdj�n|jd=q)WdS(s
This function uses L{PollThread} class to ping/poll individual
mirror
in parallel.
This function refers:
- L{PollThread.run()}
This function is referred by:
- L{FastestMirror.get_mirrorlist()}
isfile:s 127.0.0.1s%s already timed:
%ss::1t localhostN(RmRJRoRtisAlivetjoinR0R8R Rt_add_resultRRut
PollThreadtstarttappend(RpR'tmhosttresultt
pollThread((s%/usr/lib/yum-plugins/fastestmirror.pyR{{s.
cCsG|j�tr"d||fGHn||j|<|t|<|j�dS(s�
This function is called by L{PollThread.run()} to add details of a
mirror in C{FastestMirror.results} dictionary.
This function is referred by:
- L{PollThread.run()}
@param mirror : The mirror that was polled for response time.
@type mirror : String
@param host : The hostname of the mirror.
@type host : String
@param time : The response time of the mirror.
@type time : Integer
@param timedhosts : A list of time intervals to reach different
hosts
corresponding to the mirrors. The index of the list are hostnames.
@type timedhosts : List
s * %s : %f
secsN(RwRRnR Ry(RpR'R8Re((s%/usr/lib/yum-plugins/fastestmirror.pyR��s
(
t__name__t
__module__t__doc__RqRuRwRyRMR{R�(((s%/usr/lib/yum-plugins/fastestmirror.pyRL?s )R�cBs
eZdZd�Zd�ZRS(s�
B{PollThread} class implements C{threading.Thread} class. This class
provides the functionalities to ping/poll the mirrors in parallel.
cCs�tjj|�||_||_t|�|_tj|�d}|dkr\d|_nQ|dkrtd|_n9|dkr�d|_n!|dkr�d |_n d
|_dS(s1
It is initiliazer function for B{L{PollThread}} class. This
function
initiliazes the service ports for different webservices.
@param parent : The parent class.
@type parent : Class
@param mirror : The mirror of a repository.
@type mirror : String
ithttpiPthttpsi�RziR*s 127.0.0.1i����N(RstThreadRqtparentR'R8turlparsetport(RpR�R'tuService((s%/usr/lib/yum-plugins/fastestmirror.pyRq�s
cCsby#|jtkr=t|j}trd|j|fGHqn�|jdddtfkrad}n�tjtjtj�}tj|jd�}|dkr�t |j|d�|_
|j| |_ntj�}|j|j|j
f�tj�|}|j
�|jj|j|j|�Wn8tr>d|jGHn|jj|j|jd �nXd
S(s�
The C{threading.Thread.run()} function is being overridden here.
This function pings/polls a mirror and add the details of that
mirror to the C{FastestMirror.results} dictionary.
The response time of any mirror is '99999999999' if any
exception
occurs during polling.
This function refers:
- L{FastestMirror._add_result()}
This function is referred by:
- L{FastestMirror._poll_mirrors()}
s%s already timed: %ss 127.0.0.1s::1R�it:is * %s :
deadl�g�]N(R8R RRRUtAF_INETtSOCK_STREAMtstringtfindtintR�RetconnectRbR�R�R'(RpR�tsocktuPortttime_before((s%/usr/lib/yum-plugins/fastestmirror.pytrun�s*
(R�R�R�RqR�(((s%/usr/lib/yum-plugins/fastestmirror.pyR��s cCsgtattj�dkr;dtjdGHtjd�ntjd}dtt|�j��GHdS(s�
This is the main function for B{fastestmirror} module.
This function explains the usage of B{fastestmirror} module. Also
parses
the command line arguments.
This function refers:
- L{FastestMirror.get_mirrorlist()}
is+Usage: %s <mirror1> [mirror2] ...
[mirrorN]ii����sResult:
N( RRRJtsystargvtexitRORLRM(Rm((s%/usr/lib/yum-plugins/fastestmirror.pyRs
t__main__((.R�RR�ReRUR�R�RgRsR6tyum.pluginsRtrequires_api_versiontplugin_typeRRRRRR RR
RBRRRR
RRRTtsetRERR$R8R/R4R_RFRWRARLR�R�RR�(((s%/usr/lib/yum-plugins/fastestmirror.pyt<module>(sP (
d ~G