łň
	Fc           @   sQ  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d  d k	 Z	 d  d k
 Z
 d  d k Z e
 i d  d e  i f d     YZ e d j o e i i   Z e i e i    e i d  Z e i   i   Z d e i i e i i d	 i e f Z e e i i i   e  Z e i    n d S(
   i˙˙˙˙N(   t   Timeri   t
   MirrorTestc           B   s~   e  Z d  Z d e i f d     YZ d d  Z d   Z d   Z	 d d d  Z
 d d d d d
  Z d d d d d  Z RS(   s@   Determines the best mirrors by perfoming ping and download test.t
   PingWorkerc           B   s&   e  Z d  Z d d d  Z d   Z RS(   s˘   Use the command line command ping to determine the server's
           response time. Using multiple threads allows to run several
           test simultaneously.i    i   c         C   s\   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ t i d  |  _ t	 i
 i |   d  S(   Ns   ^rtt .* = [\.\d]+/([\.\d]+)/.*(   t   borderst   modt   parentt   idt   jobst   resultst   ret   compilet   match_resultt	   threadingt   Threadt   __init__(   t   selfR   R   R   R   R   R   (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR      s    						c         C   sI  d  } x<t i t i j  o(|  i i i   oy" |  i i t	 d  } | i
 } Wn
 q	 n X|  i i d |  t i d | d  } x9 t	 o1 | i   } | p Pn t i |  i |  } q Wt i i   t i d 7_ |  i i t i t i |  i |  i  | o' |  i i t | d  | | g  n t i i   q	 Wd  S(   Ni   s   Pinging %s...s   ping -q -c 2 -W 1 -i 0.5 %st   ri    (   t   NoneR   t	   completedt   todoR   t   runningt   isSetR   t   gett   Truet   hostnamet   report_actiont   ost   popent   readlineR	   t   findallR   t   completed_lockt   acquiret   report_progressR   R   R   t   appendt   floatt   release(   R   t   resultt   mirrort   hostt   commandot   line(    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyt   run   s6     	 
'(   i    i   (   i    i    (   t   __name__t
   __module__t   __doc__R   R)   (    (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR      s   	c         C   sy   t  i i |   | |  _ g  |  _ d t _ t  i   t _ t	 |  t _
 | |  _ | p t  i   |  _ n
 | |  _ d  S(   Ni    (   R   R   R   t	   test_filet   threadsR   R   t   LockR   t   lenR   t   mirrorst   EventR   (   R   R1   R-   R   (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR   6   s    				c         C   sT   |  i  d d  } |  i t d   |   } x  | D] \ } } | i G| GHq4 Wd S(   s   Run a test of the mirror test.t   maxi
   c         S   s   |  d  S(   i   (    (   R   (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyt   <lambda>F   s    N(   t   run_ping_testt   run_download_testt   mapR   (   R   t   results_pingR   t   tt   h(    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyt   run_full_testC   s
     c         C   s	   | GHd S(   s_   Should be used by all sub test to collect action status messages
           in a central place.N(    (   R   t   text(    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR   J   s    i    id   c         C   s#   d | | d | | d f GHd S(   sZ   Should be used by all sub test to collect progress messages
           in a central place.s   Completed %s of %si    i   N(    (   R   t   currentR3   R   R   (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR    O   s    i   c   
   
   C   sĚ   | d j o |  i } n t i   } x | D] } | i |  q- Wg  } xL t d  D]> } t i | | | |  | |  }	 |  i i |	  |	 i	   qW Wx |  i D] }	 |	 i
   qŁ W| i   | d | !S(   ső   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.i   i    N(   R   R1   t   Queuet   putt   rangeR   R   R.   R!   t   startt   joint   sort(
   R   R1   R3   R   R   R   t   mR   t   iR9   (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR5   T   s"      
 
c   	         sż     f d   } | d j o   i } n g  } xx | D]p }   i i   p Pn | |  } | d j o | i | | g  n   i | i |  t |  d |  q6 W| i   | d | !S(   sů   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            sv   d |  i    d   i f }   i d |  t i   } y* t i |  i d  } t i   | SWn d Sn Xd  S(   Ns   %s/%si    s   Downloading %s...i  (   t   get_repo_urlsR-   R   t   timet   urllibt   urlopent   read(   R%   t   urlRA   t   data(   R   (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyt   test_download_speedq   s    i    g      ŕ?i   N(   g      ŕ?i   (	   R   R1   R   R   R!   R    t   indexR0   RC   (	   R   R1   R3   R   R   RM   R   RD   t   download_time(    (   R   sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR6   k   s    
 )
N(   i    id   (   i    i    (   i    i   (   i    i    (   i    i   (   i    i    (   R*   R+   R,   R   R   R   R   R   R;   R   R    R5   R6   (    (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pyR      s   (			t   __main__s   dpkg --print-architectures!   dists/%s/%s/binary-%s/Packages.gzi    (!   R   R>   RG   R	   R   t   tempfilet
   aptsourcest   timeitR    RH   t   sockett   randomt   setdefaulttimeoutR   R   R*   t   distrot
   get_distrot   get_sourcest   SourcesListR   t   pipeRJ   t   stript   archt   source_templatet   namet
   componentsR-   t
   mirror_sett   valuest   appR;   (    (    (    sB   /var/lib/python-support/python2.5/softwareproperties/MirrorTest.pys   <module>   s&   H}	
	