+eT2@sddlmZmZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl m ZddlmZddlmZmZmZGdd d eZed kreddZed ejd d ndS))absolute_importprint_function)TemplateN)gettext) SourcesList)get_disturl_downloadablecountry_mirrorc@seZdZdZdZdZdejkZddZ ddZ d d Z d d Z d dZ dddZddZddZddZddZddZddZddZd d!Zd"S)#DistUpgradeFetcherCorez2 base class (without GUI) for the upgrade fetcher z http://archive.ubuntu.com/ubuntumainZDEBUG_UPDATE_MANAGERcCs+||_t|_||_g|_dS)N)new_distrcurrent_dist_name _progress run_options)selfr ZprogressrD/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeFetcherCore.py__init__/s   zDistUpgradeFetcherCore.__init__cCs$|jr tjj|dndS)z" helper to show debug information  N)DEBUGsysstderrwrite)rmsgrrr_debug6s zDistUpgradeFetcherCore._debugcCsdS)NTr)rrrrshowReleaseNotes;sz'DistUpgradeFetcherCore.showReleaseNotescCst|t|dS)z dummy implementation for error display, should be overwriten by subclasses that want to more fancy method F)print)rZsummarymessagerrrerror>s  zDistUpgradeFetcherCore.errorcCs|jjr|jdtjj|jj}|jdtjj|jj}ttditjj|d6tjj|d6|j ||rdSndS)N/z0authenticate '%(file)s' against '%(signature)s' file signatureTF) r upgradeToolSigtmpdirospathbasename upgradeToolr_gpgauthenticate)rfZsigrrr authenticateFs #z#DistUpgradeFetcherCore.authenticatez/etc/apt/trusted.gpgc stjtjtjdkrRtjddtjddnddddddddd |jd d d |d ||g}fdd}tj|dtjd|dddd}tj dtj dtj d}tj d}z|j } |j } | dkrt d| t dt |j t |jj t |j dSd| krdSt dt | dSWd|j |jj |j XdS)zx authenticated a file against a given signature, if no keyring is given use the apt default keyring rgpgz --status-fdz%dz --logger-fdz --no-optionsz --homedirz--no-default-keyringz--ignore-time-conflictz --keyringz--verifycs&tjdtjddS)Nr)r%closer) logger_pipe status_piperr gpg_preexechsz;DistUpgradeFetcherCore.gpgauthenticate..gpg_preexecrZ preexec_fnZ close_fdsFZuniversal_newlinesTrz gpg exited %dzDebug information: ZVALIDSIGzinvalid result from gpg:N)r-r.)r%piper version_infoset_inheritabler$ subprocessPopenPIPEr0fdopenreadwaitrr) rr!r"Zkeyringr/r3procZ status_handleZ logger_handleZgpgresZretr)r1r2rr*RsP            z&DistUpgradeFetcherCore.gpgauthenticatecCstjj|jtjj|j}ttdtjj|tjj|s]dSyXt j |jdtjj|jd}x|D]}|j |qW|j Wn=t j k r}ztjd|dSWYdd}~XnXdS)Nzextracting '%s'Fr rzfailed to open tarfile (%s)T)r%r&joinr$r'urirr)existstarfileopenZextractr0Z ReadErrorloggingr)rfnameZtarZtarinfoerrrextractDistUpgraders'  z*DistUpgradeFetcherCore.extractDistUpgradercCs`d|j|jjf|_}tjj|s\|jtdtddtdSdS)Nz%s/%szCould not run the upgrade toolz. zThis is most likely a bug in the upgrade tool. Please report it as a bug using the command 'ubuntu-bug ubuntu-release-upgrader-core'.T) r$r namescriptr%r&rArr))rrIrrrverifyDistUpraders   z(DistUpgradeFetcherCore.verifyDistUpradercCs/|jd|jtdd}t}x|jD]}|js6|js6|jdk rdq6n|j|kryq6n|jj |r|j |jkr|j |j kr|S|j |jkr6d|j kr6|j|t |d}t||jr|S|j|jq6q6W|jddS) a try to figure what the mirror is from current sources.list do this by looing for matching DEFAULT_COMPONENT, current dist in sources.list and then doing a http HEAD/ftp size request to see if the uri is available on this server zmirror_from_sources_list: %sZ withMatcherFZdebr Nzno mirror found)rrrsetlistZdisabledZinvalidtyper@ startswithZdistDEFAULT_COMPONENTcompslenr add)rr@Z default_uriZsourcesseenrFZ mirror_urirrrmirror_from_sources_lists& "! z/DistUpgradeFetcherCore.mirror_from_sources_listcCs|j|jrA|jd|j||j}|rA|Snt|}t}|jd|}y)t||jstd|nWnHtk r}z(|jd||jdd}WYdd}~XnX|S)z expand the uri so that it uses a mirror if the url starts with a well know string (like archive.ubuntu.com) ztrying to find suitable mirrorZ countrymirrorzfailed to download %sz url '%s' could not be downloadedrKN) rODEFAULT_MIRRORrrUrr Zsafe_substituter Exception)rr@Znew_uriZ uri_templatemrFrrr _expandUris   %z!DistUpgradeFetcherCore._expandUricCstjdd}||_tj|tjd||jdkrqtj j ddtj j ddntj |j }|j jdk r|j|j j}tj||d td }|n|j jdk r|j|j j|_tj||jd td }||j}||jkrNtjd |d Sxwtjj|j jtjj|j jgD]E}tjj|otjj|dkstjd|d SqWdSd S)z. download the tarball with the upgrade script prefixzubuntu-release-upgrader-zusing tmpdir: '%s'rzDebug::Acquire::http1zDebug::Acquire::ftpNZdescrzUpgrade tool signaturez Upgrade toolzfetch result != continue (%s)Fzfile '%s' missingT)tempfileZmkdtempr$r%chdirrDdebugrapt_pkgconfigrLZAcquirerr r#rYZ AcquireFiler)r(r@runZRESULT_CONTINUEwarnr&r'rAgetsize)rr$Zfetcherr@Zaf1Zaf2resultr+rrrfetchDistUpgraders>      *z(DistUpgradeFetcherCore.fetchDistUpgradercCsV|jg|j}tjdkr?tjddg|ntj|j|dS)Nrz /usr/bin/sudoZsudo)rIrr%getuidexecv)rargsrrrrunDistUpgradersz&DistUpgradeFetcherCore.runDistUpgradercCs!tjdtj|jdS)Nz..)r%r]shutilZrmtreer$)rrrrcleanup s zDistUpgradeFetcherCore.cleanupcCs|jsdS|js<|jtdtddS|jsr|jtdtd|jdS|js|jtdtddS|js|jtdtd|jdSyKtj |j tj st d |j }d |_ |n|jWnwt k r}zW|j d krc|jtd td d S|jtd td|jWYdd}~XnXdS)NzFailed to fetchz=Fetching the upgrade failed. There may be a network problem. zAuthentication failedz_Authenticating the upgrade failed. There may be a problem with the network or with the server. zFailed to extractz[Extracting the upgrade failed. There may be a problem with the network or with the server. zVerification failedz[Verifying the upgrade failed. There may be a problem with the network or with the server. zCan not execute '%s' zCan not run the upgradezyThis usually is caused by a system where /tmp is mounted noexec. Please remount without noexec and run the upgrade again.FzThe error message is '%s'.T)rrerr)r,rkrGrJr%accessrIX_OKOSErrorerrnoristrerror)rexrFrrrrasD              'zDistUpgradeFetcherCore.runN)__name__ __module__ __qualname____doc__rVrPr%environrrrrrr,r*rGrJrUrYrerirkrarrrrr (s$      5     '  r __main__zgot mirror: '%s'zghttp://archive.ubuntu.com/ubuntu/dists/intrepid-proposed/main/dist-upgrader-all/0.93.34/intrepid.tar.gzz http://archive.ubuntu.com/ubuntu)Z __future__rrstringrr%r_rDrBr\rjrr7rr)Zaptsources.sourceslistrZutilsrr r objectr rsdrrUrrrrs(