
    8.g,U                         S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJ r   " S S\	5      r
 " S S5      r " S S	\5      r " S
 S\5      r " S S\5      rS rSSSS/ 0 4S jrg)    N)ElementTree)gettextc                       \ rS rSrSrg)NoDistroTemplateException$    N)__name__
__module____qualname____firstlineno____static_attributes__r       3/usr/lib/python3/dist-packages/aptsources/distro.pyr   r   $   s    r   r   c                   f    \ rS rSr/ 0 4S jrS rSS jrS rS rSS jr	S	 r
S
 rS rS rS rSrg)Distribution(   c                     UR                  5       U l        X l        X0l        X@l        XPl        X`l        SU l        SU l        g)z0Container for distribution specific informationsdebzdeb-srcN)	loweridcodenamedescriptionreleaseis_likelike_codenamesbinary_typesource_type)selfr   r   r   r   r   r   s          r   __init__Distribution.__init__)   s<     ((* &, $r   c                 R
   Xl         SU l        / U l        / U l        / U l        / U l        / U l        / U l        / U l        / U l	        SU l
        / U l        SU l        SU l        SU l        / U l        U R                   R                   R"                   HG  nU R%                  UR&                  5      (       d  M%  UR(                  U R*                  :X  d  MA  X l          O   U R                  c'  [-        SU R*                  < SU R.                  < 35      e/ n/ n/ n/ nU R                   R1                  5        GH  nUR2                  (       Gd  U R%                  UR4                  5      (       Gaa  UR6                  (       GaO  UR6                  R8                  (       Ga3  U R%                  UR6                  R&                  5      (       Ga  UR:                  R=                  S5      (       aI  UR>                  (       d8  U R
                  RA                  U5        URC                  URD                  5        GOUR:                  R=                  S5      (       a.  UR>                  (       a  U R
                  RA                  U5        GOQURF                  U RH                  :X  ac  UR>                  (       dR  U R                  RA                  U5        URC                  URD                  5        URA                  UR:                  5        OURF                  U RH                  :X  a-  UR>                  (       a  U R                  RA                  U5        OURF                  U RJ                  :X  a-  UR>                  (       d  U R                  RA                  U5        OFURF                  U RJ                  :X  a,  UR>                  (       a  U R                  RA                  U5        UR2                  (       a  GM  UR6                  U R                  RL                  ;   d  GM  UR>                  (       d8  URF                  U RH                  :X  a  U R                  RA                  U5        GM  UR>                  (       d8  URF                  U RJ                  :X  a  U R                  RA                  U5        GMe  U R                  RA                  U5        GM     [O        U5      U l        [O        U5      U l        URC                  U5        URC                  U5        [O        U5      U l        [O        U5      U l	        U RQ                  5         g)zN
Find the corresponding template, main and child sources
for the distribution
NF z2Error: could not find a distribution template for /cdrom:))sourceslistsource_templatechild_sourcesmain_sourcesdisabled_sourcescdrom_sourcesdownload_compsenabled_compscdrom_comps
used_mediaget_source_codesource_code_sourcesdefault_servermain_servernearest_serverused_serversmatcher	templatesis_codenamenamedistributionr   r   r   exploded_listinvaliddisttemplateofficialuri
startswithdisabledappendextendcompstyper   r   childrensetget_mirrors)r   r%   r=   mediarD   r-   r,   sources           r   get_sourcesDistribution.get_sources9   s    '# " $#%  !  ((00::H..83H3HDGG3S (0$ ; '+77DMM+  &&446FNNN$$V[[11OOOOO,,,$$V__%9%9:: ::((226??&&--f5&&v||4ZZ**844&&--f5[[D$4$44V__%%,,V4LL.LL,[[D$4$44))008[[D$4$44V__,,33F;[[D$4$44))008>>>foo9M9M9V9V&V6;;$:J:J+J&&--f5V[[D<L<L-L,,33F;))008? 7@ "%j{+U#[) /e*r   Nc                    U R                   R                  U l        U R                   H6  nUR	                  S5      (       a  M  U R
                  R                  U5        M8     [        U R                  5      S:X  a  U R                  U l	        OU R                  S   R                  U l	        0 U l        Sn[        R                  R                  U5      (       a  [        US9n[!        USS5      c  UR"                  Ul        UR%                  S5      nU HU  n UR&                  S   n UR&                  S
   n[*        R,                  " SU5      U R                  UR/                  5       '   MW     SU l        SU l        [        R4                  " SSS9n	U	R7                  S5      n
U	R7                  S5      nUS:X  a  [        U	5      nXS-   U R/                  5       nU(       a	  X-  U l        XR                  ;   a  U R                  U   U l        Xl        gg! [(         a    UR&                  S	   n GNf = f! [(         a    UR&                  S   n GNf = f)zB
Provide a set of mirrors where you can get the distribution from
r$   r   z%/usr/share/xml/iso-codes/iso_3166.xml)fileiterNiso_3166_entrycommon_namer8   alpha_2_codealpha_3_codeiso_3166LANGen_UK)default_.   )r&   base_urir2   r.   r@   r4   rB   lenr(   r1   r?   	countriesospathexistsr   getattrgetiteratorrO   attribKeyErrorr   dgettextr   countrycountry_codegetenvfindr3   )r   mirror_templatemediumfnameetitelmdescrcodelocaleazrh   s                r   rH   Distribution.get_mirrors   s   
  //88 ooF$$X..!!((0 &
 t  !Q&"&"2"2D"&"3"3A"6":":D 777>>%  %(B r64(0..)*B/JJ}5E6::n5D 07/?/?
E/Rtzz|,   673KKKK7FA!ea(..0"1"@D>>)>>,7DL , *+   /JJv.E/   6::n5D6s$   H'H2H/.H/2IIc                     SnUR                  S5      nUR                  S5      nUS:w  a  US:w  a  X[        S5      -   U nX R                  ;   a  [        S5      U R                  U   -  $ SUR	                  S5      -  $ )zgTry to get a human readable name for the main mirror of a country
Customize for different distributionsNz://z.archive.ubuntu.comrZ   Server for %s%s/ )rj   r]   r^   rX   rstripr   serverrg   ilis        r   _get_mirror_nameDistribution._get_mirror_name   s|     KK[[./7rRxU^b1Gnn$_%w(???&-----r   c                    S n/ n[        U R                  5      S:  d>  [        U R                  5      S:X  a  U" U R                  S   U R                  5      (       aq  UR                  [	        S5      U R                  S/5        U R
                  (       a7  UR                  U R                  U R
                  5      U R
                  S/5        U$ [        U R                  5      S:X  a  U" U R                  S   U R                  5      (       d  UR                  [	        S5      U R                  S/5        U R                  S   nU R
                  (       aN  U" X0R
                  5      (       d7  UR                  U R                  U R
                  5      U R
                  S/5        U(       a#  UR                  U R                  U5      US/5        U$ [        U R                  5      S:  a  UR                  [	        S5      U R                  S/5        U R
                  (       a7  UR                  U R                  U R
                  5      U R
                  S/5        UR                  [	        S5      SS/5        U R                   H_  nU R                  U5      US/nU" X0R
                  5      (       d  U" X0R                  5      (       a  MG  XB;  d  MN  UR                  U5        Ma     U$ )	z+Return a list of used and suggested serversc                 l    [         R                  " U R                  S5      UR                  S5      5      $ )z[Helper function that handles comaprision of mirror urls
that could contain trailing slashesrz   )rematchstripr{   )mir1mir2s     r   compare_mirrors5Distribution.get_server_list.<locals>.compare_mirrors   s'     88DJJt,dkk$.?@@r   r[   r   zMain serverTFzCustom serversN)r]   r4   r2   rB   rX   r3   r   )r   r   mirrorsr}   mirror_entrys        r   get_server_listDistribution.get_server_list   s   	A t  !A%!!"a' 1 1! 4d6F6FGGNNAm,d.>.>EF""--d.A.AB++d W ""#q(a $"2"22
 2
 NNAm,d.>.>FG&&q)F ""&v/B/BCCNN 11$2E2EF //!  5 5f =vtLM2 / ""#a' NNAm,d.>.>FG""--d.A.AB++ NNA./t<=++ $ 5 5f =vuM"6+>+>???,,D D !0NN<0 , r   c                 N   Uc  U R                   nUc  U R                  nUc  [        U R                  5      nUc  U R                  nSnSn[        U R                  5      =(       d    [        U R                  5       H  nUR                  n  O   U R                  R                  XX4XVUS9nU R                  (       ak  XR                  :X  a[  U R                  R                  U R                  UUUUUR                  UU R                  R                  R                  U5      S-   S9  ggg)z#
Add distribution specific sources
N)parentrN   r[   )rN   r   pos)r1   r   listr,   r   reversedr'   r(   rN   r%   addr/   r   index)	r   rE   r?   r<   rD   commentr   rN   
new_sources	            r   
add_sourceDistribution.add_source  s!    ;%%C<==D=++,E<##Dt112Qht?P?P6QQF;;D R %%))tG * 


 D,<,<$<    __!$$))//
;a? ! 	 %=r   c                 T   [        U/5      nU R                   Hr  nUR                  R                   HU  nUR                  U:X  d  M  UR
                  (       d  M(  UR
                  U;  d  M:  UR                  UR
                  5        MW     Mt     U H  nU R                  U5        M     g)z
Enable a component in all main, child and source code sources
(excluding cdrom based sources)

comp:         the component that should be enabled
N)r   r(   r=   
componentsr8   parent_componentrB   _enable_component)r   comprD   rJ   cs        r   enable_componentDistribution.enable_component?  s     dV''F__//66T>a&8&8&8))6Q%7%78 0 (
 A""1% r   c                   ^ U4S jn/ nUR                  U R                  5        UR                  U R                  5        0 n0 nU Hu  nUR                  U R                  :X  d  M  UR
                  U;  a  [        5       XFR
                  '   UR                   H   nXFR
                     R                  U5        M"     Mw     U R                   Hu  nUR                  U R                  :X  d  M  UR
                  U;  a  [        5       XVR
                  '   UR                   H   nXVR
                     R                  U5        M"     Mw     [        U R                  5      S:  a  U R                  ST-  /S9  O,U H  nU" X5        M     U R                   H  nU" X5        M     U R                  (       aT  [        U R                  5      S:  a  U R                  U R                  ST-  /S9  g U R                   H  nU" X5        M     g g )Nc                    > U R                   U;  a  gTXR                      ;   a  gU R                  T/-   U l        XR                      R                  T5        g)z
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<   rD   r   )rJ   comps_per_distr   s     r   add_component_only_once?Distribution._enable_component.<locals>.add_component_only_onceQ  sO     {{.0 ~kk22!<<4&0FL;;'++D1r   r[   ry   )rD   )rE   rD   )rC   r(   r'   rE   r   r<   rG   rD   r   r0   r   r]   r   r/   )	r   r   r   sourcesr   comps_per_sdistsr   rJ   s	    `       r   r   Distribution._enable_componentP  s   	2$ t(()t))* Avv)))66/-0UN66*A"66*..q1 !	  ))Avv)))660.1eOFF+A#FF+//2 !	 * t  !A%OO4$;-O0 "'? " 22'@ 3 4++,q0T%5%5dTk]K #66F+FD 7  r   c                    / nUR                  U R                  5        UR                  U R                  5        UR                  U R                  5        XR                  ;   a  / nUR                  U R                  5        U Hm  nXR
                  ;   d  M  UR
                  nUR                  U5        XCl        [        UR
                  5      S:  d  MR  U R                  R                  U5        Mo     g)z`
Disable a component in all main, child and source code sources
(excluding cdrom based sources)
r[   N)	rC   r(   r'   r0   r-   rD   remover]   r%   )r   r   r   rJ   rD   s        r   disable_componentDistribution.disable_component  s    
 t(()t))*t//0###GNN4,,-F||#T"$v||$q($$++F3 r   c                 J  ^  U 4S jn/ n/ nUT l         T R                   H  nU" XQU5        M     T R                   HI  nUR                  R                  b&  UR                  R                  UR
                  :w  d  M@  U" XQU5        MK     T R                   H  nU" XQU5        M     g)z@Change the server of all distro specific sources to
a given hostc                 f  > Xl         U R                   He  nU R                   U R                  U/U;   a  U R                  R                  U5        M=  UR	                  U R                   U R                  U/5        Mg     [        U R                  5      S:  a  TR                  R                  U 5        g g )Nr[   )r?   rD   r<   r   rB   r]   r%   )rJ   r?   seenr   r   s       r   change_server_of_source;Distribution.change_server.<locals>.change_server_of_source  s    JJJT2d:LL''-KKV[[$ ?@	 %
 6<< 1$  ''/ %r   N)r1   r(   r'   r=   r\   r?   r0   )r   r?   r   seen_binaryseen_sourcerJ   s   `     r   change_serverDistribution.change_server  s    		0 !''F#F= (((F ((0??++vzz9'[A ) ..F#F= /r   c                 $    XR                   :X  a  gg)z/Compare a given name with the release codename.TF)r   r   r8   s     r   r7   Distribution.is_codename  s    == r   )r   r-   r*   r'   r   r^   rg   rh   r1   r   r)   r+   r,   r/   r   r   r   r2   r(   r3   r   r0   r&   r   r%   r.   r4   N)NNNNr"   )r	   r
   r   r   r   rK   rH   r   r   r   r   r   r   r   r7   r   r   r   r   r   r   (   sF    :<R% Tl6-p.CJ#J&";Ez4(><r   r   c                   *    \ rS rSrSrS rS rS rSrg)DebianDistributioni  z)Class to support specific Debian featuresc                 D    XR                   :X  d  U R                  S;   a  gg)zuCompare a given name with the release codename and check if
if it can be used as a synonym for a development releases)testingunstableTF)r   r   r   s     r   r7   DebianDistribution.is_codename  s      == DLL4K$Kr   c                 `   SnUR                  S5      nUR                  S5      nUS:w  a  US:w  a  X[        S5      -   U nX R                  ;   aL  [        S5      [        R
                  " SU R                  U   R                  5       5      R                  5       -  $ SUR                  S5      -  $ )	zQTry to get a human readable name for the main mirror of a country
Debian specificNz://ftp.z.debian.orgrZ   rx   rT   ry   rz   )rj   r]   r^   rX   r   rf   r{   r|   s        r   r   #DebianDistribution._get_mirror_name  s     KK	"[['7rRxY/"5Gnn$ /"""w 7 > > @&( &-----r   c                 ,    [         R                  U SS9  g )Nz http://ftp.%s.debian.org/debian/rk   r   rH   r   s    r   rH   DebianDistribution.get_mirrors  s      "D 	! 	
r   r   N)	r	   r
   r   r   __doc__r7   r   rH   r   r   r   r   r   r     s    3.&
r   r   c                       \ rS rSrSrS rSrg)UbuntuDistributioni  z)Class to support specific Ubuntu featuresc                 ,    [         R                  U SS9  g )Nz$http://%s.archive.ubuntu.com/ubuntu/r   r   r   s    r   rH   UbuntuDistribution.get_mirrors  s      "H 	! 	
r   r   Nr	   r
   r   r   r   rH   r   r   r   r   r   r     s
    3
r   r   c                       \ rS rSrSrS rSrg)UbuntuRTMDistributioni  z-Class to support specific Ubuntu RTM featuresc                 :    U R                   R                  U l        g r   )r&   r\   r2   r   s    r   rH   !UbuntuRTMDistribution.get_mirrors  s    //88r   )r2   Nr   r   r   r   r   r     s
    79r   r   c                  v   SSK n SSKJnJnJn   U" SS/UUSS9R                  5       S   nUR                  5        H0  nUR                  S5      (       d  M  UR                  S	S
5      S
   s  $    g! [         a=  nUR                   U R                  :w  a  [        R                  " SU-  5         SnAgSnAff = f)z=Get the current channel from system-image-cli -i if possible.r   N)DEVNULLPIPEPopenzsystem-image-cliz-iT)stdoutstderruniversal_newlinesz	channel: z: r[   z+system-image-cli failed, using defaults: %s)errno
subprocessr   r   r   communicate
splitlinesr@   splitOSErrorENOENTloggingwarning)r   r   r   r   outlineexcs          r   _system_image_channelr     s    //Q&#	

 +- NN$D{++zz$*1-- %   Q99$OOICOPQs$   AA1 A1 .A1 1
B8;3B33B8c                 r   U b  U R                  5       n U (       a  U(       a  U(       a  U(       d  [        R                  " 5       nUS   n US   nUS   nUR                  S5      nUR                  S/ 5      nU H/  nUR                  SUR	                  5       -  S5      nUc  M+  XU'   M1     U S:X  aA  [        5       n	U	b4  S	U	;   a.  S
n U	R                  SS5      S   R                  SS5      S   nUnUnU S:X  a  [        XX#XE5      $ U S
:X  a  [        XX#XE5      $ U S:X  a  [        XX#XE5      $ [        XX#XE5      $ )z
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
NIDVERSION_CODENAMEPRETTY_NAME
VERSION_IDID_LIKEz%s_VERSION_CODENAMEubuntuzubuntu-rtm/z
ubuntu-rtmr#   r[   -r   debian)r   platformfreedesktop_os_releasegetupperr   rsplitr   r   r   r   r   )
r   r   r   r   r   r   
os_releaselike_idlike_codenamechannels
             r   
get_distror     s]     
~XXZ8446
01 /.....B/ G&NN%7M (*7w'  >+-G"}'?!">>#q1!4::3B1E&"	X~!+
 	
 
\$+
 	
 
x!+
 	
 B+XXr   )r   r   r_   r   r   xml.etree.ElementTreer   apt_pkgrX   	Exceptionr   r   r   r   r   r   r   r   r   r   <module>r      sz   4   	  	 -  		 	\ \~!
 !
H
 
9. 9, 5Yr   