xkdk] ddlZddlZddlZddlZddlZddlmZddlmZGdde Z Gdde Z Gdd e Z Gd d e ZGd d eZdZdZGddZddddgfdZdS)N) ElementTree)gettextceZdZdS)NoDistroTemplateExceptionN)__name__ __module__ __qualname__3/usr/lib/python3/dist-packages/aptsources/distro.pyrr%sDr rcXeZdZgfdZdZddZdZdZddZd Z d Z d Z d Z d Z dS) Distributionch||_||_||_||_||_d|_d|_dS)z0Container for distribution specific informationsdebzdeb-srcN)idcodename descriptionreleaseis_like binary_type source_type)selfrrrrrs r __init__zDistribution.__init__*s>  &   $r c||_d|_g|_g|_g|_g|_g|_g|_g|_g|_ d|_ g|_ d|_ d|_ d|_g|_|jjjD]5}||jr|j|jkr ||_n6|jt-d|jd|jg}g}g}g}|jjD]}|js||jr|jr|jjr||jjr|jdr=|js6|j ||!|j"n7|jdr"|jr|j |n|j#|j$krV|jsO|j ||!|j"| |jn|j#|j$kr"|jr|j |nc|j#|j%kr"|js|j |n1|j#|j%kr!|jr|j ||js|j|jj&vr|js,|j#|j$kr|j |6|js,|j#|j%kr|j |i|j |tO||_tO||_|!||!|tO||_tO||_ |(dS)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 distributionrrrlistinvaliddisttemplateofficialuri startswithdisabledappendextendcompstyperrchildrenset get_mirrors)rrr6mediar=r&r%sources r get_sourceszDistribution.get_sources6s '# " $#% ! (0:  H .. 83HDG3S3S(0$   '++777DMM+    &+ 9 9FN 9$$V[11 9O 9O,  9 $$V_%9::  9:((2296?9&--f555&&v|4444Z**844 9 9&--f5555$444V_4%,,V444LL...LL,,,,$4444)008888$444V_4,33F;;;;$4444)00888> 9fo9M9V&V&V96;$:J+J+J&--f55559V[D>%  S%(((Br64((0.)**B S S/J}5EE///Jv.EEE/6:n5DD666:n5DDD6/6/? E/R/Rtzz||,,  67333 KK   KK   77F Aa!eai(..00  A"1L"@D  4> ) )>,7DL ,D    * )s$6 DDD" D00E  E c"d}|d}|d}|dkr |dkr||tdz|}||jvrtd|j|zSd|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   [[. / / 77rRxxQU^b01G dn $ $_%%w(?? ?&----- -r cHd}g}t|jdks4t|jdkr||jd|jrh|t d|jdg|jr5|||j|jdgnt|jdkr||jd|js|t d|jdg|jd}|jrF|||js5|||j|jdg|r+||||dgnt|jdkr|t d|jdg|jr5|||j|jdg|t dddg|jD]V}|||dg}|||js|||jr=||vr||W|S) z+Return a list of used and suggested serverscxtj|d|dS)zgHelper function that handles comaprision of mirror urls that could contain trailing slashesrr)rematchstriprs)mir1mir2s r compare_mirrorsz5Distribution.get_server_list..compare_mirrorss.8DJJt,,dkk$.?.?@@ @r rSrz Main serverTFzCustom serversN)rUr-r+r;rPr,rx)rrmirrorsru mirror_entrys r get_server_listzDistribution.get_server_lists A A A t ! !A % % ! " "a ' ' 1! 4d6FGG ( NNAm,,d.>E F F F" --d.ABB+" # #q ( (  a $"22 2 ( NNAm,,d.>F G G G&q)F" &vt/BCCNN 11$2EFF /! N 5 5f = =vtLMMM " # #a ' ' NNAm,,d.>F G G G" --d.ABB+ NNA.//t< = = =+ 1 1 $ 5 5f = =vuM "?64+>??1??D,DD1!00NN<000r rc f||j}||j}|t|j}||j}|j|||||}|jrX||jkrO|j|j|||||j |jj |dzdSdSdS)z3 Add distribution specific sources NrS)rFpos) r*rr3r%rraddr(rrFindex)rr>r8r5r=comment new_sources r add_sourcezDistribution.add_sources ;%C <=D =+,,E <#D%))$T5'JJ    DD,<$<$<    _$)// ;;a? !       $<$|D]}||dS)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!r6 componentsr1parent_componentr_enable_component)rcompr=rCcs r enable_componentzDistribution.enable_component2sTF ' 2 2F_/ 2 26T>>a&8>IIa0111 2 & &A  " "1 % % % % & &r cnfd}g}||j||ji}i}|D][}|j|jkrI|j|vrt ||j<|jD]"}||j|#\|j D][}|j|j krI|j|vrt ||j<|jD]"}||j|#\t|jdkr| dzgn'|D]}||||j D]}||||j rPt|j dkr"| |j dzgdS|j D]}|||dSdS)Nc|j|vrdS||jvrdS|xjgz c_||jdS)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_onceCsc{.00~fk222 LLTF "LL 6; ' + +D 1 1 1 1 1r rSrq)r=)r>r=)r<r!r r>rr5r@r=rr)rrUrr() rrrsourcesrcomps_per_sdistsrrCs ` r rzDistribution._enable_componentBsI 2 2 2 2 2$t()))t)*** 2 2Av)))6//-0UUN16*22A"16*..q1111) 3 3Av)))600.1eeOAF+33A#AF+//2222 t ! !A % % OO4$;-O 0 0 0 0" @ @''????2 A A''@@@@   E4+,,q00T%5dTk]KKKKK#6EEF++FODDDD E E EEr cg}||j||j||j||jvrg}||j|D]W}||jvrL|j|t|jdkr|j|XdS)zx Disable a component in all main, child and source code sources (excluding cdrom based sources) rSN) r<r!r r)r&r=removerUr)rrrrCs r disable_componentzDistribution.disable_components t()))t)***t/000 4# # #G NN4, - - - 4 4Fv|## ##D)))v|$$q(($++F333  4 4r cfd}g}g}|_jD]}||||jD]0}|jj|jj|jkr ||||1jD]}||||dS)zHChange the server of all distro specific sources to a given hostc.||_|jD]P}|j|j|g|vr|j|.||j|j|gQt |jdkrj|dSdS)NrS)r8r=r5rr;rUr)rCr8seenrrs r change_server_of_sourcez;Distribution.change_server..change_server_of_sourcesFJ  A AJ T2d::L''----KKV[$ ?@@@@6<  1$$ ''/////%$r N)r*r!r r6rTr8r))rr8r seen_binary seen_sourcerCs` r change_serverzDistribution.change_servers 0 0 0 0 0  !' > >F # #FC = = = =( B BF(0?+vz99''[AAA. > >F # #FC = = = = > >r c ||jkrdSdS)z/Compare a given name with the release codename.TF)rrr1s r r0zDistribution.is_codenames 4= 45r N)NNNNr)rrr rrDrArxrrrrrrr0r r r rr)sCE % % % %TTTl6-6-6-6-p . . .CCCJ6&&& ;E;E;Ez444$>>><r rc$eZdZdZdZdZdZdS)DebianDistributionz)Class to support specific Debian featuresc2||jks |jdvrdSdS)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= DL4K$K$K45r cd}|d}|d}|dkr |dkr||tdz|}||jvrTtdt jd|j|zSd|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 " " [[ ' ' 77rRxxQY/"45G dn $ $/"""w 7 > > @ @&(( &----- -r c>t|ddS)Nz http://ftp.%s.debian.org/debian/rdrrArs r rAzDebianDistribution.get_mirrorss/  "D !     r N)rrr __doc__r0rxrAr r r rrsG33...&     r rceZdZdZdZdS)UbuntuDistributionz)Class to support specific Ubuntu featuresc>t|ddS)Nz$http://%s.archive.ubuntu.com/ubuntu/rrrs r rAzUbuntuDistribution.get_mirrorss/  "H !     r Nrrr rrAr r r rrs)33     r rceZdZdZdZdS)UbuntuRTMDistributionz-Class to support specific Ubuntu RTM featuresc(|jj|_dSr)rrTr+rs r rAz!UbuntuRTMDistribution.get_mirrorss/8r Nrr r r rrs)7799999r rcddlm}m}ddl}ddddd} |d d g| d}|d }|d |dDn>#t$r1}|j|j krtj d|zYd}~nd}~wwxYw|S)z-Call lsb_release --idrc and return a mapping.rPopenPIPENsidDebianzDebian GNU/Linux unstable (sid)r)CodenameDistributor ID DescriptionRelease lsb_releasez-idrc)stdoutzutf-8c3HK|]}d|v|dVdS)z: N)split).0lines r z_lsb_release..s3UUDuPT}}djj''}}}}UUr  z#lsb_release failed, using defaults:) subprocessrrerrno communicatedecodeupdaterOSErrorENOENTloggingwarning)rrrresultoutexcs r _lsb_releasers&&&&&&&&LLL"8 F Ie]G,T:::FFHHKjj!! UUCIIdOOUUUUUUU III 9 $ $ OACG H H HI MsA.B B?'B::B?cddlm}m}ddl} ddlm}n9#t $r,t jt jt j }YnwxYw |ddg||d d}| D]5}| d r| d d d cS6n>#t$r1}|j|jkrt!jd |zYd}~nd}~wwxYwdS) z=Get the current channel from system-image-cli -i if possible.rrN)DEVNULLzsystem-image-cliz-iT)rstderruniversal_newlinesz channel: z: rSz+system-image-cli failed, using defaults: %s)rrrrr ImportErrorrWopendevnullO_RDWRr splitlinesr9rrrrr)rrrrrrrs r _system_image_channelrs^&&&&&&&&LLL1&&&&&&& 111'"*bi001 Qe  &#    +--  NN$$ . .D{++ .zz$**1---- . . QQQ 9 $ $ OICO P P PQ 4s.3A  A A1CC C> 'C99C>c6eZdZdZdZd dZdZdZdZdZ dS) _OSReleasez/etc/os-releaseTci|_d|_tj|_t j|jsdS|d|_|r| dSdS)NFT) rvalidrOS_RELEASE_FILErFrWrXisfileparseinject_lsb_compat)r lsb_compats r rz_OSRelease.__init__su  . w~~di((  F   %  " " $ $ $ $ $ % %r c@|jd|jd<|jd|jd<|jd|jd<|jds"|jd|jd<|jd|jd <dS) NIDr PRETTY_NAMErVERSION_CODENAMErUBUNTU_CODENAME VERSION_IDr)rgetrs r rz_OSRelease.inject_lsb_compat-s(, D(9 $%%)[%? M""&+//2D"E"E J{:& I&*koo6G&H&HDK #!%!>!> Ir ct|jd}|D]7}|}|s|j|dd8|dS)Nr=rS)rrFr} parse_entryrclose)rfrs r rz_OSRelease.parse7sl C  2 2D::<>+--G"}'?'?!">>#q11!4::3BB1E& " X~~!"h WgNNN \$R;QQQ x!"h WgNNNB+wHHHr )rrr{rrWxml.etree.ElementTreerapt_pkgrP Exceptionrobjectrrrrrrrr r r r rs4 ------         KKKKK6KKK\ ! ! ! ! ! ! ! ! H        99999.999,411111111h4r-I-I-I-I-I-Ir