
    xkd]=              
          d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	Z	d dl
mZmZmZmZmZmZ d dlZd dlmZ dededee         fd	Z G d
 de          Z G d de          Z G d de          Z G d de          Zdedee         fdZ G d de          Zedk    r edd          Z ej        ej                    ej!        D ]Z" ej        de"j#        z              ej        de"j$        z              ej        de"j%        z              ej        de"j&        z             e"j'        i k    r3 ej        d e(e"j'        )                                          z             e"j*        D ]*Z+ ej        de+j#        de+j$        de+j,                   +e"j-        D ]Z. ej        d e.j$        z             dS dS )!    )print_functionN)PopenPIPE)castDictIteratorListOptionalTuple)gettexttemplatecsv_pathreturnc           	   #     	K   t                      }t          j        |           5 }|D ]}d|v r.|                    |d                             d                     d|v r'd|d         v r nQ|                    |d                    t          |                                          E d{V  	 ddd           dS |D ]!}d|v r|                    |d                    "	 ddd           n# 1 swxY w Y   t          |          5 }t          t          t          j        |                              }ddd           n# 1 swxY w Y   |D ]}|d         |v rdV  |d                             d	d          |d<   t          j        |           5 }|D ]}d|vs
d|d         vrd
|v r=|d         	t          	fd|d
                             d          D                       rR t          |          j        di |                                D ]}|                    d
          r|V  	 ddd           n# 1 swxY w Y   t          j        |           5 }|D ]}d|v rd|d         v r n|D ]8}d|v rd|d         v rt          |                                          E d{V  9	 ddd           dS # 1 swxY w Y   dS )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   | ]p}|                     d           o t          j        |dd                   dk     p5|                     d          o t          j        |dd                   dk    V  qdS )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>b   s       
 
 " ",,T22 L ' 7abb	3 G G! K
 ",,T22 L ' 7abb	3 G G! K
 
 
 
 
 
     )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_templater:   .   s      55L 
	"	" 3d 	 	G!W,,##G,>$?$E$Ed$K$KLLL'!!''***E  !12227||..0000000000 3 3 3 3 3 3 3 3  	3 	3G'!!  !1222	33 3 3 3 3 3 3 3 3 3 3 3 3 3 3& 
h >:D
!;!;<<==> > > > > > > > > > > > > > >   x=L((Y//;;I_X&& 	$  '))S8H-H-H'))i.C 
 
 
 
 &-[%9%?%?%E%E
 
 
 
 
 ! !/CLL/66#66AACC  D{33 ! JJJJ)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	6 
	"	" 1d 	 	G'!!cWW-=&=&= 	1 	1G '!!cWW-=&=&=7||..0000000000	11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1sP   BC/>$C//C36C3	/EEEBII	I	!AK  KKc                   6    e Zd ZddZdedefdZdedefdZdS )	Templater   Nc                     d | _         d| _        g | _        d | _        d | _        d | _        d | _        g | _        g | _        d | _	        i | _
        d | _        d| _        d| _        d S 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__   sj    #'	
'))-*.'+#'	+-(*(,-/+/r"   compc                 (    |d | j         D             v S )z6Check if the distribution provides the given componentc              3   $   K   | ]}|j         V  d S N)r?   )r   cs     r    r!   z)Template.has_component.<locals>.<genexpr>   s$      881888888r"   )rF   )rN   rP   s     r    has_componentzTemplate.has_component   s    8888888r"   urlc                     t          |          \  }}}|| j        v r!| j        |                             ||          S dS )z6Check if a given url of a repository is a valid mirrorF)	split_urlrI   has_repository)rN   rV   protohostnamedirs        r    	is_mirrorzTemplate.is_mirror   sC    (~~xt&&?8,;;E3GGG5r"   )r   N)__name__
__module____qualname__rO   r)   boolrU   r]   r#   r"   r    r<   r<      sl            9# 9$ 9 9 9 9S T      r"   r<   c            
           e Zd Z	 	 	 ddedee         dee         dee         fdZdee         fdZd	eddfd
Zdee         fdZdeddfdZ	deddfdZ
dee         fdZdS )	ComponentNr?   desc	long_descparent_componentc                 >    || _         || _        || _        || _        d S rS   )r?   rC   description_longrf   )rN   r?   rd   re   rf   s        r    rO   zComponent.__init__   s)     	 ) 0r"   r   c                     | j         S rS   rf   rM   s    r    get_parent_componentzComponent.get_parent_component       $$r"   parentc                     || _         d S rS   rj   )rN   rm   s     r    set_parent_componentzComponent.set_parent_component   s     &r"   c                 >    | j         | j         S | j        | j        S d S rS   )rh   rC   rM   s    r    get_descriptionzComponent.get_description   s+     ,(()##4r"   c                     || _         d S rS   )rC   rN   rd   s     r    set_descriptionzComponent.set_description   s    r"   c                     || _         d S rS   rh   rs   s     r    set_description_longzComponent.set_description_long   s     $r"   c                     | j         S rS   rv   rM   s    r    get_description_longzComponent.get_description_long   rl   r"   )NNN)r^   r_   r`   r)   r
   rO   rk   ro   rq   rt   rw   ry   r#   r"   r    rc   rc      s-        ##'*.
1 
1
1 sm
1 C=	
1
 #3-
1 
1 
1 
1%hsm % % % %'3 '4 ' ' ' '#     C  D        % % % % % %%hsm % % % % % %r"   rc   c            
           e Zd ZdZ	 ddedededee         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e         fdZdeddfdZdS )Mirrorz&Storage for mirror related informationNrZ   r[   r\   locationc                 \    || _         g | _        |                     ||           || _        d S rS   )r[   repositoriesadd_repositoryr|   )rN   rZ   r[   r\   r|   s        r    rO   zMirror.__init__   s4     !.0E3''' r"   r   c                 V    | j                             t          ||                     d S rS   )r~   append
RepositoryrN   rZ   r\   s      r    r   zMirror.add_repository   s)      E3!7!788888r"   r   c                 *    fd| j         D             S )Nc                 *    g | ]}|j         k    |S r#   )rZ   )r   rrZ   s     r    
<listcomp>z5Mirror.get_repositories_for_proto.<locals>.<listcomp>   s%    AAAa50@0@0@0@0@r"   r~   )rN   rZ   s    `r    get_repositories_for_protoz!Mirror.get_repositories_for_proto   s     AAAA4,AAAAr"   c                 P    |dS | j         D ]}|j        |k    r||j        v r dS dS r>   )r~   rZ   r\   )rN   rZ   r\   r   s       r    rY   zMirror.has_repository   sB    ;5" 	 	Aw%C15LLttur"   c                 *      fd j         D             S )Nc                 D    g | ]}|                     j                  S r#   )get_urlr[   )r   r   rN   s     r    r   z(Mirror.get_repo_urls.<locals>.<listcomp>   s'    DDDQ		$-((DDDr"   r   rM   s   `r    get_repo_urlszMirror.get_repo_urls   s     DDDD$2CDDDDr"   c                     | j         S rS   r|   rM   s    r    get_locationzMirror.get_location   s
    }r"   c                     || _         d S rS   r   )rN   r|   s     r    set_locationzMirror.set_location   s     r"   rS   )r^   r_   r`   __doc__r)   r
   rO   r   r	   r   ra   rY   r   r   r   r#   r"   r    r{   r{      sB       00 NR! !!$'!.1!=Ec]! ! ! !9C 9c 9d 9 9 9 9B B\8J B B B BC c d    EtCy E E E Ehsm    !S !T ! ! ! ! ! !r"   r{   c                   N    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dS )	r   rZ   r\   r   Nc                 "    || _         || _        d S rS   rZ   r\   r   s      r    rO   zRepository.__init__   s    
r"   c                     | j         | j        fS rS   r   rM   s    r    get_infozRepository.get_info   s    z48##r"   r[   c                 *    | j         d|d| j        S )Nz:///r   )rN   r[   s     r    r   zRepository.get_url   s    #zzz888TXX>>r"   )r^   r_   r`   r)   rO   r   r   r   r#   r"   r    r   r      s        c      $%S/ $ $ $ $? ? ? ? ? ? ? ?r"   r   rV   c                     t          j        d| d          }t          |          dk     r(|                    d           t          |          dk     (|S )zCsplit a given URL into the protocoll, the hostname and the dir partz:*\/+   )maxsplitr   N)rer'   lenr   )rV   r'   s     r    rX   rX      sO    HXsQ///E
e**q..T e**q..Lr"   c                   P    e Zd Z	 	 d
dee         defdZdedee         ddfd	ZdS )DistInfoN/usr/share/python-apt/templatesdistbase_dirc           	         d| _         g | _        t          j                            d          | _        d }t          j        d          }t          j        d          }|s	 t          g ddt                    
                                d                                         }nL# t          t          f$ r8}|j        t          j        k    rt!          j        d	|z             d
}Y d }~nd }~ww xY w|| _        i }|d|d}d                    |                                          }	t+          t,          d           }
t+          t.          d           }t1          ||	          D ]H}|                    dd          }t5          |          dk     r-|d                                         }|d                                         }|dk    rt7          |          | _        ||dk    r|| _         |dk    rR|                     |
|           t+          t.          d           }t-                      }
||
_        ||
_        d|z  |
_         |dk    r||
_         |dk    rRd|
_!        | j        D ]A}|j        |k    r4|
j"        #                    |           |j$        #                    |
           BH|dk    rt          j%        |          |
_&        i|dk    rt          j%        |          |
_'        |dk    r	||
_(        |dk    r|
j)        s	||
_)        |d| j        z  k    r	||
_)        |dk    r|
j*        s	||
_*        |d| j        z  k    r	||
_*        |dk    s|d| j        z  k    rhtV          j,        -                    |          r|p<tV          j,        .                    tV          j,        /                    ||                    }||vri }	 ta          |          5 }tc          te          |j3        d  |D                                 }d d d            n# 1 swxY w Y   n!# th          $ r tk          d!           g }Y nw xY w|D ]w}|6                    d"          r|7                    d#|          }.tq          |          \  }}}||v r||         9                    ||           btu          ||||          ||<   x|||<   ||         |
_;        p|d$k    rt7          |          |
_<        |d%k    rG|r4|
=                    |j                  s|
j>        #                    |           t/          |          }|d&k    r$|?                    t7          |                     |d'k    r$|@                    t7          |                     -|d(k    r|A                    |           J|                     |
|           t+          t,          d           }
t+          t.          d           }d S ))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/{}.csv:   r   ChangelogURIMetaReleaseURIr   z^%s$	MatchNameParentSuite	AvailableOfficialRepositoryTypeBaseURIz
BaseURI-%sMatchURIzMatchURI-%sMirrorsFilezMirrorsFile-%sc                 6    g | ]}|                                 S r#   )strip)r   xs     r    r   z%DistInfo.__init__.<locals>.<listcomp>`  s     $@$@$@1QWWYY$@$@$@r"   z#WARNING: Failed to read mirror filez#LOC:z\1Descriptionrc   CompDescriptionCompDescriptionLongParentComponent)Bmetarelease_uri	templatesr   configfindarchr   compiler   r   communicater   OSErrorIOErrorerrnoENOENTloggingwarningr   r2   lowerr   r<   rc   r:   r'   r   _changelogs_urifinish_templater?   rJ   rB   r@   rA   r   rG   string_to_boolrK   rL   rE   rD   rH   ospathisabsabspathjoinr+   r-   filtermatch	Exceptionprintr   subrX   r   r{   rI   rC   rU   rF   rt   rw   ro   )rN   r   r   r|   	match_locmatch_mirror_lineexcmap_mirror_sets
dist_fname	csv_fnamer   	componentr9   tokensr   valuenannyrI   value_fmirror_datarZ   r[   r\   s                          r    rO   zDistInfo.__init__   s   
  ")+N''(;<<	J~..	J&
 
  	  333+/#  
 ![]]1& UWW  W%      9,,O$Ls$RSSS 
 	%-XXttt4
3::4::<<HH	 $''D))	$Z;; T	6 T	6DZZQ''F6{{Q1IOO%%E1IOO%%E&&&'hh##***',$$'!!$$Xy999 D11	#:: %(,%&,un##+%%&+##-''!%!^ 8 8EzU** (//666--h777	8
 +%%%,%;E%B%B""*$$$+$:5$A$A!!*** %)##H,=#$)!!,222$)!!*$$X-?$%*""-$)333%*""-''54Dty4P+P+P GMM%(( Fwrw||He'D'DEE 
 //46J
)!%[[ G*. &$5$;$@$@$@$@$@!" !"+ +K               % ) ) )CDDD&() !, 
 
??733 %'0}}UD'A'AH$1:4.##z11&x0??sKKKK39 %xh4 4Jx00 .8OE*&5e&<##-'''(xx$$+%% :X%;%;IN%K%K :'..y999%e,,		+++))!E((3333///..qxx8888+++..u555Xy111$''D))			sO    AB$ $C-5.C((C-P#-PP#P	P#P	P##Q Qr   r   r   c                    |sdS |j         &|j        r|j        D ]}|j         r|j         |_          n|j        i k    r&|j        r|j        D ]}|j         r|j        |_         n|r6|                    |j                  s|j                            |           d}|j        D ]}|j        |_        | j	                            |           dS )zfinish the current tempalteN)
rH   r@   rA   rI   rU   r?   rF   r   rL   r   )rN   r   r   ts       r    r   zDistInfo.finish_template  s     	F%(.%%  ; )*H&E "$$$%  ; *+,H'E  	X33INCC 	&&y111I! 	+ 	+A !
Hh'''''r"   )Nr   )	r^   r_   r`   r
   r)   rO   r<   rc   r   r#   r"   r    r   r      s         #9B* B*smB* B* B* B* B*H( (-5i-@(	( ( ( ( ( (r"   r   __main__Ubuntur   z

Suite: %szDesc: %szBaseURI: %szMatchURI: %szMirrors: %s z -z  %s)/
__future__r   r.   r   r   r   
subprocessr   r   r   typingr   r   r   r	   r
   r   r   r   r   r)   r:   objectr<   rc   r{   r   rX   r   r^   dinfor   r   r   r?   rC   rD   rH   rI   r-   keysrF   rP   rh   rG   r@   r#   r"   r    <module>r      s  0 & % % % % % 



   				 " " " " " " " " 				                            S1s S1c S1hsm S1 S1 S1 S1l    v   <"% "% "% "% "% "% "% "%J !  !  !  !  !V  !  !  !F	? 	? 	? 	? 	? 	? 	? 	?3 49    \( \( \( \( \(v \( \( \(~ z<==AGL!"""K 5 5]X]2333Z("66777]X%66777^h&88999"$$GLh.A.F.F.H.H)I)IIJJJ' 	 	DGLL!%D,<,<,<d>S>ST    & 	5 	5EGL%"334444	5 5 5r"   