³ò
à ŠHc           @   sU  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 Z d  d k	 Z	 d  d k
 l Z d „  Z d „  Z d d d „  ƒ  YZ d e f d „  ƒ  YZ d	 d d
 „  ƒ  YZ d d d „  ƒ  YZ e d j og e i ƒ  e ƒ  Z x e D] Z e i ƒ  GHqWe d d ƒ Z d e GHe d d ƒ GHe d d ƒ GHn d S(   iÿÿÿÿN(   t   DistInfoc         C   s®   | i  d ƒ } |  i  d ƒ }  | |  j o t Sn y* | i d ƒ d } |  i d ƒ d } Wn t j
 o t Sn Xd | j o& | | i d ƒ d | j o t Sn t S(   s¢   check if the given add_url is idential or a mirror of orig_uri
    e.g. master_uri = archive.ubuntu.com
      compare_uri = de.archive.ubuntu.com
      -> True
  s   / s   //i   t   .(   t   rstript   Truet   splitt
   IndexErrort   Falset   index(   t
   master_urit   compare_urit   compare_srvt
   master_srv(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt	   is_mirror(   s    	c         C   s   t  t |  ƒ ƒ S(   s.    simple and efficient way to return uniq list (   t   listt   set(   t   s(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   uniqE   s    t   SourceEntryc           B   sP   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s    single sources.list entry c         C   s§   t  |  _ t  |  _ d |  _ d |  _ d |  _ g  |  _ d |  _ | |  _ | d  j o& t
 i i d ƒ t
 i i d ƒ } n | |  _ |  i | ƒ d  |  _ g  |  _ d  S(   Nt    s   Dir::Etcs   Dir::Etc::sourcelist(   R   t   invalidt   disabledt   typet   urit   distt   compst   commentt   linet   Nonet   apt_pkgt   Configt   FindDirt   Findt   filet   parset   templatet   children(   t   selfR   R    (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   __init__K   s    								&		c         C   s\   |  i  | i  j oI |  i | i j o6 |  i | i j o# |  i | i j o |  i | i j S(   s-    equal operator for two sources.list entries (   R   R   R   R   R   (   R$   t   other(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   __eq__[   s
    c         C   s)  t  i | ƒ } g  } d } t } t } x× t t | ƒ ƒ D]Ã } | | d j o t } | | | 7} q: | | d j o t } | | | 7} q: | o3 | | i ƒ  o! t } | i | ƒ | | } q: | | i ƒ  o | o
 t } q: | | | 7} q: Wt | ƒ d j o | i | ƒ n | S(   s~    a split() implementation that understands the sources.list
        format better and takes [] into account (for e.g. cdroms) R   t   [t   ]i    (   t   stringt   stripR   t   ranget   lenR   t   isspacet   append(   R$   R   t   piecest   tmpt   p_foundt   space_foundt   i(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   mysplitd   s.     
c      	   C   s¿  t  i |  i ƒ } | d j p | d j o t |  _ d Sn | d d j oL t |  _ t  i | d ƒ } | d d j o t |  _ d Sqš | d } n | i d ƒ } | d j o | | d |  _ | |  } n |  i	 | ƒ } t
 | ƒ d
 j  o t |  _ d Sn t  i | d ƒ |  _ |  i d j o t |  _ d Sn t  i | d ƒ |  _ t
 |  i ƒ d j  o t |  _ n t  i | d ƒ |  _ t
 | ƒ d
 j o | d
 |  _ n
 g  |  _ d S(   sZ    parse a given sources.list (textual) line and break it up
        into the field we have R   t   #Ni    i   t   rpms   rpm-srct   debs   deb-srci   i   (   R7   s   rpm-srcR8   s   deb-src(   R8   s   deb-srcR7   s   rpm-src(   R*   R+   R   R   R   R   R   t   findR   R5   R-   R   R   R   R   (   R$   R   R0   R4   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyR!      s<    					c         C   s¡   | |  _  | t j oU d } t i |  i ƒ |  _ x# |  i | d j o | d 7} q5 W|  i | |  _ n2 t i |  i ƒ d d j o d |  i |  _ n d S(   s#    set a line to enabled or disabled i    R6   i   N(   R   R   R*   t   lstripR   R+   (   R$   t	   new_valueR4   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   set_enabled±   s    
 c         C   s   |  i  ƒ  i ƒ  S(   s    debug helper (   t   strR+   (   R$   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   __str__À   s    c         C   s¶   |  i  o |  i Sn d } |  i o
 d } n | d |  i |  i |  i f 7} t |  i ƒ d j o | d d i |  i ƒ 7} n |  i	 d j o | d |  i	 7} n | d 7} | S(   s#    return the current line as string R   s   # s   %s %s %si    t    s    #s   
(
   R   R   R   R   R   R   R-   R   t   joinR   (   R$   R   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyR=   Ä   s    


 
N(   t   __name__t
   __module__t   __doc__R   R%   R'   R5   R!   R<   R>   R=   (    (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyR   I   s   				0		t   NullMatcherc           B   s   e  Z d  Z d „  Z RS(   s    a Matcher that does nothing c         C   s   t  S(   N(   R   (   R$   R   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   matchÕ   s    (   RA   RB   RC   RE   (    (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyRD   Ó   s   t   SourcesListc           B   sz   e  Z d  Z e d d „ Z d „  Z d „  Z d d d d „ Z d „  Z	 d	 „  Z
 d d
 „ Z d „  Z d „  Z d „  Z RS(   s8    represents the full sources.list + sources.list.d file s    /usr/share/python-apt/templates/c         C   s=   g  |  _  | o t | ƒ |  _ n t ƒ  |  _ |  i ƒ  d  S(   N(   R   t   SourceEntryMatchert   matcherRD   t   refresh(   R$   t   withMatchert   matcherPath(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyR%   Ú   s
    	c         C   s·   g  |  _  t i i d ƒ } t i i d ƒ } |  i | | ƒ t i i d ƒ } x( t i d | ƒ D] } |  i | ƒ qd Wx5 |  i  D]* } | i t j o |  i	 i
 | ƒ q… q… Wd S(   s"    update the list of known entries s   Dir::Etcs   Dir::Etc::sourcelists   Dir::Etc::sourcepartss	   %s/*.listN(   R   R   R   R   R   t   loadt   globR   R   RH   RE   (   R$   t   dirR    t   partsdirt   source(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyRI   ä   s    	 
 c         c   s#   x |  i  D] } | Vq
 Wt ‚ d S(   sI    simple iterator to go over self.list, returns SourceEntry
        types N(   R   t   StopIteration(   R$   t   entry(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   __iter__ô   s    
 	R   iÿÿÿÿc      
   C   s~  | } xµ |  i  D]ª }	 |	 i t j o” |	 i t j o„ |	 i | j ot | |	 i j od |	 i | j oT xQ | D]E }
 |
 |	 i j o/ | | i |
 ƒ =t	 | ƒ d j o |	 Sq³ qn qn Wq q Wx|  i  D]}	 |	 i t j od |	 i t j oT |	 i | j oD | |	 i j o4 |	 i | j o$ t
 |	 i | ƒ } | |	 _ |	 SqÉ |	 i t j o} |	 i t j om |	 i | j o] | |	 i j oM |	 i | j o= t	 t |	 i ƒ t | ƒ @ƒ t	 | ƒ j o t |	 _ |	 SqÉ qÉ Wd | | | f } x | D] } | d | } qîW| d j o d | | f } n | d } t | ƒ } | d j o | | _ n |  i i | ƒ |  i  i | | ƒ | S(   s™   
    Add a new source to the sources.list.
    The method will search for existing matching repos and will try to 
    reuse them as far as possible
    i    s   %s %s %sR?   R   s   %s #%s
s   
N(   R   R   R   R   R   R   R   R   R   R-   R   R   R   R   R   R    RH   RE   t   insert(   R$   R   R   R   t
   orig_compsR   t   posR    R   RP   t   new_compR   t   ct	   new_entry(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   addû   sN    
    
   	  ,	 
c         C   s   |  i  i | ƒ d S(   s2    remove the specified entry from the sources.list N(   R   t   remove(   R$   t   source_entry(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyR[   .  s    c         C   sÙ   t  i i d ƒ } t  i i d ƒ } t i i | | | ƒ o7 t i i | | ƒ o  t i | | | | | ƒ n t  i i d ƒ } xJ t	 i	 d | ƒ D]5 } t i i | | ƒ o t i | | | ƒ qœ qœ Wd S(   s:    restore sources.list files based on the backup extension s   Dir::Etcs   Dir::Etc::sourcelists   Dir::Etc::sourcepartss	   %s/*.listN(
   R   R   R   R   t   ost   patht   existst   shutilt   copyRM   (   R$   t
   backup_extRN   R    RO   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   restoreBackup2  s      c         C   s‹   t  ƒ  } | d j o t i d ƒ } n x[ |  i D]P } | i | j o: t i i | i ƒ o$ t	 i
 | i d | i | f ƒ q3 q3 W| S(   s‚    make a backup of the current source files, if no backup extension
        is given, the current date/time is used (and returned) s   %y%m%d.%H%Ms   %s%sN(   R   R   t   timet   strftimeR   R    R]   R^   R_   R`   Ra   (   R$   Rb   t   already_backupedRP   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   backup?  s    	
 &(c         C   sp   yO t  | d ƒ } | i ƒ  } x- | D]% } t | | ƒ } |  i i | ƒ q% WWn d | GHn X| i ƒ  d S(   s    (re)load the current sources t   rs   could not open file '%s'N(   t   opent	   readlinesR   R   R/   t   close(   R$   R    t   ft   linesR   RP   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyRL   J  s     c         C   sé   h  } t  |  i ƒ d j oL d t i i d ƒ t i i d ƒ f } d } t | d ƒ i | ƒ d Sn x[ |  i D]P } | i | i	 ƒ p t | i	 d ƒ | | i	 <n | | i	 i | i
 ƒ  ƒ qr Wx | D] } | | i ƒ  qÍ Wd S(   s    save the current sources i    s   %s%ss   Dir::Etcs   Dir::Etc::sourcelists    ## See sources.list(5) for more information, especialy
# Remember that you can only use http, ftp or file URIs
# CDROMs are managed through the apt-cdrom tool.
t   wN(   R-   R   R   R   R   R   Ri   t   writet   has_keyR    R=   Rk   (   R$   t   filesR^   t   headerRP   Rl   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   saveW  s    
  c         C   s½   g  } h  } x¤ | D]œ } | i  d j o q n | i  i t j oB | i  } | i | ƒ p g  | | <n | | } | i | ƒ q t | i  i ƒ d j o | i | ƒ q q W| | f S(   s5   get all parent and child channels in the sources listi    N(   R"   R   t   childR   Rp   R/   R-   R#   (   R$   t   sources_listt   parentst   used_child_templatesRP   t   keyt   temp(    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyt   check_for_relationsj  s     	
N(   RA   RB   RC   R   R%   RI   RS   R   RZ   R[   Rc   Rg   RL   Rs   Rz   (    (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyRF   Ø   s   		3				RG   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s©   g  |  _  t i d | ƒ } x† | D]~ } t i i | ƒ } | i d ƒ } | d | !} t | d | ƒ} x5 | i  D]* } | i d  j o |  i  i	 | ƒ qs qs Wq# Wd  S(   Ns	   %s/*.infos   .infoi    t   base_dir(
   t	   templatesRM   R]   R^   t   basenameR9   R    t	   match_uriR   R/   (   R$   RK   t
   spec_filesRl   R4   R   R"   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyR%   …  s    	 
 c         C   s­   t  i  } t } x— |  i D]Œ } t i | i | i ƒ o- t i | i | i	 ƒ o t
 } | | _ Pq | i | i ƒ o- t i | i | i	 ƒ o t
 } | | _ Pq q W| S(   s%   Add a matching template to the source(   t   gettextR   R|   t   ret   searchR~   R   RE   t
   match_nameR   R   R"   R   (   R$   RP   t   _t   foundR"   (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyRE   “  s    	
 			(   RA   RB   R%   RE   (    (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pyRG   „  s   	t   __main__s!   http://archive.ubuntu.com/ubuntu/s$   http://de.archive.ubuntu.com/ubuntu/s   is_mirror(): %ss    http://archive.ubuntu.com/ubuntus#   http://de.archive.ubuntu.com/ubuntu(    (    (    (   R*   R€   R   R   RM   R`   Rd   t   os.pathR]   t   syst   distinfoR    R   R   R   t   objectRD   RF   RG   RA   t
   InitConfigt   sourcesRR   R=   t   mirror(    (    (    s:   /usr/lib/python2.5/site-packages/aptsources/sourceslist.pys   <module>   s8   		Š¬"
	 		