D['L@sddlZddlZddlZddlZddlmZddlmZGdddeZ Gddde Z Gdd d e Z Gd d d e Z d d ZddddddZdS)N) ElementTree)gettextc@seZdZdS)NoDistroTemplateExceptionN)__name__ __module__ __qualname__rr4/usr/lib/python3/dist-packages/DistUpgrade/distro.pyr"s rc@seZdZddZddZdddZdd Zd d Zddddd d dZddZ ddZ ddZ ddZ ddZ dS) DistributioncCs:||_||_||_||_d|_d|_dS)z2 Container for distribution specific informations Zdebzdeb-srcN)idcodename descriptionrelease binary_type source_type)selfr r r rrrr __init__(s      zDistribution.__init__cCs||_d|_g|_g|_g|_g|_g|_g|_g|_g|_ d|_ g|_ d|_ d|_ d|_g|_xH|jjjD]7}|j|jr|j|jkr||_PqqW|jdkr td|j|jfng}g}g}g}x4|jjD]&}|j r|j|jr|jr|jjr|j|jjr|jjdr|j r|jj ||j!|j"q|jjdr|jr|jj |q|j#|j$kr6|j r6|jj ||j!|j"|j |jq|j#|j$krd|jrd|jj |q|j#|j%kr|j r|j j |q|j#|j%kr|jr|jj |qn|j r.|j|jj&kr.|j r|j#|j$kr|jj |qT|j rA|j#|j%krA|j j |qT|jj |q.q.Wt'||_t'||_|j!||j!|t'||_t'||_ |j(dS)zf Find the corresponding template, main and child sources for the distribution NFz7Error: could not find a distribution template for %s/%szcdrom:)) sourceslistsource_template child_sources main_sourcesZdisabled_sourcesZ cdrom_sourcesZdownload_comps enabled_comps cdrom_comps used_mediaget_source_codesource_code_sourcesdefault_server main_servernearest_server used_serversZmatcherZ templates is_codenamenameZ distributionr rr listZinvaliddisttemplateZofficialuri startswithZdisabledappendextendcompstyperrZchildrenset get_mirrors)rrr%Zmediar*rrsourcerrr get_sources3s                               zDistribution.get_sourcesNc Cs:|jj|_x3|jD](}|jds|jj|qqWt|jdkri|j|_ n|jdj |_ i|_ d}t j j|r{td|}t|dddkr|j|_n|jd}x|D]}y|jd}Wntk r!|jd }YnXy|jd }Wntk rT|jd }YnXtjd ||j |j.compare_mirrorsr6rz Main serverTFzCustom serversN)r9r rr(r4rrP)rrTZmirrorsrMZ mirror_entryrrr get_server_listsB    %  zDistribution.get_server_listrc Cs|dkr|j}n|dkr0|j}n|dkrNt|j}n|dkrf|j}n|jj|||||}|jr||jkr|jj|j||||d|j d|jjj |dndS)z3 Add distribution specific sources Nr0posr6) rr r#rrraddrrr0index)rr+r&r$r*ZcommentZ new_sourcerrr add_source s         zDistribution.add_sourcecCst|g}xS|jD]H}x?|jjD]1}|j|kr,|jr,|j|jq,q,WqWx|D]}|j|qlWdS)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,rr%Z componentsr"Zparent_componentrW_enable_component)rcompr*r.crrr enable_component!s zDistribution.enable_componentc sfdd}g}|j|j|j|ji}i}xm|D]e}|j|jkrK|j|krt||j.add_component_only_oncer6r*z%sr+)r)rrr+rr$r,r*rWrrr9rYr) rr[r_sourcesr^Zcomps_per_sdistsr\r.r)r[r rZ1s:   #zDistribution._enable_componentcCsg}|j|j|j|j|j|j||jkr^g}|j|jnxX|D]P}||jkre|jj|t|jdkr|jj|qqeqeWdS)zx Disable a component in all main, child and source code sources (excluding cdrom based sources) r6N) r)rrrrr*remover9r)rr[r`r.rrr disable_componentos zDistribution.disable_componentcsfdd}g}g}|_x!jD]}||||q1WxKjD]@}|jjdks|jj|jkrU||||qUqUWx!jD]}||||qWdS)zN Change the server of all distro specific sources to a given host cs||_x[|jD]P}|j|j|g|krG|jj|q|j|j|j|gqWt|jdkrjj|ndS)Nr6)r&r*r$rbr(r9r)r.r&seenr[)rrr change_server_of_sources  z;Distribution.change_server..change_server_of_sourceN)rrrr%r8r&r)rr&reZ seen_binaryZ seen_sourcer.r)rr change_servers  zDistribution.change_servercCs||jkrdSdSdS)z1 Compare a given name with the release codename. TFN)r )rr"rrr r!szDistribution.is_codename)rrrrr/r-rPrUrYr]rZrcrfr!rrrr r &s  ]9  3  >  r c@s:eZdZdZddZddZddZdS) DebianDistributionz+ Class to support specific Debian features cCs*||jks|jdkr"dSdSdS)z Compare a given name with the release codename and check if if it can be used as a synonym for a development releases testingunstableTFN)rhri)r r)rr"rrr r!szDebianDistribution.is_codenamecCsd}|jd}|jd}|d krY|d krY||td|}n||jkrtdtjd|j|jjSd|jdSdS) z_ Try to get a human readable name for the main mirror of a country Debian specific Nz://ftp.z .debian.orgr6z Server for %sr2z%sz/ r7r7)rEr9r:r4rr@rL)rrMrBrNrOrrr rPsz#DebianDistribution._get_mirror_namecCstj|dddS)NrFz http://ftp.%s.debian.org/debian/)r r-)rrrr r-szDebianDistribution.get_mirrorsN)rrr__doc__r!rPr-rrrr rgs   rgc@s"eZdZdZddZdS)UbuntuDistributionz+ Class to support specific Ubuntu features cCstj|dddS)NrFz$http://%s.archive.ubuntu.com/ubuntu/)r r-)rrrr r-szUbuntuDistribution.get_mirrorsN)rrrrjr-rrrr rks rkcCsddlm}m}ddl}idd6dd6dd 6d d 6}yX|d d gd|jd}|jd}|jdd|jdDWnKtk r}z+|j|j krt j d|nWYdd}~XnX|S)z-Call lsb_release --idrc and return a mapping.r)PopenPIPENZsidCodenameDebianzDistributor IDzDebian GNU/Linux unstable (sid) DescriptionriReleaseZ lsb_releasez-idrcstdoutzutf-8css*|] }d|kr|jdVqdS)z: N)split).0rOrrr sz_lsb_release.. z#lsb_release failed, using defaults:) subprocessrlrmerrnoZ communicatedecodeupdatersOSErrorENOENTloggingZwarning)rlrmrxresultoutexcrrr _lsb_releases  "''rcCs|o|o|o|sLt}|d}|d}|d}|d}n|dkrkt||||S|dkrt||||St||||SdS)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 zDistributor IDrnrprqZUbunturoN)rrkrgr )r r r rr~rrr get_distros        r)rr}rQr;Zxml.etree.ElementTreerZapt_pkgr4 Exceptionrobjectr rgrkrrrrrr s