
    \eo<              
          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lmZm	Z	 d dl
mZ d dlZd dlmZ dededee   fd	Z G d
 d      Z G d d      Z G d d      Z G d d      Zdedee   fdZ G d d      Zedk(  rq edd      Z ej4                  ej6                         ej8                  D ];  Z ej4                  dej<                  z          ej4                  dej>                  z          ej4                  dej@                  z          ej4                  dejB                  z         ejD                  i k7  r3 ej4                  d eejD                  jG                               z         ejH                  D ];  Z% ej4                  de%j<                   de%j>                   de%jL                          = ejN                  D ]!  Z( ej4                  d e(j>                  z         # > yy)!    N)Iterator)PIPEPopen)cast)gettexttemplatecsv_pathreturnc           	   #     	K   t               }t        j                  |       5 }|D ]k  }d|v r#|j                  |d   j	                  d             d|v rd|d   v r nA|j                  |d          t        |      j                         E d{    m 	 ddd       y|D ]  }d|v s|j                  |d           	 ddd       t        |      5 }t        t        t        j                  |                  }ddd       D ]  }|d   |v rd |d   j                  d	d      |d<   t        j                  |       5 }|D ]  }d|vsd|d   vrd
|v r,|d   	t        	fd|d
   j	                  d      D              r? t        |      j                  di |j                         D ]  }|j!                  d
      r|   	 ddd        t        j                  |       5 }|D ]  }d|v sd|d   v s n |D ]/  }d|v rd|d   v rt        |      j                         E d{    1 	 ddd       y7 # 1 sw Y   xY w# 1 sw Y   TxY w# 1 sw Y   _xY w7 :# 1 sw Y   yxY ww)a~  Expand the given template.

    A template file consists of a header, followed by paragraphs
    of templated suites, followed by a footer. A templated suite
    is any paragraph where the Suite field contains {.

    This function expands all templated suites using the information
    found in the CSV file supplied by distro-info-data.

    It yields lines of template info.
    zX-Exclude-Suitesz, Suite{Nseries versionz LTSz	X-Versionc              3      K   | ]d  }|j                  d       xr t        j                  |dd       dk  xs/ |j                  d      xr t        j                  |dd       dkD   f yw)le   Nr   ge)
startswithapt_pkgversion_compare).0fieldvers     5/usr/lib/python3/dist-packages/aptsources/distinfo.py	<genexpr>z#_expand_template.<locals>.<genexpr>Y   s      
 " ",,T2 L ' 7 7ab	3 G! K
 ",,T2 L ' 7 7ab	3 G! K
s   A*A- )setr   TagFileupdatesplitaddstr
splitlinesopenreversedlistcsv
DictReaderreplaceanyformatr   )
r   r	   known_suitestmplsection
csv_objectreleasesrelliner   s
            @r   _expand_templater4   %   s     5L 
	" 3d 	G!W,##G,>$?$E$Ed$KL'!''**  !127|..000	 3 3  	3G'!  !12	33& 
h >:D
!;<=>  x=L(Y//;I__X& 	$ ')S8H-H')i.C 
 &-[%9%?%?%E
 
 !/CL//6#6AAC D{3 J)	 	@ 
	" 1d 	G'!cWW-=&=	  	1G '!cWW-=&=7|..000	11 1[ 13 3&> >	 	N 11 1s    I4A*H?H<H?	I4	H?(H??I4(I:AI4 BI	I4(
I(3I(;0I(+I&,I(3	I4<H??I	I4II4I#	I4&I((I1-I4c                   4    e Zd ZddZdedefdZdedefdZy)	Templater
   Nc                     d | _         d| _        g | _        d | _        d | _        d | _        d | _        g | _        g | _        d | _	        i | _
        d | _        d| _        d| _        y NFT)namechildparents
match_namedescriptionbase_uritype
componentschildren	match_uri
mirror_setdistribution	availableofficialselfs    r   __init__zTemplate.__init__|   sf     $	
')&*'+$( $	+-(*%)-/(,    compc                 ,    |d | j                   D        v S )z6Check if the distribution provides the given componentc              3   4   K   | ]  }|j                     y wN)r9   )r   cs     r   r   z)Template.has_component.<locals>.<genexpr>   s     818s   )r@   )rH   rK   s     r   has_componentzTemplate.has_component   s    8888rJ   urlc                 |    t        |      \  }}}|| j                  v r| j                  |   j                  ||      S y)z6Check if a given url of a repository is a valid mirrorF)	split_urlrC   has_repository)rH   rQ   protohostnamedirs        r   	is_mirrorzTemplate.is_mirror   s=    (~xt&??8,;;E3GGrJ   )r
   N)__name__
__module____qualname__rI   r#   boolrP   rX   r   rJ   r   r6   r6   {   s-     9# 9$ 9S T rJ   r6   c            
           e Zd Z	 	 	 ddededz  dedz  dedz  fdZdedz  fdZd	eddfd
Zdedz  fdZdeddfdZdeddfdZ	dedz  fdZ
y)	ComponentNr9   desc	long_descparent_componentc                 <    || _         || _        || _        || _        y rN   )r9   r=   description_longra   )rH   r9   r_   r`   ra   s        r   rI   zComponent.__init__   s#     	 ) 0rJ   r
   c                     | j                   S rN   ra   rG   s    r   get_parent_componentzComponent.get_parent_component       $$$rJ   parentc                     || _         y rN   re   )rH   rh   s     r   set_parent_componentzComponent.set_parent_component   s
     &rJ   c                 d    | j                   | j                   S | j                  | j                  S y rN   )rc   r=   rG   s    r   get_descriptionzComponent.get_description   s5      ,((()###rJ   c                     || _         y rN   )r=   rH   r_   s     r   set_descriptionzComponent.set_description   s
    rJ   c                     || _         y rN   rc   rn   s     r   set_description_longzComponent.set_description_long   s
     $rJ   c                     | j                   S rN   rq   rG   s    r   get_description_longzComponent.get_description_long   rg   rJ   )NNN)rY   rZ   r[   r#   rI   rf   rj   rl   ro   rr   rt   r   rJ   r   r^   r^      s       $'+
1
1 Dj
1 :	
1
 *
1%cDj %'3 '4 't  C  D  % % %%cDj %rJ   r^   c            
           e Zd ZdZ	 ddededededz  fdZdededdfd	Zdeded
   fdZdedede	fdZ
dee   fdZdedz  fdZdeddfdZy)Mirrorz&Storage for mirror related informationNrU   rV   rW   locationc                 R    || _         g | _        | j                  ||       || _        y rN   )rV   repositoriesadd_repositoryrw   )rH   rU   rV   rW   rw   s        r   rI   zMirror.__init__   s*     !.0E3' rJ   r
   c                 N    | j                   j                  t        ||             y rN   )ry   append
RepositoryrH   rU   rW   s      r   rz   zMirror.add_repository   s      E3!78rJ   r}   c                 `    | j                   D cg c]  }|j                  |k(  s| c}S c c}w rN   )ry   rU   )rH   rU   rs      r   get_repositories_for_protoz!Mirror.get_repositories_for_proto   s'    ,,Aa50@AAAs   ++c                 l    |y| j                   D ]"  }|j                  |k(  s||j                  v s" y yr8   )ry   rU   rW   )rH   rU   rW   r   s       r   rT   zMirror.has_repository   s=    ;"" 	Aww%C155L	 rJ   c                 r    | j                   D cg c]  }|j                  | j                         c}S c c}w rN   )ry   get_urlrV   )rH   r   s     r   get_repo_urlszMirror.get_repo_urls   s)    262C2CDQ		$--(DDDs   "4c                     | j                   S rN   rw   rG   s    r   get_locationzMirror.get_location   s    }}rJ   c                     || _         y rN   r   )rH   rw   s     r   set_locationzMirror.set_location   s	     rJ   rN   )rY   rZ   r[   __doc__r#   rI   rz   r'   r   r\   rT   r   r   r   r   rJ   r   rv   rv      s    0 KO!!$'!.1!=@4Z!9C 9c 9d 9B B\8J BC c d EtCy EcDj !S !T !rJ   rv   c                   F    e Zd ZdededdfdZdeeef   fdZdedefdZy)	r}   rU   rW   r
   Nc                      || _         || _        y rN   rU   rW   r~   s      r   rI   zRepository.__init__   s    
rJ   c                 2    | j                   | j                  fS rN   r   rG   s    r   get_infozRepository.get_info   s    zz488##rJ   rV   c                 >    | j                    d| d| j                   S )Nz:///r   )rH   rV   s     r   r   zRepository.get_url   s!    **S
!DHH:66rJ   )rY   rZ   r[   r#   rI   tupler   r   r   rJ   r   r}   r}      sC    c   $%S/ $7 7 7rJ   r}   rQ   c                     t        j                  d| d      }t        |      dk  r |j                  d       t        |      dk  r |S )zCsplit a given URL into the protocoll, the hostname and the dir partz:*\/+   )maxsplitr   N)rer!   lenr|   )rQ   r!   s     r   rS   rS      s=    HHXsQ/E
e*q.T e*q.LrJ   c                   B    e Zd Z	 	 d	dedz  defdZdededz  ddfdZy)
DistInfoNdistbase_dirc                    d| _         g | _        t        j                  j	                  d      | _        d }t        j                  d      }t        j                  d      }|s4	 t        g ddt              j                         d   j                         }|| _        i }| d| d}d|j%                          d}	t'        t(        d       }
t'        t*        d       }t-        ||	      D ]  }|j/                  dd      }t1        |      dk  r%|d   j                         }|d   j                         }|dk(  rt3        |      | _        a|dk(  r|| _         n|dk(  rE| j7                  |
|       t'        t*        d       }t)               }
||
_        ||
_        d|z  |
_        |dk(  r||
_        |dk(  r`d|
_        | j                  D ]H  }|j8                  |k(  s|
j@                  jC                  |       |jD                  jC                  |
       J *|dk(  rt        jF                  |      |
_$        K|dk(  rt        jF                  |      |
_%        l|dk(  r	||
_&        z|dk(  r|
jN                  s	||
_'        |d| j
                  z  k(  r	||
_'        |dk(  r|
jP                  s	||
_(        |d| j
                  z  k(  r	||
_(        |dk(  s|d | j
                  z  k(  r.tR        jT                  jW                  |      xr |xs= tR        jT                  jY                  tR        jT                  j[                  ||            }||vri }	 t]        |      5 }t_        ta        |jb                  |D cg c]  }|j                          c}            }d d d        D ]`  }|ji                  d"      r|jk                  d#|      }'tm        |      \  }}}||v r||   jo                  ||       Ptq        ||||      ||<   b |||<   ||   |
_9        *|d$k(  rt3        |      |
_:        A|d%k(  rE|r6|
jw                  |j8                        s|
jx                  jC                  |       t+        |      }|d&k(  r|j{                  t3        |             |d'k(  r|j}                  t3        |             |d(k(  s|j                  |        | j7                  |
|       t'        t(        d       }
t'        t*        d       }y # t        $ rB}|j                  t        j                  k7  rt        j                   d	|z         d
}Y d }~d }~ww xY wc c}w # 1 sw Y   xY w# td        $ r tg        d!|        g }Y w xY w))Nr   zAPT::Architecturez^#LOC:(.+)$zS^(#LOC:.+)|(((http)|(ftp)|(rsync)|(file)|(mirror)|(https))://[A-Za-z0-9/\.:\-_@]+)$)lsb_releasez-iz-sT)universal_newlinesstdoutr   z&lsb_release failed, using defaults: %sDebianr   z.infoz/usr/share/distro-info/z.csv:   r   ChangelogURIMetaReleaseURIr   z^%s$	MatchNameParentSuite	AvailableOfficialRepositoryTypeBaseURIz
BaseURI-%sMatchURIzMatchURI-%sMirrorsFilezMirrorsFile-%sz$WARNING: Failed to read mirror file z#LOC:z\1Descriptionr^   CompDescriptionCompDescriptionLongParentComponent)@metarelease_uri	templatesr   configfindarchr   compiler   r   communicatestripOSErrorerrnoENOENTloggingwarningr   lowerr   r6   r^   r4   r!   r   _changelogs_urifinish_templater9   rD   r<   r:   r;   r|   rA   string_to_boolrE   rF   r?   r>   rB   ospathisabsabspathjoinr%   r'   filtermatch	Exceptionprintr   subrS   rz   rv   rC   r=   rP   r@   ro   rr   rj   )rH   r   r   rw   	match_locmatch_mirror_lineexcmap_mirror_sets
dist_fname	csv_fnamer   	componentr3   tokensr   valuenannyrC   value_fxmirror_datarU   rV   rW   s                           r   rI   zDistInfo.__init__   s   
  ")+NN''(;<	JJ~.	JJ&
  3+/#
 ![]1& UW  	 z4&.
-djjl^4@	 $'D)	$Z; T	6DZZQ'F6{Q1IOO%E1IOO%E&&'h#**',$'!$$Xy9 D1	#: %(,%&,un#+%&+#-'!%!^^ 8EzzU* ((//6--h7	8
 +%%,%;%;E%B"*$$+$:$:5$A!** %)#H,=,=$)!,22$)!*$X-?-?%*"-$))33%*"-'54Dtyy4P+P GGMM%( Fwwrww||He'DE 
 /46J
)!%[ G*. &$5$;$;8?$@1QWWY$@!"+K !, 
??73'0}}UD'AH$1:4.##z1&x0??sK39 %xh4Jx0
 .8OE*&5e&<#-''(x$+%X%;%;INN%K''..y9%e,	++))!E(3//..qx8++..u5iT	6j 	Xy1$'D)	M   99,OO$Ls$RS J %A	  % ) DUGLM&()sT   "3T U!U0UUU!	U
7UUUU	U!!U>=U>r   r   r
   c                    |sy|j                   <|j                  r0|j                  D ]!  }|j                   s|j                   |_          n |j                  i k(  r<|j                  r0|j                  D ]!  }|j                   s|j                  |_         n |r8|j	                  |j
                        s|j                  j                  |       d}|j                  D ]  }|j                  |_         | j                  j                  |       y)zfinish the current tempalteN)
rB   r:   r;   rC   rP   r9   r@   r|   rF   r   )rH   r   r   ts       r   r   zDistInfo.finish_templatez  s    %(..%% ;;)*H& "$%% ;;*+,,H' X33INNC&&y1I!! 	+A !

H	+h'rJ   )N/usr/share/python-apt/templates)rY   rZ   r[   r#   rI   r6   r^   r   r   rJ   r   r   r      sI      9B*DjB* B*H( (Y=M (RV (rJ   r   __main__Ubuntur   z

Suite: %szDesc: %szBaseURI: %szMatchURI: %szMirrors: %s z -z  %s))r(   r   r   r   r   collections.abcr   
subprocessr   r   typingr   r   r   r   r#   r4   r6   r^   rv   r}   r'   rS   r   rY   dinfor   r   r   r9   r=   r>   rB   rC   keysr@   rK   rc   rA   r:   r   rJ   r   <module>r      s  0    	 	 $ "    S1s S1c S1hsm S1l <"% "%J !  !F	7 	73 49 Z( Z(z z<=AGLL!!"KK 
5]X]]23Z("6"667]X%6%667^h&8&889"$GLLh.A.A.F.F.H)IIJ'' 	WDGLL1TYYKr$*:*:);2d>S>S=TUV	W&& 	5EGLL%"3"334	5
5 rJ   