o >Ic@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z ddlmZddlmZddlmZGdddeZGd d d eZGd d d eZd dZe\ZZGdddeZGdddeZGdddejZe dkrddl!Z!ddl"m#Z#ddl$m$Z$e%dee#de$dZ&e%e&'e!(e&)e&*e&j+e&,dge%e&-e&.dSdS)N)PopenPIPE)gettext)ngettext) inside_chrootc@ eZdZdS)CacheExceptionN__name__ __module__ __qualname__rr>/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeCache.pyr (r c@r)CacheExceptionLockingFailedNr rrrrr,rrc@r)CacheExceptionDpkgInterruptedNr rrrrr0rrcCsd}d}td}td|D]/}|d|kr"|tj|7}q|ddks7|ddks7|ddkr8q|tj|7}q|dkrLtdd }|dkrWtd d }|d 7}d }|d |krg|d }||7}||fS)zjestimate the amount of space used by the kernel and initramfs in /boot, including a safety margin rz /boot/*%s*z/boot/initrd.img-%sz initrd.imgz.bakz.dpkg-z>estimate_kernel_initrd_size_in_boot() returned '0' for kernel?iz>estimate_kernel_initrd_size_in_boot() returned '0' for initrd?i ig?)osunameglobpathgetsizefindloggingwarning)kernelinitrdkverf initrd_bufferrrr#estimate_kernel_initrd_size_in_boot4s4   r!c@s eZdZdZddZddZdS)FreeSpaceRequiredz FreeSpaceRequired object: This exposes: - the total size required (size_total) - the dir that requires the space (dir) - the additional space that is needed (size_needed) cCs||_||_||_dSN) size_totaldir size_needed)selfr$r%r&rrr__init__`s zFreeSpaceRequired.__init__cCsd|j|j|jfS)Nz@FreeSpaceRequired Object: Dir: %s size_total: %s size_needed: %s)r%r$r&r'rrr__str__dszFreeSpaceRequired.__str__N)r r r __doc__r(r*rrrrr"Xs r"c@eZdZdZddZdS)NotEnoughFreeSpaceErrorzI Exception if there is not enough free space for this operation cCs ||_dSr#)free_space_required_list)r'r.rrrr(ms z NotEnoughFreeSpaceError.__init__Nr r r r+r(rrrrr-hs r-c@seZdZdZdZdsddZddZed d Zd d Z d dZ ddZ ddZ ddZ eddZeddZeddZeddZddZdd Zdtd!d"Zd#d$Zdud%d&Zdud'd(Zdud)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zdvd:d;Z dvdd?Z"dvd@dAZ#dBdCZ$dDdEZ%dFdGZ&dHdIZ'dJdKZ(dLdMZ)dNdOZ*dPdQZ+dRdSZ,e dTdUZ-dVdWZ.dXdYZ/edZd[Z0d\d]Z1d^d_Z2d`daZ3dbdcZ4e dddeZ5dfdgZ6dhdiZ7djdkZ8dldmZ9dndoZ:dwdqdrZ;dS)xMyCacherNTc Cs"g|_g|_||_||_d|_d|_||_|jdd|_d|_ |rJz t | d|_Wnt yI}zdt|vrAt|t|d}~wwtj|||dd|_|j|d|_tdd gtdd d |_||d d dkrdtj vrt j!ddt j!dddS)NFDistroMetaPkgsTzdpkg --configure -aRemovalDenylistFilerz-r)stdoutuniversal_newlinesrSourcesFromhardyRELEASE_UPGRADE_NO_RECOMMENDSzAPT::Install-Recommendstruez"APT::AutoRemove::SuggestsImportantfalse)" to_install to_removeviewquirkslockpartialUpgradeconfiggetlistmetapkgs _listsLockapt_pkgpkgsystem_locklock_lists_dir SystemErrorstrrraptCacher(getListFromFileremoval_denylist_get_linux_metapackagelinux_metapackagerr communicatestripr _initAptLoggetrenvironset)r'rDr@rAprogressrBerrrr(vsF    zMyCache.__init__cCs2|D]}|jrq|jjtjkr|jdddqdS)z! honor the dselect install state F) auto_instauto_fixN) is_installed_pkgselected_staterHSELSTATE_INSTALL mark_installr'pkgrrr_apply_dselect_upgradeszMyCache._apply_dselect_upgradecCsJt}|D]}|jr|jjs"|jj|jks|jj|jkr"||jq|S)zB return the packages not downloadable packages in reqreinst state ) rX candidate downloadabler^ inst_state ReInstReq HoldReInstReqaddname)r' reqreinstrcrrrreq_reinstall_pkgss zMyCache.req_reinstall_pkgscCs~|j}t|dkr=tddt|}tddt|d|}|||r=|gdt|}||| dSd S) z/ check for reqreinst state and offer to fix it rzRemove package in bad statezRemove packages in bad statezThe package '%s' is in an inconsistent state and needs to be reinstalled, but no archive can be found for it. Do you want to remove this package now to continue?zThe packages '%s' are in an inconsistent state and need to be reinstalled, but no archives can be found for them. Do you want to remove these packages now to continue?, )z /usr/bin/dpkgz--removez--force-remove-reinstreqTF) rmlenrjoinaskYesNoQuestion release_locklist getTerminalcallget_lock)r'r@rlheadersummarycmdrrrfix_req_reinsts&   zMyCache.fix_req_reinstcCs|jddd}tj|st|tjd|tjddttj |dtj tj Btj Bd|_ tj}d |}t|j |d tjd d tjd d tjdd dS)z init logging, create log fileFilesLogDirz/var/log/dist-upgradezDir::LogzDir::Log::Terminalz apt-term.logzapt.logiz Log time: %s zutf-8zDebug::pkgProblemResolverr<zDebug::pkgDepCache::MarkerzDebug::pkgDepCache::AutoInstallN)rDgetWithDefaultrrexistsmakedirsrHrXopenrpO_RDWRO_CREATO_APPENDlogfddatetimenowwriteencode)r'logdirrrwrrrrUs    zMyCache._initAptLogcCsZt|drt|jt|jtd|_td|_t|jdt|jddS)N old_stdoutrr)hasattrrcloser old_stderrdupdup2rr)rrr_startAptResolverLogs     zMyCache._startAptResolverLogcCs4tdtdt|jdt|jddS)Nrr)rfsyncrrrr)rrr_stopAptResolverLogs  zMyCache._stopAptResolverLogcsfdd}|S)z3 decorator to ensure that the apt output is logged cs*|d|i|}|d|SNr)rr)argskwargsresrrrwrappers  z(MyCache.withResolverLog..wrapperr)rrrrrwithResolverLogs zMyCache.withResolverLogcCs,t|j}t}|||j|j|jS)z< get the size of the packages that are required to download )rHPackageManager _depcacheAcquire get_archives_list_records fetch_needed)r'pmfetcherrrrrequired_downloads zMyCache.required_downloadcCs|jjS)z9 get the size of the additional required space on the fs )rusr_sizer)rrradditional_required_spacesz!MyCache.additional_required_spacecCs z|jjWStyYdSw)z< get the extra size needed to install the snap replacements r)rAextra_snap_spaceAttributeErrorr)rrr#additional_required_space_for_snapss   z+MyCache.additional_required_space_for_snapscCs |jjdkS)z is the cache broken r)r broken_countr)rrr is_brokens zMyCache.is_brokencCs:tjdd}t||_|jdkrd|}t|dS)NzDir::State::ListsrBrzCan not lock '%s' )rHrDfind_dirrvrGr)r'rkrZrrrrJs   zMyCache.lock_lists_dircCs$|jdkrt|jd|_dSdS)Nrr4)rGrrr)rrrunlock_lists_dirs   zMyCache.unlock_lists_dircCsH|tj||}||r|jrttd|dkr"tddS)zf our own update implementation is required because we keep the lists dir lock zThe server may be overloadedFzAapt.cache.update() returned False, but did not raise exception?!?N)rrMrNupdaterJrelease_file_download_errorIOError_)r' fprogressrrrrr"s  zMyCache.updatecCs,td|jr |tj|||dS)Nzcache.commit())rinforBrrrMrNcommit)r'r iprogressrrrr1s zMyCache.commitc CsT|jr(z td|_WdSty'}ztd|WYd}~dSd}~wwdS)NFzfailed to SystemUnLock() (%s) )rBrHpkgsystem_unlockrKrdebugr' pkgSystemOnlyrZrrrrr7 zMyCache.release_lockc CsT|js(z td|_WdSty'}ztd|WYd}~dSd}~wwdS)NTzfailed to SystemLock() (%s) )rBrHrIrKrrrrrrrv?rzMyCache.get_lockcCsB|r |j|j}n|jj}|dkrtd|j|fdS|jS)z* check if the given pkg can be downloaded Nz1no version information for '%s' (useCandidate=%s)F)rget_candidate_verr^ current_verrrrkrf)r'rc useCandidateverrrrrfGszMyCache.downloadablecCs|jo |j|jS)z$ check if the pkg is auto-removable )r]r is_garbager^rbrrrpkg_auto_removableRs zMyCache.pkg_auto_removablecCs |jS)z^ try to fix broken dependencies on the system, may throw SystemError when it can't)r fix_brokenr)rrrrWs zMyCache.fix_brokencCsLg|_g|_|D]}|js|jr|j|j|jr#|j|jq dS)z* create a snapshot of the current changes N)r>r? get_changesmarked_installmarked_upgradeappendrk marked_deleterbrrrcreate_snapshot\s  zMyCache.create_snapshotcCs|jdSr#)rinitr)rrrclearfsz MyCache.clearcCsZt|j}|||jD] }||}|q|jD] }||}|jdddqdS)z restore a snapshot F)r\r[N)rH ActionGrouprrr? mark_deleter>ra)r' actiongrouprkrcrrrrestore_snapshotis    zMyCache.restore_snapshotcCs|jdd}|D]8}||vr||jrtd|dSd}|j|dD] }|||vo2||jM}q'|rAtd|dSq tddS) ac This checks if we run on a desktop or a server install. A server install has more freedoms, for a desktop install we force a desktop meta package to be install on the upgrade. We look for a installed desktop meta pkg and for key dependencies, if none of those are installed we assume server mode r2r3z@need_server_mode(): run in 'desktop' mode, (because of pkg '%s')FTKeyDependencieszIneed_server_mode(): run in 'desktop' mode, (because of key deps for '%s')z[need_server_mode(): can not find a desktop meta package or key deps, running in server mode)rDrEr]rr)r'rFkey deps_foundrcrrrneed_server_modews  zMyCache.need_server_modecCsL|jr$z td|WdSty#|tdtdYdSwdS)zY check if the cache is ok and if the required metapkgs are installed z$Have broken pkgs, trying to fix themzBroken packageszYour system contains broken packages that couldn't be fixed with this software. Please fix them first using synaptic or apt-get before proceeding.FT)rrrrrKerrorr)r'r@rrrcoherence_checks   zMyCache.coherence_checkcKsXtd||f||vr*||jdi|||js*||js*td|dSdS)NzInstalling '%s' (%s)z Installing/upgrading '%s' failedFTr)rrrarrrr'rcreasonflagsrrrraszMyCache.mark_installcCsPtd||f||vr&||jr&||||js&td|dSdS)NzUpgrading '%s' (%s)zUpgrading '%s' failedFT)rrr] mark_upgraderrr'rcrrrrrs  zMyCache.mark_upgradecKs6td||f||vr||jdi|dSdS)NzRemoving '%s' (%s)r)rrrrrrr mark_removezMyCache.mark_removecCs6td||f||vr|j||jddSdS)NzPurging '%s' (%s)T)rrrrr^rrrr mark_purgerzMyCache.mark_purgecCs8||vr||jr||jr|||dSdSdSdSr#)r]rra)r'pkgnamerrrr_keep_installeds zMyCache._keep_installedc Cs\|jddD]}||dq|jD]"}||vr5||js#||jr5|j|dD] }||d|q*q|jdddkrtd|jdd D] }|D]}|j rj|j j rj|j rj|j j |krj||j d |qOqK|jD]<}||vr||js||jr|j|d D]"}|D]}|j r|j j r|j r|j j |kr||j d ||fqqqod Sd S) z[ run after the dist-upgrade to ensure that certain packages are kept installed r2KeepInstalledPkgszDistro KeepInstalledPkgs rulez%s KeepInstalledPkgs ruleOptions withNetworkTruez"Running KeepInstalledSection rulesKeepInstalledSectionz$Distro KeepInstalledSection rule: %sz %s KeepInstalledSection rule: %sN)rDrErrFr]rrVrrrerfrsectionrk)r'rrrrcrrrkeep_installed_rulesH      zMyCache.keep_installed_rulecCs|js |jddSdS)z. run before the upgrade was done in the cache PreDistUpgradeCacheN)rCrArunr)rrrpre_upgrade_ruleszMyCache.pre_upgrade_rulecCsd|jfd|jfd|jfd|jffD]@\}}|jdd|D] }||d|q|jD]%}||vrQ||js<||jrQ|j|d|D] }||d||fqEq,q|j s^|j d d Sd S) z- run after the upgrade was done in the cache InstallUpgradeRemovePurger2z PostUpgrade%szDistro PostUpgrade%s rulez%s PostUpgrade%s rulePostDistUpgradeCacheN) rarrrrDrErFr]rrCrAr)r'ruleactionrcrrrrpost_upgrade_rules$  zMyCache.post_upgrade_rulec CsDtdzddlm}Wnttfy)}ztd|WYd}~dSd}~wwz]|dd}|jD]}||vrF||jrF| |d n q3t d WdS| }td |||vrht d |WdS||j s||js||t d |WdSWdSWdSty}ztd|WYd}~dSd}~ww)zR this checks for nvidia hardware and checks what driver is needed znvidiaUpdate()r)NvidiaDetectionz%NvidiaDetector can not be imported %sNFz./ubuntu-drivers-obsolete.pkgs)obsoletezold nvidia driverz1no old nvidia driver installed, installing no newznv.selectDriver() returned '%s'z no '%s' foundz,installing %s as suggested by NvidiaDetectorTz$NvidiaDetection returned a error: %s)rrNvidiaDetector.nvidiadetectorr ImportError SyntaxErrorr oldPackagesr]rr selectDriverrrrra Exception)r'rrZnv oldDriverdriverrrrcheckForNvidiasF      zMyCache.checkForNvidiacCs&|D]}|jdr|jrdSqdS)Nzlinux-headers-TF)rk startswithr]rbrrr_has_kernel_headers_installed/s z%MyCache._has_kernel_headers_installedc Cstd|jz |jd\}}}Wnty-}ztd|WYd}~dSd}~wwtdgtdd}d |vrBtd d S) zd check for the running kernel and try to ensure that we have an updated version zKernel uname: '%s' -z/Can't parse kernel uname: '%s' (self compiled?)NFdmesg)r6rsWARNING: NR_CPUS limitzUP kernel on SMP system!?!T) rrrsplitrrrrrS)r'versionbuildflavourrZrrrrcheckForKernel6s zMyCache.checkForKernelcCsd}|jdd}|D]@}|jj|j}|r%|jdkr%td|j q |j rK|j j rK|j sK|j sK|j |vrKd|j vrK|j j|vrK||j d|q dS)N)requiredr2RemoveEssentialOkrzPackage %s has no priority set:z;priority in required set '%s' but not scheduled for install)rDrE_pcacherrr^priorityrrrkrerfr]rra)r'needremoveEssentialOkrcrrrr checkPriorityFs$   zMyCache.checkPrioritycCsZd}|r!|ddkr||td|d7}|s|jdd|dS)Nrg{Gz?rT)finished)locked pulseProgress processEventstimesleep)r'r@rBirrr updateGUI[s    zMyCache.updateGUIc Csrt}|tj|j|j|fd}|zzK||d| | t r3t dn||||||sK||||jrbttdddd|DWnwty}zktd}|jd d d kr|td 7}n|jd d d kr|jd dd kr|td7}|r|td7}n |td7}|td7}||td|t|}t d||WYd}~W||dSd}~wwW||n ||wg} g} |D]^} | j rq| j!r:| "| j#| j$j%D].} t&'| j(| j)j*dkr7| j+D]\} }| j,j-.| }|r5|j/s5| "| j#nqq q| j0j1}d}|D]}||j2O}qB|sT| "| j#qz|j3dd}|rht dWdSWn t4j5ytYnwt6| dkr| 7t dd| t6| dkr| 7t dd| ||tdtdd| |dSdS) N)targetrTz5skipping kernel checks because we run inside a chrootz!Broken packages after upgrade: %srncss"|] }|js |jr|jVqdSr#)is_inst_broken is_now_brokenrk).0prrr s z&MyCache.distUpgrade..zBAn unresolvable problem occurred while calculating the upgrade. r foreignPkgsrzThis was likely caused by: * Unofficial software packages not provided by Ubuntu Please use the tool 'ppa-purge' from the ppa-purge package to remove software from a Launchpad PPA and try the upgrade again. False devReleasezThis was caused by: * Upgrading to a pre-release version of Ubuntu This is most likely a transient problem, please try again later. z@This is most likely a transient problem, please try again later.zIf none of this applies, then please report this bug using the command 'ubuntu-bug ubuntu-release-upgrader-core' in a terminal. zIf you want to investigate this yourself the log files in '/var/log/dist-upgrade' will contain details about the upgrade. Specifically, look at 'main.log' and 'apt.log'.zCould not calculate the upgradezDist-upgrade failed: '%s'Frr2AllowUnauthenticatedzAllowUnauthenticated set!z!Packages to downgrade found: '%s' z$Unauthenticated packages found: '%s'z"Error authenticating some packageszIt was not possible to authenticate some packages. This may be a transient network problem. You may want to try again later. See below for a list of unauthenticated packages. )8 threadingLockacquireThreadrr@startrupgrader rrrrrrr_keepBaseMetaPkgsInstalled_installMetaPkgs_verifyChangesrrKrrprDrVrrrLrreleaserrmarked_downgraderrkr^ version_listrHversion_comparever_str installedr file_listrr find_index is_trustedreoriginstrusted getboolean configparser NoOptionErrorrosort)r'r@ serverModerCrBtrZdetails error_msg untrusted downgradercr verFileIterindex indexfiler4r5originbrrr distUpgradefs           -          zMyCache.distUpgradecCstjd}|jdd}|D]A}|jr,||jr,t d|jt t d|j|jrR|j j dkrR|jj|dfvrR|j|vrRt d|jt t d |jq|jdd }|D],}|d \}}||vr||jr||jj|kr||js||jrt t d |q\dS) zy this function tests if the current changes don't violate our constraints (deny listed removals etc) zAPT::Architecturer2rzHThe package '%s' is marked for removal but it's in the removal deny listzJThe package '%s' is marked for removal but it is in the removal deny list.TallzDThe package '%s' is marked for removal but it's an ESSENTIAL packagez1The essential package '%s' is marked for removal. BadVersionsrz*Trying to install deny listed version '%s')rHrDrrErr_inRemovalDenylistrkrrrKrr^ essentialr0 architecturerrerrr)r' main_archr rc badVersionsbvrrrrrr*s2    zMyCache._verifyChangescCsn|jj|j}|durtd|jdS|jdur$td|jdS|jd\}}|jj ||fdS)a helper to make sure that the pkg._records is pointing to the right location - needed because python-apt 0.7.9 dropped the python-apt version but we can not yet use the new version because on upgrade the old version is still installed NzNo candidate ver: FzNo file_list for: %s rT) rrrr^printrkr1poprlookup)r'rcrrrArrr_lookupPkgRecords  zMyCache._lookupPkgRecordc Csi}t}|D]C}||std|jq|jjjdD]*}| drI|t dddD]}| }||vr@t||<|| |jq1qq|D](}d}|j dd}||vr^d}||D] }||jsmd}nqb|ru| |qM|S) Nz&no PkgRecord found for '%s', skipping r!Task:,Tr2 IgnoredTasksF)rXrQrrrkrrrecordrrrorTrjrDrEr]) r'tasksinstalled_tasksrclinetaskr0 ignored_tasksrrrrinstalledTasks)s:      zMyCache.installedTaskscCstd|D]M}|js|jrq||t|jjdr!|jjjs*t d|j q|jjj dD]!}| drS|t dd dD]}|}||vrR|qDq2qdS)Nzrunning installTasksrUzcan not find Record for '%s'r!rRrST)rrrr]rQrrrrUrrkrrrorTra)r'rVrcrXrYrrr installTasksEs"    zMyCache.installTaskscCs$|jddD]}||dqdS)Nr2 BaseMetaPkgsz%base meta package keep installed rule)rDrEr)r'r@rcrrrr(Vsz"MyCache._keepBaseMetaPkgsInstalledc sfdd}jddjddD]}|qD]:}z|vr>|jr>|jr>td||Wq tyZ}zt d||fWYd}~q d}~ww|stdD]d}d }j|d D] }||vo}|jM}qr|rtd |z|Wn+tt fy}zt d ||f| t d |t dWYd}~dSd}~wwtd||j fnqg|sddd}| t dt d|dfdSd S)NcsVD]&}|vr(|}|jr|jrtd|j|jr |jr%|jr(dSqdS)zy internal helper that checks if at least one meta-pkg is installed or marked install z(metapkg '%s' installed but marked_deleteTF)r]rrrrkr)rrcrFr'rrmetaPkgInstalled\s  z2MyCache._installMetaPkgs..metaPkgInstalledr2r3r]zMarking '%s' for upgradez Can't mark '%s' for upgrade (%s)z$none of the '%s' meta-pkgs installedTrz!guessing '%s' as missing meta-pkgz$failed to mark '%s' for install (%s)zCan't install '%s'zIt was impossible to install a required package. Please report this as a bug using 'ubuntu-bug ubuntu-release-upgrader-core' in a terminal.Fzmarked_install: '%s' -> '%s'rnrr4zCan't guess meta-packagezYour system does not contain a %s or %s package and it was not possible to detect which version of Ubuntu you are running. Please install one of the packages above first using synaptic or apt-get before proceeding.)rDrErar] is_upgradablerrrrKrKeyErrorrrrrp)r'r@r_rcrrZr meta_pkgsrr^rr)Zsd     zMyCache._installMetaPkgscCs8|jD]}t||rtd||fdSqdS)Nzdenylist expr '%s' matches '%s'TF)rPrecompilematchrr)r'rexprrrrrHs zMyCache._inRemovalDenylistc Cs||jrtd|dS||jkrtd|dS||r+td|dS|jddD]}||vrO||jrO||jj |krOtd|dSq2||vrVdSz |j dd }Wn t j ykd}Ynwt |j}||zF||j|d |j||vrWdS|D]*}|j|vs|j|vs||js|j|jkrtd ||jf|WdSqWdSttfy} ztd |t| | f|WYd} ~ dSd} ~ ww) Nz skipping running kernel pkg '%s'Fz skipping kernel metapackage '%s'z"skipping '%s' (in removalDenylist)r2rz'skipping '%s' (in KeepInstalledSection)TPurgeObsoletes)purgez8package '%s' produces an unwanted removal '%s', skippingz3_tryMarkObsoleteForRemoval failed for '%s' (%s: %s))endswithrrrrRrHrDrEr0rr6r7r8rHrrrrr@rrrkrrKrarrepr) r'rremove_candidatesforced_obsoletes foreign_pkgsrrhrrcrZrrrtryMarkObsoleteForRemovals`           z!MyCache.tryMarkObsoleteForRemovalcCs0t}|D]}|jr||s||jq|Sz1 get all package names that are not downloadable )rXr]anyVersionDownloadablerjrk)r' obsolete_pkgsrcrrr_getObsoletesPkgss  zMyCache._getObsoletesPkgscCs|jjD]}|jr dSqdS)zA helper that checks if any of the version of pkg is downloadable TF)r^r-rf)r'rcrrrrrps zMyCache.anyVersionDownloadablecCs4t}|D]}|jr|j|jr||jq|Sro)rXr]rrr^rjrk)r'unused_dependenciesrcrrr_getUnusedDependenciess  zMyCache._getUnusedDependenciescCst}|jdd}tj|r5t|}|D]}|ds%|| qWdn1s0wYt}|D]}||vrAq:||}|j rR|j |j sR|jrSq:||q:t|S)z return list of installed and demoted packages If a demoted package is a automatic install it will be skipped r2 Demotions#N)rXrDrVrrr~rrrjrTr]ris_auto_installedr^rrs)r' demotionsdemotions_file demotions_frXinstalled_demotionsdemoted_pkgnamercrrrget_installed_demoted_packagess.     z&MyCache.get_installed_demoted_packagescCs~t}|D]7}|jr<||r<|jsqd}|jjD]}||jvr'|j|kr'd}||jvr3|j|kr3d}q|r<||jq|S)zm get all packages that are installed from a foreign repo (and are actually downloadable) TF) rXr]rfrer4archiverCrjrk)r'allowed_originfromDisttoDistrmrcforeignrCrrr_getForeignPkgss$      zMyCache._getForeignPkgsFc shGdddt}fdd}gi}i}td>}|D]3}z |\}} } } } } WntyD}ztd||fWYd}~qd}~ww| vrN| qWdn1sYwYjtdd t j d }d }t |d r|j d ddr|j d d}tj|st|td|dddd||dd fD]R}tj|}||}tj|rt|}|j|j}n td|d}||vrtd|||f|||||<qtd||f|||<||||<q~td|d}|D] }td|jr|js|jrtd|jtf|d7}q|t|dt}d}t |d rX|j d ddrXtd |j d d}|D]}|jsP|jrV||jj 7}qFd}|r||D]}|j!rs|jsm|j"rs||j#j 7}q_td!|||j$fd|j%fd|j&fd"d|fd#d$||fd|ff D]4\}}|dkrqtj|}td%||||||j'f||j'|8_'||j(|7_(qi}|D]G}||j'dkrt )t*t+||j'd}t,|t-r|.t/0}t )||j(}t,|t-r |.t/0}t1|||||||<qt|dkr2t2d&d'd(|Dt3t4|5dS))z this checks if we have enough free space on /var, /boot and /usr with the given cache Note: this can not be fully accurate if there are multiple mountpoints for /usr, /var, /boot c@r,)z)MyCache.checkFreeSpace..FreeSpacez@ helper class that represents the free space on each mounted fs cSs||_d|_dSr)freer )r' initialFreerrrr(?s z2MyCache.checkFreeSpace..FreeSpace.__init__Nr/rrrr FreeSpace=s rcs D] }||r |SqdS)z return 'id' of a directory so that directories on the same filesystem get the same id (simply the mount_point) /)r)d mount_pointmountedrr make_fs_idCs  z*MyCache.checkFreeSpace..make_fs_idz /proc/mountsz-line '%s' in /proc/mounts not understood (%s)NT)rreversezDir::Cache::archivesz/tmp/rDAufsEnabledFRWDirzcache aufs_rw_dir: %sr/usrz/varz/bootz/homezdirectory '%s' does not existsrzDir %s mounted on %szFree space on %s: %szfs_free contains: '%s'z%^linux-(image|image-debug)-[0-9.]*-.*z,%s (new-install) added with %s to boot spacergz*taking aufs overlay into space calculationz&additional space for the snapshots: %s)ri )z/tmpiP)riz dir '%s' needs '%s' of '%s' (%f)zNot enough free space: %scSsg|]}t|qSr)rL)rrrrr sz*MyCache.checkFreeSpace..)6objectrr ValueErrorrrrr9rorHrDrrr}rVrrr~rrealpathstatvfsf_bavailf_frsizerrcrerkrr KERNEL_SIZE INITRD_SIZEreinstalled_sizer]rr0rrrrr  size_to_strfloatabs isinstancebytesdecodelocalegetpreferredencodingr"rr-rsvalues)r'snapshots_in_userrmnt_mapfs_freemountsrXwhatwherefsoptionsarDrZ archivedir aufs_rw_dirrfs_idstr kernel_countrc space_in_bootrequired_for_aufsrequired_for_snapshotsr%size required_list free_at_least free_neededrrrcheckFreeSpace4s                      zMyCache.checkFreeSpace)NTr#)T)r)F)s\    ! l