}κ^c@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z dZ e fZ eaeadaiadadaeadadadadaeaeaeZd Z d Z!d Z"d Z#d Z$dZ%dZ&dZ'dZ(dddYZ)dej*fdYZ+dZ,e-dkre,ndS(s| B{FastestMirror} is a Yum plugin which sorts each repository's mirrorlist according to connection speed prior to download. iN(t TYPE_COREs2.5iti icCst|dr|jdn|jdddta|jdddta|jdddda|j dd dd a |jdd dd a |jdd dd a |j dddda|j dddda|j dddda|jdddtadS(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_timeoutit hostfilepatht timedhoststmaxhostfileagei t maxthreadstexcludet include_onlytprefersno.prefer.mirrort downgrade_ftpN(thasattrRtconfBooltFalseRtTrueRtconfIntRt confStringRR R tNoneR R RR(tconduit((s%/usr/lib/yum-plugins/fastestmirror.pyt init_hookHs  cCstr0tddkr0|jjjdtantjjtr|jddytjtWqt k r}|jdd|qXndS(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|jddjddS(NRit@i(tsplit(tmirror((s%/usr/lib/yum-plugins/fastestmirror.pytscCsJtjj|s7yttd}tSWq7tSXntj|tjS(Ntw( RRRtfileRRRtaccesstW_OK(tfnamethostfile((s%/usr/lib/yum-plugins/fastestmirror.pyt_can_write_resultsscCs:d}x-|D]%}|jdr(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_ftps  c s_tr0tddkr0jjjdtantjjtrZttkrZt a nj \}}jjj st t rdStrjddn0t rjddtnjddi}j}g}xu|jD]g}|jtkrqntr6t|jdkr6qnt|jdkrQqn|j|jqWt|j}x|jD]}|jtkrqntrt|jdkrt|jd t |_qnt|jdkrqnt||kr't|jj|t|R?tlvl((Rs%/usr/lib/yum-plugins/fastestmirror.pytprereposetup_hooksn!   "&& 0   cCskyStt}x6|jD](}|j\}}t|t|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::1Rit:is * %s : deadlg]N(R8R RRRUtAF_INETt SOCK_STREAMtstringtfindtintRRetconnectRbRRR'(RpRtsocktuPortt time_before((s%/usr/lib/yum-plugins/fastestmirror.pytruns*      (RRRRqR(((s%/usr/lib/yum-plugins/fastestmirror.pyRs cCsgtattjdkr;dtjdGHtjdntjd}dtt|jGHdS(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 [mirror2] ... [mirrorN]iisResult: N( RRRJtsystargvtexitRORLRM(Rm((s%/usr/lib/yum-plugins/fastestmirror.pyRs  t__main__((.RRRReRURRRgRsR6t yum.pluginsRtrequires_api_versiont plugin_typeRRRRRR RR RBR RR R RRRTtsetRERR$R8R/R4R_RFRWRARLRRRR(((s%/usr/lib/yum-plugins/fastestmirror.pyt(sP            (   d   ~G