\e6_ddlZddlZddlZddlZddlZddlZddlmZddlmZ Gdde Z GddZ Gdd e Z Gd d e ZGd d eZdZdZGddZddddgfdZy)N) ElementTree)gettextc eZdZy)NoDistroTemplateExceptionN)__name__ __module__ __qualname__3/usr/lib/python3/dist-packages/aptsources/distro.pyrr%sr rcVeZdZgfdZdZd dZdZdZddZdZ d Z d Z d Z d Z y) Distributioncf||_||_||_||_||_d|_d|_y)z0Container for distribution specific informationsdebzdeb-srcN)idcodename descriptionreleaseis_like binary_type source_type)selfrrrrrs r __init__zDistribution.__init__*s8  &   $r c ||_d|_g|_g|_g|_g|_g|_g|_g|_g|_ d|_ g|_ d|_ d|_ d|_g|_|jj j"D]@}|j%|j&s|j(|j*k(s9||_n|j%t-d|j*d|j.g}g}g}g}|jj1D]#}|j2sB|j%|j4r&|j6r|j6j8r|j%|j6j&r|j:j=drD|j>s8|j jA||jC|jDn}|j:j=dr)|j>r|j jA|n9|jF|jHk(r^|j>sR|jjA||jC|jD|jA|j:n|jF|jHk(r(|j>r|jjA|n|jF|jJk(r(|j>s|jjA|n@|jF|jJk(r'|j>r|jjA||j2ra|j6|jjLvs|j>s6|jF|jHk(r|jjA||j>s6|jF|jJk(r|jjA| |jjA|&tO||_tO||_|jC||jC|tO||_tO||_ |jQy)zf Find the corresponding template, main and child sources for the distribution NFz2Error: could not find a distribution template for /cdrom:)) sourceslistsource_template child_sources main_sourcesdisabled_sources cdrom_sourcesdownload_comps enabled_comps cdrom_comps used_mediaget_source_codesource_code_sourcesdefault_server main_servernearest_server used_serversmatcher templates is_codenamename distributionrrr exploded_listinvaliddisttemplateofficialuri startswithdisabledappendextendcompstyperrchildrenset get_mirrors)rrr6mediar=r&r%sources r get_sourceszDistribution.get_sources6s '# " $#% ! ((00:: H .83H3HDGG3S(0$      '+77DMM+    &&446 9FNN$$V[[1OOOO,,$$V__%9%9:::((26??&&--f5&&v||4ZZ**84&&--f5[[D$4$44V__%%,,V4LL.LL,[[D$4$44))008[[D$4$44V__,,33F;[[D$4$44))008>>foo9M9M9V9V&V6;;$:J:J+J&&--f5V[[D>% %(Br64(0..)*B S/JJ}5E6::n5D07/?/? E/Rtzz|, S  673 KK  KK  7F Aa!ea(..0 "1L"@D  4>> )>>,7DL ,D  *+ /JJv.E/ 6::n5D6s$ HH HH H<;H<cd}|jd}|jd}|dk7r|dk7r||tdz|}||jvrtd|j|zSd|j dzS)zoTry to get a human readable name for the main mirror of a country Customize for different distributionsNz://z.archive.ubuntu.comrR Server for %s%s/ )rcrUrVrPrstriprserverr`ilis r _get_mirror_namezDistribution._get_mirror_names KK  [[. / 7rRxQU^b1G dnn $_%w(?? ?&---- -r c`d}g}t|jdks8t|jdk(r||jd|jrl|jt d|jdg|j r7|j|j |j |j dg|St|jdk(r||jd|js|jt d|jdg|jd}|j rJ|||j s7|j|j |j |j dg|r#|j|j ||dg|St|jdkDr|jt d|jdg|j r7|j|j |j |j dg|jt dddg|jD]S}|j ||dg}|||j s|||jr>||vsC|j|U|S) z+Return a list of used and suggested serverscjtj|jd|jdS)zgHelper function that handles comaprision of mirror urls that could contain trailing slashesrr)rematchstriprs)mir1mir2s r compare_mirrorsz5Distribution.get_server_list..compare_mirrorss'88DJJt,dkk$.?@ @r rSrz Main serverTFzCustom serversN)rUr-r+r;rPr,rx)rrmirrorsru mirror_entrys r get_server_listzDistribution.get_server_lists A t  !A % !! "a ' 1 1! 4d6F6FG NNAm,d.>.>E F""--d.A.AB++dW"" #q (   a $"2"22  NNAm,d.>.>F G&&q)F""&vt/B/BCNN 11$2E2EF //! 5 5f =vtLM2/"" #a ' NNAm,d.>.>F G""--d.A.AB++ NNA./t< =++ 1 $ 5 5f =vuM "64+>+>??D,,D!0NN<0 1r c B| |j}| |j}|t|j}| |j}d}d}t |j xst |jD]}|j}n|jj|||||||}|jrn||jk(r^|jj|j|||||j||jjj|dzyyy)z3 Add distribution specific sources N)parentrFrS)rFrpos)r*rlistr%rreversedr r!rFraddr(rindex) rr>r8r5r=commentrrF new_sources r add_sourcezDistribution.add_sources* ;%%C <==D =++,E <##Dt112Qht?P?P6Q F;;D  %%)) #tUGF*   DD,<,<$<      __!$$))// ;a? ! %= r c2t|g}|jD]d}|jjD]I}|j|k(s|j s |j |vs/|j |j Kf|D]}|j|y)z Enable a component in all main, child and source code sources (excluding cdrom based sources) comp: the component that should be enabled N)rr!r6 componentsr1parent_componentr;_enable_component)rcompr=rCcs r enable_componentzDistribution.enable_component<sdV '' 9F__// 966T>a&8&8))6 Q%7%78 9 9  &A  " "1 % &r cfd}g}|j|j|j|ji}i}|D]p}|j|jk(s|j |vrt ||j <|jD] }||j j|"r|jD]p}|j|jk(s|j |vrt ||j <|jD] }||j j|"rt|jdkr|jdzgn*|D] }||| |jD] }||| |jrUt|jdkr"|j|jdzgy|jD] }||| yy)Nc|j|vry||jvry|jgz|_||jjy)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)r5r=r)rCcomps_per_distrs r add_component_only_oncez?Distribution._enable_component..add_component_only_onceNsS{{.0~fkk22!<<4&0FL 6;; ' + +D 1r rSrq)r=)r>r=)r<r!r r>rr5r@r=rr)rrUrr() rrrsourcesrcomps_per_sdistsrrCs ` r rzDistribution._enable_componentMs 2$t(()t))* 2Avv)))66/-0UN166*2A"166*..q12  2 )) 3Avv)))660.1eOAFF+3A#AFF+//23  3 t  !A % OO4$;-O 0" @'? @22 A'@ A   4++,q0T%5%5dTk]K#66EF+FODE r cg}|j|j|j|j|j|j||jvrg}|j|j|D]i}||j vs|j }|j |||_t|j dksO|jj |ky)zx Disable a component in all main, child and source code sources (excluding cdrom based sources) rSN) r<r!r r)r&r=removerUr)rrrrCr=s r disable_componentzDistribution.disable_components t(()t))*t//0 4## #G NN4,, - 4Fv||#  T"$ v||$q($$++F3  4r c<fd}g}g}|_jD] }||||jD]F}|jj$|jj|j k7s=||||Hj D] }||||y)zHChange the server of all distro specific sources to a given hostc\||_|jD]a}|j|j|g|vr|jj|:|j |j|j|gct |jdkrj j|yy)NrS)r8r=r5rr;rUr)rCr8seenrrs r change_server_of_sourcez;Distribution.change_server..change_server_of_sourcesFJ  AJJ T2d:LL''-KKV[[$ ?@  A 6<< 1$  ''/%r N)r*r!r r6rTr8r))rr8r seen_binary seen_sourcerCs` r change_serverzDistribution.change_servers 0  !'' >F #FC = >(( BF((0??++vzz9'[A  B.. >F #FC = >r c$||jk(ryy)z/Compare a given name with the release codename.TF)rrr1s r r0zDistribution.is_codenames 4== r N)NNNNr)rrr rrDrArxrrrrrrr0r r r rr)sDCE %Tl6-p .CJ#J&";Ez4(><r rc"eZdZdZdZdZdZy)DebianDistributionz)Class to support specific Debian featuresc@||jk(s|jdvryy)z}Compare a given name with the release codename and check if if it can be used as a synonym for a development releases)testingunstableTF)rrrs r r0zDebianDistribution.is_codenames" 4== DLL4K$Kr cZd}|jd}|jd}|dk7r|dk7r||tdz|}||jvrKtdt j d|j|j j zSd|j dzS) zYTry to get a human readable name for the main mirror of a country Debian specificNz://ftp.z .debian.orgrRrprLrqrr)rcrUrVrPrr^rsrts r rxz#DebianDistribution._get_mirror_names KK " [[ ' 7rRxQY/"5G dnn $/"""w 7 > > @&( &---- -r c2tj|dy)Nz http://ftp.%s.debian.org/debian/rdrrArs r rAzDebianDistribution.get_mirrorss  "D ! r N)rrr __doc__r0rxrAr r r rrs3.& r rceZdZdZdZy)UbuntuDistributionz)Class to support specific Ubuntu featuresc2tj|dy)Nz$http://%s.archive.ubuntu.com/ubuntu/rrrs r rAzUbuntuDistribution.get_mirrorss  "H ! r Nrrr rrAr r r rrs 3 r rceZdZdZdZy)UbuntuRTMDistributionz-Class to support specific Ubuntu RTM featuresc:|jj|_yr)rrTr+rs r rAz!UbuntuRTMDistribution.get_mirrorss//88r Nrr r r rrs 79r rchddl}ddlm}m}ddddd} |d d g| j d}|j d }|j d |jdD|S#t$r<}|j|jk7rtjd|zYd}~|Sd}~wwxYw)z-Call lsb_release --idrc and return a mapping.rN)PIPEPopensidDebianzDebian GNU/Linux unstable (sid)r)CodenameDistributor ID DescriptionRelease lsb_releasez-idrc)stdoutzutf-8c3HK|]}d|vs|jdyw)z: N)split).0lines r z_lsb_release..s UDuPT}djj'Us "" z#lsb_release failed, using defaults:) errno subprocessrr communicatedecodeupdaterOSErrorENOENTloggingwarning)rrrresultoutexcs r _lsb_releasers&"8 F I]G,T:FFHKjj! UCIIdOUU M I 99 $ OOACG H MIsAA,, B151B,,B1cjddl}ddlm}m}m} |ddg||dj d}|j D]*}|jds|jd d d cS y#t$r;}|j|jk7rtjd |zYd}~yd}~wwxYw) z=Get the current channel from system-image-cli -i if possible.rN)DEVNULLrrzsystem-image-cliz-iT)rstderruniversal_newlinesz channel: z: rSz+system-image-cli failed, using defaults: %s) rrrrrr splitlinesr9rrrrr)rrrrrrrs r _system_image_channelrs// Q  &#  +-  NN$ .D{+zz$*1-- .  Q 99 $ OOICO P Qs$AA.A.+A.. B271B--B2c4eZdZdZdZddZdZdZdZdZ y) _OSReleasez/etc/os-releaseci|_d|_tj|_t j j|jsy|jd|_|r|jyy)NFT) rvalidrOS_RELEASE_FILErFrWrXisfileparseinject_lsb_compat)r lsb_compats r rz_OSRelease.__init__'sX  .. ww~~dii(     " " $ r c|jd|jd<|jd|jd<|jjd|jd<|jds(|jjd|jd<|jjd|jd <y) NIDr PRETTY_NAMErVERSION_CODENAMErUBUNTU_CODENAME VERSION_IDr)rgetrs r rz_OSRelease.inject_lsb_compat5s(, D(9 $%%)[[%? M""&++//2D"E J{{:&&*kkoo6G&HDKK #!%!> Ir ct|j}|D]4}|j}|s|j|j dd6|j y)N=rS)openrFr} parse_entryrclose)rfrs r rz_OSRelease.parse?sU O 2D::t}|2d |vr.d }|jd d d jdd d}|}|}|d k(rt|||||S|d k(rt|||||S|dk(rt|||||St|||||S)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 via a call to lsb-release z#Provided only a subset of arguments) stacklevelrrrrrUbuntuz ubuntu-rtm/z Ubuntu-RTMrrS-rr)warningswarnDeprecationWarningrrrrrrrsplitrrrrr) rrrrr os_release os_result lsb_resultchannels r get_distrorWsJ 8  [G MM57IVW  \  !^   "))I"^ ( )j) / Y'-- 2. >+-G"}'?!">>#q1!4::3B1E& " X~!"h WgNN \$R;QQ x!"h WgNNB+wHHr )rrrWr{rrxml.etree.ElementTreerapt_pkgrP Exceptionrrrrrrrrrr r r rs4 -   XXv ! ! H  9.9,*11h4r1Ir