³ò
à ŠHc        	   @   s³   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 „  Z d e f d „  ƒ  YZ d f  d „  ƒ  YZ d e f d „  ƒ  YZ	 d	 e f d
 „  ƒ  YZ
 d „  Z d S(   iÿÿÿÿNc         C   s   t  i d |  ƒ S(   Ns
   python-apt(   t   gettextt   dgettext(   t   s(    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   _   s    t   NoDistroTemplateExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR   "   s   t   Distributionc           B   st   e  Z d  „  Z d „  Z d d „ Z d „  Z d „  Z d d d d d d „ Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   c         C   s:   | |  _  | |  _ | |  _ | |  _ d |  _ d |  _ d S(   s2    Container for distribution specific informations t   debs   deb-srcN(   t   idt   codenamet   descriptiont   releaset   binary_typet   source_type(   t   selfR	   R
   R   R   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   __init__&   s    					c   	      C   s   | |  _  d |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _	 g  |  _
 t |  _ g  |  _ d |  _ d |  _ d |  _ g  |  _ xK |  i  i i D]: } |  i | i ƒ o! | i |  i j o | |  _ Pq  q  W|  i d j o t d f ‚ n g  } g  } g  } g  } g  } x}|  i  i D]o} | i t j o±|  i | i ƒ ož| i o”|  i | i i ƒ o~| i i d ƒ o4 | i t j o$ |  i i  | ƒ | i! | i" ƒ qð| i i d ƒ o$ | i t# j o |  i i  | ƒ qð| i$ |  i% j oD | i t j o4 |  i i  | ƒ | i! | i" ƒ | i  | i ƒ qð| i$ |  i% j o$ | i t# j o |  i i  | ƒ qð| i$ |  i& j o$ | i t j o |  i i  | ƒ qð| i$ |  i& j o$ | i t# j o |  i i  | ƒ qðn | i t j o˜ | i |  i i' j o‚ | i t j o' | i$ |  i% j o |  i i  | ƒ q˜| i t j o' | i$ |  i& j o |  i i  | ƒ q˜|  i i  | ƒ q)q)Wt( | ƒ |  _ t( | ƒ |  _	 | i! | ƒ | i! | ƒ t( | ƒ |  _ t( | ƒ |  _
 |  i) ƒ  d S(   s\   
    Find the corresponding template, main and child sources 
    for the distribution 
    t    s-   Error: could not find a distribution templates   cdrom:N(*   t   sourceslistt   Nonet   source_templatet   child_sourcest   main_sourcest   disabled_sourcest   cdrom_sourcest   download_compst   enabled_compst   cdrom_compst
   used_mediat   Falset   get_source_codet   source_code_sourcest   default_servert   main_servert   nearest_servert   used_serverst   matchert	   templatest   is_codenamet   namet   distributionR	   R   t   listt   invalidt   distt   templatet   urit
   startswitht   disabledt   appendt   extendt   compst   Truet   typeR   R   t   childrent   sett   get_mirrors(	   R   R   R,   t   mediaR2   R   R   t   source_codet   source(    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   get_sources1   sŠ    																 		 
####c         C   sË  |  i  i |  _ x5 |  i D]* } | i d ƒ p |  i i | ƒ q q Wt |  i ƒ d j o |  i |  _	 n |  i d i
 |  _	 h  |  _ y` t d d ƒ } | i ƒ  } x> | D]6 } | i d ƒ } | d i ƒ  |  i | d i ƒ  <q® WWn d t GHn X| i ƒ  d |  _ d |  _ t i d d	 d
 ƒ} | i d ƒ } | i d ƒ }	 |	 d j o t | ƒ }	 n | | d |	 !i ƒ  }
 | o | |
 |  _ n |  i i |
 ƒ o |  i |
 |  _ |
 |  _ n d S(   sJ   
    Provide a set of mirrors where you can get the distribution from
    s   cdrom:i    s!   /usr/share/iso-codes/iso_3166.tabt   rs   	i   s   could not open file '%s't   LANGt   defaultt   en_UKR   t   .iÿÿÿÿN(   R   t   base_uriR!   R   R.   R#   R0   t   lenR   R    R-   t	   countriest   opent	   readlinest   splitt   stript   lowert   filet   closeR   t   countryt   country_codet   ost   getenvt   findR"   t   has_key(   R   t   mirror_templatet   mediumt   ft   linest   linet   partst   localet   at   zRL   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR7   ˆ   s@    
 	 )
		c         C   s²   d } | i d ƒ } | i d ƒ } | d j o( | d j o | | t d ƒ | !} n |  i i | ƒ o1 t d ƒ t i d |  i | i ƒ  ƒ i ƒ  Sn d | i d ƒ Sd S(	   ss    Try to get a human readable name for the main mirror of a country
          Customize for different distributions s   ://s   .archive.ubuntu.comiÿÿÿÿs   Server for %st   iso_3166s   %ss   / N(	   R   RO   RB   RC   RP   R   R    R   t   rstrip(   R   t   serverRK   t   it   l(    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   _get_mirror_name¸   s    		c         C   sZ  d „  } g  } t  |  i ƒ d j  p0 t  |  i ƒ d j ob | |  i d |  i ƒ oH | i t d ƒ |  i t g ƒ | i |  i |  i ƒ |  i t g ƒ nºt  |  i ƒ d j o¦ | |  i d |  i ƒ o‹ | i t d ƒ |  i t g ƒ |  i d } | | |  i ƒ p) | i |  i |  i ƒ |  i t g ƒ n | i |  i | ƒ | t g ƒ nþ t  |  i ƒ d j oç | i t d ƒ |  i t g ƒ | i |  i |  i ƒ |  i t g ƒ | i t d ƒ d t g ƒ x„ |  i D]u } | | |  i ƒ p | | |  i ƒ o qÙqÙ|  i | ƒ | t g | j o# | i |  i | ƒ | t g ƒ qÙqÙWn | S(   s-    Return a list of used and suggested servers c         S   s"   t  i |  i d ƒ | i d ƒ ƒ S(   sf   Helper function that handles comaprision of mirror urls
           that could contain trailing slashess   / (   t   ret   matchRG   R[   (   t   mir1t   mir2(    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   compare_mirrorsÊ   s    i   i    s   Main servers   Custom serversN(
   RB   R#   R!   R0   R   R3   R_   R"   R   R   (   R   Rd   t   mirrorsR\   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   get_server_listÈ   s:    	#
 +R   c         C   sõ   | d j o |  i } n | d j o |  i } n | d j o t |  i ƒ } n | d j o |  i } n |  i i | | | | | ƒ } |  i t	 j oU | |  i j oE |  i i |  i
 | | | | d | i d |  i i i | ƒ d ƒn d S(   s+   
    Add distribution specific sources
    RI   t   posi   N(   R   R    R
   R)   R   R   R   t   addR   R3   R   RI   t   index(   R   R4   R-   R+   R2   t   commentt
   new_source(    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt
   add_sourceõ   s     	c            sØ  ‡  f d †  } g  } | i  |  i ƒ | i  |  i ƒ h  } h  } xf | D]^ } | i |  i j oE | i | i ƒ p t ƒ  | | i <n t | | i i	 | i
 ƒ qH qH Wxi |  i D]^ } | i |  i j oE | i | i ƒ p t ƒ  | | i <n t | | i i	 | i
 ƒ q´ q´ Wt |  i ƒ d j  o |  i d d ˆ  g ƒ n x | D] } | | | ƒ qNW|  i t j o_ t |  i ƒ d j  o$ |  i d |  i d d ˆ  g ƒ qÔx" |  i D] } | | | ƒ q¹Wn d S(   s£   
    Enable a component in all main, child and source code sources
    (excluding cdrom based sources)

    comp:         the component that should be enabled
    c            s_   | i  |  i ƒ p d Sn ˆ  | |  i j o d Sn |  i i ˆ  ƒ | |  i i ˆ  ƒ d S(   s´   
        Check if we already added the component to the repository, since
        a repository could be splitted into different apt lines. If not
        add the component
        N(   RP   R+   R2   R0   Rh   (   R:   t   comps_per_dist(   t   comp(    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   add_component_only_once  s    i   R2   s   %sR4   N(   R1   R   R   R4   R   RP   R+   R6   t   mapRh   R2   R   R   RB   Rl   R   R3   (   R   Rn   Ro   t   sourcesRm   t   comps_per_sdistR   R:   (    (   Rn   s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   enable_component  s:     "
 " $
 c         C   sÃ   g  } | i  |  i ƒ | i  |  i ƒ | i  |  i ƒ | |  i j o g  } | i  |  i ƒ n x\ | D]T } | | i j o> | i i | ƒ t | i ƒ d j  o |  i i | ƒ q» qg qg Wd S(   sl   
    Disable a component in all main, child and source code sources
    (excluding cdrom based sources)
    i   N(	   R1   R   R   R   R   R2   t   removeRB   R   (   R   Rn   Rq   R:   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   disable_componentI  s     c      
      sÁ   ‡  f d †  } g  } g  } | ˆ  _  x! ˆ  i D] } | | | | ƒ q. WxN ˆ  i D]C } | i i d j p | i i | i j o | | | | ƒ qR qR Wx! ˆ  i D] } | | | | ƒ q£ Wd S(   sJ    Change the server of all distro specific sources to
        a given host c            s—   | |  _  x] |  i D]R } |  i  |  i | g | j o |  i i | ƒ q | i |  i  |  i | g ƒ q Wt |  i ƒ d j  o ˆ  i i |  ƒ n d  S(   Ni   (   R-   R2   R+   Rt   R0   RB   R   (   R:   R-   t   seenRn   (   R   (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   change_server_of_source^  s    	
  N(   R    R   R   R,   RA   R   R-   R   (   R   R-   Rw   t   seen_binaryt   seen_sourceR:   (    (   R   s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt   change_server[  s    
	
 
 
 c         C   s    | |  i  j o t Sn t Sd S(   s1    Compare a given name with the release codename. N(   R
   R3   R   (   R   R'   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR&   u  s    N(   R   R   R   R;   R   R7   R_   Rf   Rl   Rs   Ru   Rz   R&   (    (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR   %   s   		W0		-	>		t   DebianDistributionc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s+    Class to support specific Debian features c         C   s0   | |  i  j p |  i d j o t Sn t Sd S(   s    Compare a given name with the release codename and check if
        if it can be used as a synonym for a development releases t   testingt   unstableN(   R|   R}   (   R
   R   R3   R   (   R   R'   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR&     s     c         C   s²   d } | i d ƒ } | i d ƒ } | d j o( | d j o | | t d ƒ | !} n |  i i | ƒ o1 t d ƒ t i d |  i | i ƒ  ƒ i ƒ  Sn d | i d ƒ Sd S(	   s]    Try to get a human readable name for the main mirror of a country
          Debian specific s   ://ftp.s   .debian.orgiÿÿÿÿs   Server for %sRZ   s   %ss   / N(	   R   RO   RB   RC   RP   R   R    R   R[   (   R   R\   RK   R]   R^   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR_   ‡  s    		c         C   s   t  i |  d d ƒd  S(   NRQ   s    http://ftp.%s.debian.org/debian/(   R   R7   (   R   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR7   —  s    (   R   R   t   __doc__R&   R_   R7   (    (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR{   |  s   		t   UbuntuDistributionc           B   s   e  Z d  Z d „  Z RS(   s+    Class to support specific Ubuntu features c         C   s   t  i |  d d ƒd  S(   NRQ   s$   http://%s.archive.ubuntu.com/ubuntu/(   R   R7   (   R   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR7     s    (   R   R   R~   R7   (    (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyR   ›  s   c          C   sÃ   g  }  xI d d d d g D]5 } t  i d | ƒ } |  i | i ƒ  i ƒ  ƒ ~ q W|  \ } } } } | d j o t | | | | ƒ Sn8 | d j o t | | | | ƒ Sn t | | | | ƒ Sd S(	   s‡    Check the currently used distribution and return the corresponding
        distriubtion class that supports distro specific features. s   -is   -cs   -ds   -rs   lsb_release %s -st   Ubuntut   DebianN(   RM   t   popenR0   t   readRG   R   R{   R   (   t   lsb_infot
   lsb_optiont   pipeR	   R
   R   R   (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pyt
   get_distro¡  s     (   t   stringR    R`   RM   t   sysR   t	   ExceptionR   R   R{   R   R‡   (    (    (    s5   /usr/lib/python2.5/site-packages/aptsources/distro.pys   <module>   s   	ÿ X