ó
öòUc           @@ s“  d  d l  m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d d l m Z d d d d d	 g Z d
 „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ e d k re
 j ƒ  e ƒ  Z x% e D] Z e j d e j ƒ  ƒ qWe d d ƒ Z e j d e ƒ e j e d d ƒ ƒ e j e d d ƒ ƒ n  d S(   i    (   t   absolute_importt   print_functionNi   (   t   DistInfot	   is_mirrort   SourceEntryt   NullMatchert   SourcesListt   SourceEntryMatcherc         C@ sž   | j  d ƒ } |  j  d ƒ }  | |  k r. t Sy* | j d ƒ d } |  j d ƒ d } Wn t k
 rl t SXd | k rš | | j d ƒ d | k rš t St 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.7/dist-packages/aptsources/sourceslist.pyR   .   s    c         C@ s   t  t |  ƒ ƒ S(   s.   simple and efficient way to return uniq collection

    This is not intended for use with a SourceList. It is provided
    for internal use only. It does not have a leading underscore to
    not break any old code that uses it; but it should not be used
    in new code (and is not listed in __all__).(   t   listt   set(   t   s(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   uniqL   s    c           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 |  _ g  |  _ d  |  _ d |  _ d |  _ g  |  _	 d |  _
 | |  _ | d  k r‹ t j j d ƒ t j j d ƒ } n  | |  _ |  j | ƒ d  |  _ g  |  _ d  S(   Nt    s   Dir::Etcs   Dir::Etc::sourcelist(   R   t   invalidt   disabledt   typet   architecturest   Nonet   trustedt   urit   distt   compst   commentt   linet   apt_pkgt   configt   find_dirt   findt   filet   parset   templatet   children(   t   selfR"   R'   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   __init__Y   s"    													c         C@ sX   |  j  | j  k oW |  j | j k oW |  j | j k oW |  j | j k oW |  j | j k S(   s-    equal operator for two sources.list entries (   R   R   R   R   R    (   R+   t   other(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   __eq__l   s
    c         C@ sF  | j  ƒ  } g  } d } t } t } xù t t | ƒ ƒ D]å } | | d k r | ry t } t } | j | ƒ | | } qt } | | | 7} q7 | | d k r· t } | | | 7} q7 | rî | | j ƒ  rî t } | j | ƒ | | } q7 | | j ƒ  r| rt } q7 | | | 7} q7 Wt | ƒ d k rB| j | ƒ 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   stripR   t   ranget   lenR
   t   appendt   isspace(   R+   R"   t   piecest   tmpt   p_foundt   space_foundt   i(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   mysplitt   s6    	c         C@ si  |  j  j ƒ  } | d k s' | d k r4 t |  _ d S| d d k r t |  _ | d j ƒ  j ƒ  } | d d k r€ t |  _ d S| d } n  | j d ƒ } | d k rÆ | | d |  _ | |  } n  |  j | ƒ } t	 | ƒ d
 k  rô t |  _ d S| d j ƒ  |  _
 |  j
 d k r#t |  _ d S| d j ƒ  d d k ró| j d ƒ j d ƒ j ƒ  } x• | D]Š } y | j d d ƒ \ } } Wn t k
 r t |  _ qbX| d k rÂ| j d ƒ |  _ qb| d k rãt j | ƒ |  _ qbt |  _ qbWn  | d j ƒ  |  _ t	 |  j ƒ d k  r't |  _ n  | d j ƒ  |  _ t	 | ƒ d
 k r\| d
 |  _ n	 g  |  _ d S(   s^    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   R/   s   []t   =t   archt   ,R   i   (   R=   s   rpm-srcR>   s   deb-src(   R>   s   deb-srcR=   s   rpm-src(   R"   R1   R
   R   R   R   R&   R!   R;   R3   R   t   popt	   ExceptionR   R#   t   string_to_boolR   R   R   R    (   R+   R"   R6   R:   t   optionst   optiont   keyt   value(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR(   ™   sT    					c         C@ s^   | |  _  | r. |  j j ƒ  j d ƒ |  _ n, |  j j ƒ  d d k rZ d |  j |  _ n  d S(   s#    set a line to enabled or disabled R<   i    N(   R   R"   t   lstripR1   (   R+   t	   new_value(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   set_enabledÙ   s
    
c         C@ s   |  j  ƒ  j ƒ  S(   s    debug helper (   t   strR1   (   R+   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   __str__ä   s    c         C@ sQ  |  j  r |  j Sd } |  j r( d } n  | |  j 7} |  j r |  j d k	 r | d d j |  j ƒ |  j rq d n d f 7} nU |  j d k	 r® | d |  j r£ d n d 7} n& |  j rÔ | d d j |  j ƒ 7} n  | d	 |  j |  j	 f 7} t
 |  j ƒ d
 k r | d d j |  j ƒ 7} n  |  j d k rC| d |  j 7} n  | d 7} | S(   s#    return the current line as string R   s   # s    [arch=%s trusted=%s]RA   t   yest   nos    [trusted=%s]s
    [arch=%s]s    %s %si    t    s    #s   
N(   R   R"   R   R   R   R   R   t   joinR   R   R3   R    R!   (   R+   R"   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyRL   è   s(    			, 	
N(   t   __name__t
   __module__t   __doc__R   R,   R.   R;   R(   RK   RM   RL   (    (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR   V   s   		%	@		c           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.7/dist-packages/aptsources/sourceslist.pyt   match  s    (   RR   RS   RT   RU   (    (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR     s   c           B@ s†   e  Z d  Z e d d „ Z d „  Z d „  Z d „  Z d d d g  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  |  _  | r! t | ƒ |  _ n t ƒ  |  _ |  j ƒ  d  S(   N(   R   R   t   matcherR   t   refresh(   R+   t   withMatchert   matcherPath(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR,     s
    	c         C@ s™   g  |  _  t j j d ƒ } |  j | ƒ t j j d ƒ } x( t j d | ƒ D] } |  j | ƒ qN Wx- |  j  D]" } | j so |  j j	 | ƒ qo qo Wd S(   s"    update the list of known entries s   Dir::Etc::sourcelists   Dir::Etc::sourcepartss	   %s/*.listN(
   R   R#   R$   t	   find_filet   loadR%   t   globR   RV   RU   (   R+   R'   t   partsdirt   source(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyRW     s    		c         c@ s#   x |  j  D] } | Vq
 Wt ‚ d S(   sM    simple iterator to go over self.list, returns SourceEntry
            types N(   R   t   StopIteration(   R+   t   entry(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   __iter__%  s    	c         /@ s[   xT |  j  D]I ‰ t ‡  ‡ f d †  ˆ  Dƒ ƒ r
 t ‡ f d †  | Dƒ ƒ r
 ˆ Vq
 q
 Wd  S(   Nc         3@ s(   |  ] } t  ˆ | ƒ ˆ  | k Vq d  S(   N(   t   getattr(   t   .0RG   (   t   attrsR^   (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pys	   <genexpr>.  s    c         3@ s   |  ] } | ˆ  ƒ Vq d  S(   N(    (   Rc   t	   predicate(   R^   (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pys	   <genexpr>/  s    (   R   t   all(   R+   t
   predicatesRd   (    (   Rd   R^   s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   __find,  s    R   iÿÿÿÿc	         @ s  t  ˆ  ƒ ‰  | }	 |  j ‡  f d †  d t d t d | d | d | ƒ}
 xW |
 D]O } xF |	 D]> } | | j k r] |	 |	 j | ƒ =t |	 ƒ d k r› | Sq] q] WqP W|  j ‡  f d †  d t d | d | d | ƒ}
 xb |
 D]Z } | j rt  | j ƒ t  |	 ƒ k rt | _ | S| j sÚ t | j |	 ƒ | _ | SqÚ W| } ˆ  r^| d	 d
 j ˆ  ƒ 7} n  | d | | f 7} x |	 D] } | d | } qyW| d k r°d | | f } n  | d } t	 | ƒ } | d k	 rÞ| | _ n  |  j j | ƒ |  j j | | ƒ | 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
        c         @ s   t  |  j ƒ ˆ  k S(   N(   R   R   (   R   (   R   (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   <lambda>>  s    R   R   R   R   R   i    c         @ s   t  |  j ƒ ˆ  k S(   N(   R   R   (   R   (   R   (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyRi   K  s    s
    [arch=%s]RA   s    %s %sRP   R   s   %s #%s
s   
N(   R   t   _SourcesList__findR   R    R   R3   R   R   RQ   R   R   R'   RV   RU   R   t   insert(   R+   R   R   R   t
   orig_compsR!   t   posR'   R   R    t   sourcesR^   t   new_compR"   t   ct	   new_entry(    (   R   s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   add2  sF    $		
c         C@ s   |  j  j | ƒ d S(   s2    remove the specified entry from the sources.list N(   R   t   remove(   R+   t   source_entry(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyRs   g  s    c         C@ s²   t  j j d ƒ } t j j | | ƒ rQ t j j | ƒ rQ t j | | | ƒ n  t  j j d ƒ } xH t	 j	 d | ƒ D]3 } t j j | | ƒ rw t j | | | ƒ qw qw Wd S(   s:    restore sources.list files based on the backup extension s   Dir::Etc::sourcelists   Dir::Etc::sourcepartss	   %s/*.listN(
   R#   R$   RZ   t   ost   patht   existst   shutilt   copyR%   R\   (   R+   t
   backup_extR'   R]   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   restore_backupk  s    (c         C@ s†   t  ƒ  } | d k r' t j d ƒ } n  xX |  j D]M } | j | k r1 t j j | j ƒ r1 t	 j
 | j d | j | f ƒ q1 q1 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'   Ru   Rv   Rw   Rx   Ry   (   R+   Rz   t   already_backupedR^   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   backupv  s    	'c         C@ sk   yL t  | d ƒ 7 } x- | D]% } t | | ƒ } |  j j | ƒ q WWd QXWn t j d | ƒ n Xd S(   s    (re)load the current sources t   rNs   could not open file '%s'
(   t   openR   R   R4   t   loggingt   warning(   R+   R'   t   fR"   R^   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR[   ‚  s    c         C@ sà   i  } t  |  j ƒ d k r\ t j j d ƒ } d } t | d ƒ  } | j | ƒ Wd QXd Sz] xV |  j D]K } | j | k rš t | j d ƒ | | j <n  | | j j | j ƒ  ƒ qi WWd x | D] } | | j	 ƒ  qÃ WXd S(   s    save the current sources i    s   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(
   R3   R   R#   R$   RZ   R   t   writeR'   RL   t   close(   R+   t   filesRv   t   headerR„   R^   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   saveŒ  s    "c         C@ s¬   g  } i  } x“ | D]‹ } | j  d k r. q n  | j  j rv | j  } | | k r\ g  | | <n  | | } | j | ƒ q t | j  j ƒ d k r | j | ƒ q q W| | f S(   s5   get all parent and child channels in the sources listi    N(   R)   R   t   childR4   R3   R*   (   R+   t   sources_listt   parentst   used_child_templatesR^   RG   t   temp(    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   check_for_relations¤  s    	
N(   RR   RS   RT   R
   R,   RW   Ra   Rj   R   Rr   Rs   R{   R   R[   RŠ   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR   	  s   				4			
	c           B@ s    e  Z d  Z d „  Z d „  Z RS(   s}    matcher class to make a source entry look nice
        lots of predefined matchers to make it i18n/gettext friendly
        c         C@ s§   g  |  _  t j d | ƒ } x„ | D]| } t j j | ƒ } | j d ƒ } | d | !} t | d | ƒ} x3 | j  D]( } | j d  k	 rs |  j  j	 | ƒ qs qs Wq# Wd  S(   Ns	   %s/*.infos   .infoi    t   base_dir(
   t	   templatesR\   Ru   Rv   t   basenameR&   R   t	   match_uriR   R4   (   R+   RY   t
   spec_filesR„   R:   R   R)   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR,   Â  s    	c         C@ s¿   t  } x² |  j D]§ } t j | j | j ƒ rz t j | j | j ƒ rz | j	 | j	 k sg | j	 d k rz t
 } | | _ Pq | j | j ƒ r t j | j | j ƒ r t
 } | | _ Pq q W| S(   s%   Add a matching template to the sourceR>   (   R   R’   t   ret   searchR”   R   RU   t
   match_nameR   R   R
   R)   R   (   R+   R^   t   foundR)   (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyRU   Ð  s    !		(   RR   RS   RT   R,   RU   (    (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyR   ½  s   	t   __main__s   entry %ss!   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(   t
   __future__R    R   R\   R‚   t   os.pathRu   R–   Rx   R|   R#   t   distinfoR   t   __all__R   R   t   objectR   R   R   R   RR   t   init_configRn   R`   t   infoRL   t   mirror(    (    (    s:   /usr/lib/python2.7/dist-packages/aptsources/sourceslist.pyt   <module>   s8   			
¬´(
		
