Ñò
óˆNc           @   sÏ   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 „  Z d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ
 d e
 f d	 „  ƒ  YZ d
 e
 f d „  ƒ  YZ d „  Z e e e e d „ Z d S(   iÿÿÿÿN(   t   ElementTreec         C   s   t  i d |  ƒ S(   Ns
   python-apt(   t   gettextt   dgettext(   t   s(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   _!   s    t   NoDistroTemplateExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s5   /usr/lib/python2.6/dist-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.6/dist-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 ƒ ‚ 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(   sf   
        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   mediaR3   R   R   t   source_codet   source(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   get_sources6   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  |  _ d } t i i | ƒ oº t d | ƒ } | i d ƒ } x™ | D] } y | i d } Wn  t j
 o | i d } n Xy | i d } Wn  t j
 o | i d	 } n Xt i d
 | ƒ |  i | i ƒ  <qÇ Wn d |  _ d |  _ t i d d d ƒ}	 |	 i d ƒ }
 |	 i d ƒ } | d j o t |	 ƒ } n |	 |
 d | !i ƒ  } | o | | |  _ n | |  i j o |  i | |  _ | |  _ n d S(   sR   
        Provide a set of mirrors where you can get the distribution from
        s   cdrom:i    s%   /usr/share/xml/iso-codes/iso_3166.xmlt   filet   iso_3166_entryt   common_nameR(   t   alpha_2_codet   alpha_3_codet   iso_3166t   LANGt   defaultt   en_UKR   t   .iÿÿÿÿi   N(   R   t   base_uriR"   R   R/   R$   R1   t   lenR   R!   R.   t	   countriest   ost   patht   existsR    t   getiteratort   attribt   KeyErrorR   R   t   lowerR   t   countryt   country_codet   getenvt   findR#   (   R   t   mirror_templatet   mediumt   fnamet   ett   itt   elmt   descrt   codet   localet   at   zRR   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR8   ‘   sL    
 	 			c         C   s”   d } | i d ƒ } | i d ƒ } | d j o( | d j o | | t d ƒ | !} n | |  i j o t d ƒ |  i | Sd | i d ƒ Sd S(   su    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 %ss   %ss   / N(   R   RT   RH   RI   R   t   rstrip(   R   t   serverRQ   t   it   l(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   _get_mirror_nameÆ   s    c         C   sƒ  d „  } g  } t  |  i ƒ d j  p0 t  |  i ƒ d j op | |  i d |  i ƒ oV | i t d ƒ |  i t g ƒ |  i o) | i |  i |  i ƒ |  i t g ƒ qnÕt  |  i ƒ d j o¿ | |  i d |  i ƒ o¤ | i t d ƒ |  i t g ƒ |  i d } |  i o@ | | |  i ƒ p) | i |  i |  i ƒ |  i t g ƒ qRn | o# | i |  i | ƒ | t g ƒ qn t  |  i ƒ d j oé | i t d ƒ |  i t g ƒ |  i o) | i |  i |  i ƒ |  i t g ƒ n | i t d ƒ d t g ƒ xx |  i D]i } |  i | ƒ | t g } | | |  i ƒ p | | |  i ƒ o qq| | j o | i | ƒ qqWn | S(   s-    Return a list of used and suggested servers c         S   s"   t  i |  i d ƒ | i d ƒ ƒ S(   sl    Helper function that handles comaprision of mirror urls
                that could contain trailing slashess   / (   t   ret   matcht   stripR`   (   t   mir1t   mir2(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   compare_mirrors×   s    i   i    s   Main servers   Custom serversN(
   RH   R$   R"   R1   R   R4   R#   Rd   R   R   (   R   Rj   t   mirrorsRa   t   mirror_entry(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   get_server_listÔ   sD    	

'

 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(   s3   
        Add distribution specific sources
        R=   t   posi   N(   R   R!   R   R*   R   R   R   t   addR   R4   R   R=   t   index(   R   R5   R.   R,   R3   t   commentt
   new_source(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt
   add_source  s     	c            sÒ  ‡  f d †  } g  } | i  |  i ƒ | i  |  i ƒ h  } h  } xc | D][ } | i |  i j oB | i | j o t ƒ  | | i <n t | | i i | i	 ƒ qH qH Wxf |  i
 D][ } | i |  i j oB | i | j o t ƒ  | | i <n t | | i i | i	 ƒ q± q± Wt |  i ƒ d j  o |  i d d ˆ  g ƒ n x | D] } | | | ƒ qH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            sV   |  i  | j o d Sˆ  | |  i  j o d S|  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(   R,   R3   R1   Ro   (   R;   t   comps_per_dist(   t   comp(    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   add_component_only_once%  s    i   R3   s   %sR5   N(   R2   R   R   R5   R   R,   R7   t   mapRo   R3   R    R   RH   Rs   R   R4   (   R   Ru   Rv   t   sourcesRt   t   comps_per_sdistR   R;   (    (   Ru   s5   /usr/lib/python2.6/dist-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(   sx   
        Disable a component in all main, child and source code sources
        (excluding cdrom based sources)
        i   N(	   R2   R   R   R    R   R3   t   removeRH   R   (   R   Ru   Rx   R;   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   disable_component\  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(   sN    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.   R3   R,   R{   R1   RH   R   (   R;   R.   t   seenRu   (   R   (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   change_server_of_sourcer  s    	
  N(   R!   R   R   R-   RG   R   R.   R    (   R   R.   R~   t   seen_binaryt   seen_sourceR;   (    (   R   s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   change_servern  s    	
 
 
 c         C   s   | |  i  j o t St Sd S(   s1    Compare a given name with the release codename. N(   R   R4   R   (   R   R(   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR'   Š  s    N(   R   R   R   R<   R   R8   Rd   Rm   Rs   Rz   R|   R   R'   (    (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR   )   s   		[5		3	?		t   DebianDistributionc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s+    Class to support specific Debian features c         C   s-   | |  i  j p |  i d j o t S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   R4   R   (   R   R(   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR'   •  s     c         C   s¬   d } | i d ƒ } | i d ƒ } | d j o( | d j o | | t d ƒ | !} n | |  i j o. t d ƒ t i d |  i | i ƒ  ƒ i ƒ  S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 %sRB   s   %ss   / N(   R   RT   RH   RI   R   R   R   R`   (   R   Ra   RQ   Rb   Rc   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyRd     s    c         C   s   t  i |  d d ƒd  S(   NRU   s    http://ftp.%s.debian.org/debian/(   R   R8   (   R   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR8   ¬  s    (   R   R   t   __doc__R'   Rd   R8   (    (    (    s5   /usr/lib/python2.6/dist-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(   NRU   s$   http://%s.archive.ubuntu.com/ubuntu/(   R   R8   (   R   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR8   ´  s    (   R   R   R…   R8   (    (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyR†   ±  s   c       	   C   sÕ   d d k  l }  l } d d k } h d d 6d d 6d d	 6d
 d 6} yU |  d d g d | ƒi ƒ  d } | i d ƒ } | i d „  | i d ƒ Dƒ ƒ Wn5 t j
 o) } | i | i	 j o d G| GHqÑ n X| S(   s-   Call lsb_release --idrc and return a mapping.iÿÿÿÿ(   t   Popent   PIPENt   sidt   Codenamet   Debians   Distributor IDs   Debian GNU/Linux unstable (sid)t   DescriptionR„   t   Releaset   lsb_releases   -idrct   stdouti    s   utf-8c         s   s3   x, |  ]% } d  | j o | i  d  ƒ Vq q Wd S(   s   :	N(   t   split(   t   .0Rc   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pys	   <genexpr>Ä  s   	 s   
s,   WARNING: lsb_release failed, using defaults:(
   t
   subprocessR‡   Rˆ   t   errnot   communicatet   decodet   updateR   t   OSErrort   ENOENT(   R‡   Rˆ   R“   t   resultt   outt   exc(    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   _lsb_release¹  s    
"$c         C   sª   |  o | o | o | p5 t  ƒ  } | d }  | d } | d } | d } n |  d j o t |  | | | ƒ S|  d j o t |  | | | ƒ St |  | | | ƒ Sd S(   sè   
    Check the currently used distribution and return the corresponding
    distriubtion class that supports distro specific features.

    If no paramter are given the distro will be auto detected via
    a call to lsb-release
    s   Distributor IDRŠ   RŒ   R   t   UbuntuR‹   N(   Rœ   R†   R‚   R   (   R
   R   R   R   R™   (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt
   get_distroË  s    		


(   R   Re   RJ   t   syst   xml.etree.ElementTreeR    R   t	   ExceptionR   t   objectR   R‚   R†   Rœ   R   Rž   (    (    (    s5   /usr/lib/python2.6/dist-packages/aptsources/distro.pyt   <module>   s   	ÿ j	