+eT)0@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z Gddde Z Gddde ZdS)N)gettextc@seZdZdZdS) AptCdromErrorz% base exception for apt cdrom errors N)__name__ __module__ __qualname____doc__rrA/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeAptCdrom.pyr"s rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dddZ dddZ ddZdddZddZdddZdd Zejd!kreZndS)"AptCdromz represents a apt cdrom object cCs:||_||_t|_t|_t|_dS)N)view cdrompathsetpackages signaturesi18n)selfr pathrrr __init__)s     zAptCdrom.__init__cCs^tjjtjjdtjjd}tjj||rZtj |||ndS)zG restore the backup copy of the cdroms.list file (*not* sources.list)! z Dir::StatezDir::State::cdromsN) osrjoinapt_pkgconfigfind_dirfindexistsshutilcopy)r backup_ext cdromstaterrr restore_backup1szAptCdrom.restore_backupcCsu|j}|j||j}tjjd}t|j}|j|d|}t|dj |dS)z comment out the cdrom entry zDir::Etc::sourcelistz# %swN) _readDiskName_generateSourcesListLinerrr find_fileopenreadreplacewrite)rdisknamepentry sourceslistcontentrrr comment_out_cdrom_entry;s  z AptCdrom.comment_out_cdrom_entrycCst}t}t}xtj|jddD]\}}}|jdsa|jdrt|dd=q4q4d|krq4q4d|kr|jtjj|dq4d|kr|jtjj|dq4d |ksd |krtj d |q4d |kr3|jtjj|d q4d |krxttj tjj|d D]%}|jtjj|d |q^Wq4tjj |ddkr4|dd=q4q4W|||fS)z| scan the CD for interessting files and return them as: (packagesfiles, signaturefiles, i18nfiles) topdownTzdebian-installerz dist-upgraderNz.aptignrZPackagesz Packages.gzZSourcesz Sources.gzz+Sources entry found in %s but not supportedz Release.gpgrZpool) r rwalkr endswithaddrrloggingerrorlistdirsplit)rrrrrootdirsfilesfrrr _scanCDDs0   (      %&zAptCdrom._scanCDcCstjjd}tj}|jtjjj}|j }t |d}|j d||f|j d||fdS)z update apts cdrom.list zDir::State::cdromsaz CD::%s "%s"; zCD::%s::Label "%s"; N) rrr#ZCdromZidentaptZprogressbaseZ CdromProgressr!r$r')rZdbfileZcdromidZlabeloutrrr _writeDatabaseds  zAptCdrom._writeDatabasecCsat|}tjjd}x<t|D].}d|kr+||kr+|j|q+q+W|S)z& drop architectures that are not ours zAPT::Architecturez/binary-)r rrrremove)rrZarchdrrr _dropArchns  zAptCdrom._dropArchcCsr|j}tjj|jdd}tjj|rnt|j}x#dD]}|j|d}qOWn|S)Nz.diskinfo"][_)rErFrGrH)r rrrrr$r%r&)rr(rDZspecialrrr r!zs  zAptCdrom._readDiskNamec Csd}d}g}xo|D]g}tjd|}|sLttdn|jd}|jd}|j|jdqW| s| rdS|jd||dj|f}|S) Nz (.*)/dists/([^/]*)/(.*)/binary-*z&Could not calculate sources.list entryr.zdeb cdrom:[%s]/ %s %s )rematchrrHgroupappendsortr) rr(rrZdistcompsrBmr)rrr r"s  z!AptCdrom._generateSourcesListLineNc Cs|stjjd}n|j}x|D]}tjd|||jddf}tjj|tjj |d}|j drt j |}zOt |d:}x0|j d} |j| | dkrPqqWWdQXWd|jXq.tj||q.Wd S) NzDir::State::listsz cdrom:[%s]/%sdistsrz.gzwbiT)rrrr!uri_to_filenamerrrrsplitextr0gzipr$r%r'closerr) rZ translations targetdirr(r9fnameoutfgr?srrr _copyTranslationss$  ,%  zAptCdrom._copyTranslationsc Cs|stjjd}n|j}x|D]}tjd|||jddf}tjj|tjj |d}|j drt j |}zOt |d:}x0|j d} |j| | dkrPqqWWdQXWd|jXq.tj||q.Wd S) NzDir::State::listsz cdrom:[%s]/%srTrz.gzrUirVT)rrrr!rWrrrrrXr0rYr$r%r'rZrr) rrr[r(r9r\r]r^r?r_rrr _copyPackagess$  ,%  zAptCdrom._copyPackagescCsqtjjdd}tjjdd}x@|D]8}tjj|d}tjj|d}|d|d||g}tj|}|dksdStj t |} | j x| j d jd D]} | j\} } } tjj || }tjj|s)tjd |qntjt |}|| kstjd | |fdSqWq1Wd S)z! verify the signatues and hashes z Dir::Bin::gpgz /usr/bin/gpgvzApt::GPGV::TrustedKeyringz/etc/apt/trusted.gpgrz --keyringz--ignore-time-conflictFZSHA256 zignoring missing '%s'z(hash sum mismatch expected %s but got %sT)rrrrrr5rX subprocesscallZTagFiler$stepZsectionrrr2rDZ sha256sumr3)rrZgpgvZkeyringsigZbasepathreleasefcmdZrettentryhashsizenamer9sumrrr _verifyReleases2         zAptCdrom._verifyReleasecCs|stjjd}n|j}x|D]~}tjj|d}x_||fD]Q}tjd|||jddf}t j |tjj ||qWWq.WdS)z copy the release file zDir::State::listsrz cdrom:[%s]/%srTNT) rrrr!rrrXrWrrrr)rrr[r(rfrgr9r\rrr _copyReleases  ,'zAptCdrom._copyReleasecCs9|j\|_|_|_|j|j|_t|jdkrjtjdtt dn|j |jr|j |jn|j |j|j |j|j}|stjddS|j||j}tjjd}t|j}t|djd||f|jd S) z' reimplement pkgCdrom::Add() in python rz+no useable indexes found on CD, wrong ARCH?z`Unable to locate any package files, perhaps this is not a Ubuntu Disc or the wrong architecture?zno .disk/ directory foundFzDir::Etc::sourcelistr z%# added by the release upgrader %s %sT)r:rrrrClenr2r3rrHrorprar`r!r"rrr#r$r%r'r@)rr(Zdebliner*r+rrr _doAdds&     zAptCdrom._doAddcCs&tjd|j|rrtjjtjjdtjj d}tjj |rrt j |||qrntjj d|jtjj ddy|j}Wncttfk r}z=tjd||jjtdtd |d SWYd d }~XnXtjd ||S) z add a cdrom to apt's database zAptCdrom.add() called with '%s'z Dir::StatezDir::State::cdromszAcquire::cdrom::mountzAPT::CDROM::NoMounttruezcan't add cdrom: %szFailed to add the CDzThere was a error adding the CD, the upgrade will abort. Please report this as a bug if this is a valid Ubuntu CD. The error message was: '%s'FNzAptCdrom.add() returned: %s)r2debugr rrrrrrrrrrr rr SystemErrorrr3r rH)rrrreserrr r1s$ z AptCdrom.addcCs |jdk S)z# helper to use this as 'if cdrom:' N)r )rrrr __bool__/szAptCdrom.__bool__3)rrrrrrr,r:r@rCr!r"r`rarorprrr1rxsysversionZ __nonzero__rrrr r &s$     " r )rMrr<rr2rYrrcrzrrH Exceptionrobjectr rrrr s