HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/DistUpgrade/__pycache__/DistUpgradeCache.cpython-38.pyc
U

٪zc���@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
ddlmZddlmZddlmZGdd�de�ZGd	d
�d
e�ZGdd�de�Zd
d�Ze�\ZZGdd�de�ZGdd�de�ZGdd�dej�Ze dk�r�ddl!Z!ddl"m#Z#ddl$m$Z$e%d�ee#d�e$�d�Z&e%e&�'��e!�(�e&�)�e&�*�e&j+e&�,dg�e%e&�-��e&�.�dS)�N)�Popen�PIPE�)�gettext)�ngettext)�
inside_chrootc@seZdZdS)�CacheExceptionN��__name__�
__module__�__qualname__�r
r
�>/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeCache.pyr(src@seZdZdS)�CacheExceptionLockingFailedNr	r
r
r
rr,src@seZdZdS)�CacheExceptionDpkgInterruptedNr	r
r
r
rr0srcCs�d}d}t��d}t�d|�D]`}|d|krD|tj�|�7}q"|�d�dks"|�d�dks"|�d�dkrrq"q"|tj�|�7}q"|dkr�t�d�d	}|dkr�t�d
�d}|d7}d}|d
|kr�|d
}||7}||fS)zjestimate the amount of space used by the kernel and initramfs in /boot,
    including a safety margin
    r�z
/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�������?)�os�uname�glob�path�getsize�find�logging�warning)ZkernelZinitrdZkver�fZ
initrd_bufferr
r
r�#estimate_kernel_initrd_size_in_boot4s6���rc@s eZdZdZdd�Zdd�ZdS)�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||_||_||_dS�N)�
size_total�dir�size_needed)�selfrrr r
r
r�__init__`szFreeSpaceRequired.__init__cCsd|j|j|jfS)Nz@FreeSpaceRequired Object: Dir: %s size_total: %s size_needed: %s)rrr �r!r
r
r�__str__dszFreeSpaceRequired.__str__N)r
rr�__doc__r"r$r
r
r
rrXsrc@seZdZdZdd�ZdS)�NotEnoughFreeSpaceErrorzI
    Exception if there is not enough free space for this operation

    cCs
||_dSr)�free_space_required_list)r!r'r
r
rr"msz NotEnoughFreeSpaceError.__init__N�r
rrr%r"r
r
r
rr&hsr&c@s�eZdZdZdZdsdd�Zdd�Zed	d
��Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
edd��Zedd��Zedd��Zedd��Zdd�Zdd �Zdtd!d"�Zd#d$�Zdud%d&�Zdvd'd(�Zdwd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zdxd:d;�Z dyd<d=�Z!dzd>d?�Z"d{d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,e
dTdU��Z-dVdW�Z.dXdY�Z/edZd[��Z0d\d]�Z1d^d_�Z2d`da�Z3dbdc�Z4e
ddde��Z5dfdg�Z6dhdi�Z7djdk�Z8dldm�Z9dndo�Z:d|dqdr�Z;dS)}�MyCacher�NTc
Cs0g|_g|_||_||_d|_d|_||_|j�dd�|_d|_	|r�zt
��|��d|_Wn>t
k
r�}z dt|�kr�t|��t|��W5d}~XYnXtj�||�|�dd�|_|j�|d�|_tdd	gtdd
���d��|_|��|�dd
�dk�rdtj k�rt
j�!dd�t
j�!dd�dS)NF�Distro�MetaPkgs���Tzdpkg --configure -aZRemovalBlacklistFilerz-r)�stdoutZuniversal_newlinesrZSourcesZFromZhardyZRELEASE_UPGRADE_NO_RECOMMENDSzAPT::Install-Recommends�truez"APT::AutoRemove::SuggestsImportantZfalse)"�
to_install�	to_remove�view�quirks�lock�partialUpgrade�config�getlist�metapkgs�
_listsLock�apt_pkg�pkgsystem_lock�lock_lists_dir�SystemError�strrr�apt�Cacher"ZgetListFromFile�removal_blacklistZ_get_linux_metapackage�linux_metapackagerr�communicate�stripr�_initAptLog�getr�environ�set)r!r6r2r3Zprogressr4�er
r
rr"vs@

��
�zMyCache.__init__cCs2|D](}|jrq|jjtjkr|jddd�qdS)z! honor the dselect install state F)�	auto_inst�auto_fixN)�is_installed�_pkgZselected_stater:ZSELSTATE_INSTALL�mark_install�r!�pkgr
r
r�_apply_dselect_upgrade�s
zMyCache._apply_dselect_upgradecCsJt�}|D]:}|jr|jjs
|jj|jks8|jj|jkr
|�|j�q
|S)zB return the packages not downloadable packages in reqreinst state )	rH�	candidate�downloadablerMZ
inst_state�	ReInstReq�
HoldReInstReq�add�name)r!�	reqreinstrPr
r
r�req_reinstall_pkgs�s��zMyCache.req_reinstall_pkgscCs�|j}t|�dkr|tddt|��}tddt|��d�|�}|�||�r||��ddd	gt|�}|���|�|�	�d
SdS)z/ check for reqreinst state and offer to fix it rzRemove package in bad statezRemove packages in bad statez�The 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?z�The 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)
rY�lenr�joinZaskYesNoQuestion�release_lock�listZgetTerminal�call�get_lock)r!r2rX�headerZsummary�cmdr
r
r�fix_req_reinst�s&��
�zMyCache.fix_req_reinstcCs�|j�ddd�}tj�|�s&t�|�tj�d|�tj�dd�t�tj�	|d�tj
tjBtjBd�|_
tj��}d	|}t�|j
|�d
��tj�dd�tj�d
d�tj�dd�dS)z init logging, create log fileZFilesZLogDirz/var/log/dist-upgradezDir::LogzDir::Log::Terminalzapt-term.logzapt.logi�z
Log time: %s
zutf-8zDebug::pkgProblemResolverr/zDebug::pkgDepCache::MarkerzDebug::pkgDepCache::AutoInstallN)r6�getWithDefaultrr�exists�makedirsr:rH�openr\�O_RDWR�O_CREAT�O_APPEND�logfd�datetime�now�write�encode)r!Zlogdirrmrar
r
rrE�s"
�
�
zMyCache._initAptLogcCsZt|d�r"t�|j�t�|j�t�d�|_t�d�|_t�|jd�t�|jd�dS)N�
old_stdoutrr)�hasattrr�closerp�
old_stderr�dup�dup2rkr#r
r
r�_startAptResolverLog�s
zMyCache._startAptResolverLogcCs4t�d�t�d�t�|jd�t�|jd�dS)Nrr)r�fsyncrurprsr#r
r
r�_stopAptResolverLog�s

zMyCache._stopAptResolverLogcs�fdd�}|S)z3 decorator to ensure that the apt output is logged cs&|d���||�}|d��|S�Nr)rvrx)�args�kwargs�res�rr
r�wrapper�s
z(MyCache.withResolverLog.<locals>.wrapperr
)rr~r
r}r�withResolverLog�szMyCache.withResolverLogcCs,t�|j�}t��}|�||j|j�|jS)z< get the size of the packages that are required to download )r:ZPackageManager�	_depcacheZAcquireZget_archives�_list�_recordsZfetch_needed)r!ZpmZfetcherr
r
r�required_download�szMyCache.required_downloadcCs|jjS)z9 get the size of the additional required space on the fs )r�Zusr_sizer#r
r
r�additional_required_spacesz!MyCache.additional_required_spacecCs&z
|jjWStk
r YdSXdS)z< get the extra size needed to install the snap replacements rN)r3Zextra_snap_space�AttributeErrorr#r
r
r�#additional_required_space_for_snapss
z+MyCache.additional_required_space_for_snapscCs|jjdkS)z is the cache broken r)r�Zbroken_countr#r
r
r�	is_brokenszMyCache.is_brokencCs:tj�d�d}t�|�|_|jdkr6d|}t|��dS)NzDir::State::Listsr4rzCan not lock '%s' )r:r6�find_dirr`r9r)r!rWrIr
r
rr<s

zMyCache.lock_lists_dircCs |jdkrt�|j�d|_dS)Nrr-)r9rrrr#r
r
r�unlock_lists_dirs
zMyCache.unlock_lists_dircCsH|��tj�||�}|��|r4|jr4ttd���|dkrDtd��dS)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)r�r?r@�updater<Zrelease_file_download_error�IOError�_)r!�	fprogressr|r
r
rr�"s
zMyCache.updatecCs,t�d�|jr|��tj�|||�dS)Nzcache.commit())r�infor4r]r?r@�commit)r!r�Z	iprogressr
r
rr�1s
zMyCache.commitc
CsN|jrJzt��d|_Wn0tk
rH}zt�d|�W5d}~XYnXdS)NFzfailed to SystemUnLock() (%s) )r4r:Zpkgsystem_unlockr=r�debug�r!Z
pkgSystemOnlyrIr
r
rr]7s
zMyCache.release_lockc
CsN|jsJzt��d|_Wn0tk
rH}zt�d|�W5d}~XYnXdS)NTzfailed to SystemLock() (%s) )r4r:r;r=rr�r�r
r
rr`?s
zMyCache.get_lockcCsB|r|j�|j�}n|jj}|dkr<t�d|j|f�dS|jS)z* check if the given pkg can be downloaded Nz1no version information for '%s' (useCandidate=%s)F)r��get_candidate_verrMZcurrent_verrrrWrS)r!rPZuseCandidate�verr
r
rrSGszMyCache.downloadablecCs|jo|j�|j�S)z$ check if the pkg is auto-removable )rLr��
is_garbagerMrOr
r
r�pkg_auto_removableRs�zMyCache.pkg_auto_removablecCs
|j��S)z^ try to fix broken dependencies on the system, may throw
            SystemError when it can't)r��
fix_brokenr#r
r
rr�WszMyCache.fix_brokencCsLg|_g|_|��D]2}|js$|jr2|j�|j�|jr|j�|j�qdS)z* create a snapshot of the current changes N)r0r1�get_changes�marked_install�marked_upgrade�appendrW�
marked_deleterOr
r
r�create_snapshot\szMyCache.create_snapshotcCs|j��dSr)r�Zinitr#r
r
r�clearfsz
MyCache.clearcCsZt�|j�}||��|jD]}||}|��q|jD]}||}|jddd�q:dS)z restore a snapshot F)rKrJN)r:�ActionGroupr�r�r1�mark_deleter0rN)r!�actiongrouprWrPr
r
r�restore_snapshotis


zMyCache.restore_snapshotcCs�|j�dd�}|D]p}||kr<||jr<t�d|�dSd}|j�|d�D]}|||kod||jM}qN|rt�d|�dSqt�d�dS)	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
        r+r,z@need_server_mode(): run in 'desktop' mode, (because of pkg '%s')FT�KeyDependencieszIneed_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)r6r7rLrr�)r!r8�key�
deps_foundrPr
r
r�need_server_modews

zMyCache.need_server_modecCsL|jrHzt�d�|��Wn*tk
rF|�td�td��YdSXdS)zY check if the cache is ok and if the required metapkgs
            are installed
        z$Have broken pkgs, trying to fix themzBroken packagesz�Your system contains broken packages that couldn't be fixed with this software. Please fix them first using synaptic or apt-get before proceeding.FT)r�rr�r�r=�errorr�)r!r2r
r
r�sanity_check�s

�zMyCache.sanity_check�cKsTt�d||f�||krP||jf|�||jsP||jsPt�d|�dSdS)NzInstalling '%s' (%s)z Installing/upgrading '%s' failedFT)rr�rNr�r�r��r!rP�reason�flagsr
r
rrN�szMyCache.mark_installcCsPt�d||f�||krL||jrL||��||jsLt�d|�dSdS)NzUpgrading '%s' (%s)zUpgrading '%s' failedFT)rr�rL�mark_upgrader�r��r!rPr�r
r
rr��s
zMyCache.mark_upgradecKs.t�d||f�||kr*||jf|�dS)NzRemoving '%s' (%s))rr�r�r�r
r
r�mark_remove�szMyCache.mark_removecCs2t�d||f�||kr.|j�||jd�dS)NzPurging '%s' (%s)T)rr�r�r�rMr�r
r
r�
mark_purge�szMyCache.mark_purgecCs,||kr(||jr(||jr(|�||�dSr)rLr�rN)r!�pkgnamer�r
r
r�_keep_installed�s��zMyCache._keep_installedc	Csh|j�dd�D]}|�|d�q|jD]D}||kr&||jsF||jr&|j�|d�D]}|�|d|�qTq&|j�dd�dk�rdt�d�|j�dd	�D]@}|D]6}|j	r�|j	j
r�|jr�|j	j|kr�|�|j
d
|�q�q�|jD]�}||kr�||j�s||jr�|j�|d	�D]P}|D]D}|j	�r|j	j
�r|j�r|j	j|k�r|�|j
d||f��q�qq�dS)
z[ run after the dist-upgrade to ensure that certain
            packages are kept installed r+ZKeepInstalledPkgszDistro KeepInstalledPkgs rulez%s KeepInstalledPkgs rule�OptionsZwithNetwork�Truez"Running KeepInstalledSection rules�KeepInstalledSectionz$Distro KeepInstalledSection rule: %sz %s KeepInstalledSection rule: %sN)r6r7r�r8rLr�rFrr�rRrSr��sectionrW)r!r�r�r�rPr
r
r�keep_installed_rule�s<
�
�
�
��
�zMyCache.keep_installed_rulecCs|js|j�d�dS)z. run before the upgrade was done in the cache ZPreDistUpgradeCacheN)r5r3�runr#r
r
r�pre_upgrade_rule�szMyCache.pre_upgrade_rulecCs�d|jfd|jfd|jfd|jffD]�\}}|j�dd|�D]}||d|�q>|jD]J}||krX||jsx||jrX|j�|d|�D]}||d||f�q�qXq$|j	s�|j
�d	�d
S)z- run after the upgrade was done in the cache ZInstallZUpgradeZRemoveZPurger+z
PostUpgrade%szDistro PostUpgrade%s rulez%s PostUpgrade%s ruleZPostDistUpgradeCacheN)rNr�r�r�r6r7r8rLr�r5r3r�)r!Zrule�actionrPr�r
r
r�post_upgrade_rule�s�
�zMyCache.post_upgrade_rulec
CsDt�d�zddlm}Wn:ttfk
rT}zt�d|�WY�dSd}~XYnXz�|dd�}|jD]&}||krh||jrh|�	|d	�q�qht�
d
�WdS|��}t�d|�||kr�t�d|�WdS||j
�s
||j�s
||��t�
d
|�WdSWn2tk
�r>}zt�d|�W5d}~XYnXdS)zR
        this checks for nvidia hardware and checks what driver is needed
        znvidiaUpdate()r)�NvidiaDetectionz%NvidiaDetector can not be imported %sFNz./ubuntu-drivers-obsolete.pkgs)Zobsoletezold 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)rr�ZNvidiaDetector.nvidiadetectorr��ImportError�SyntaxErrorr�ZoldPackagesrLr�r�ZselectDriverrr�r�rN�	Exception)r!r�rIZnvZ	oldDriverZdriverr
r
r�checkForNvidias4




 zMyCache.checkForNvidiacCs&|D]}|j�d�r|jrdSqdS)Nzlinux-headers-TF)rW�
startswithrLrOr
r
r�_has_kernel_headers_installed/s�z%MyCache._has_kernel_headers_installedc
Cs�t�d|j�z|j�d�\}}}Wn6tk
r\}zt�d|�WY�dSd}~XYnXtdgtd���d}d	|kr�t�d
�dS)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?)FN�dmesg)r.rsWARNING: NR_CPUS limitzUP kernel on SMP system!?!T)	rr�r�splitr�rrrrC)r!�versionZbuildZflavourrIr�r
r
r�checkForKernel6s
zMyCache.checkForKernelcCs�d}|j�dd�}|D]�}|jj�|j�}|rJ|jdkrJt�d|j	�q|j
r|j
jr|js|j
s|j	|krd|j	kr|j
j|kr|�|j	d|�qdS)N)Zrequiredr+�RemoveEssentialOkrzPackage %s has no priority set�:z;priority in required set '%s' but not scheduled for install)r6r7�_pcacher�r�rMZpriorityrr�rWrRrSrLr�rN)r!�need�removeEssentialOkrPr�r
r
r�
checkPriorityFs&����
�zMyCache.checkPrioritycCsTd}|��r<|ddkr |��|��t�d�|d7}q|jdd�|��dS)Nr�g{�G�z�?rT)Zfinished)�lockedZ
pulseProgress�
processEvents�time�sleep)r!r2r4�ir
r
r�	updateGUI[s

zMyCache.updateGUIc
Csnt��}|��tj|j|j|fd�}|���z�z�|�	�|�
d�|��|��t
�rht�d�n|��|��|��|�|�|s�|�|�|��|jr�ttd�d�dd�|D����Wn�tk
�r�}z�td�}|j�d	d
�dk�r|td�7}n4|j�d	d
�d
k�r:|j�d	d�dk�r:|td�7}|�rN|td�7}n|td�7}|td�7}|��|�td�|�t|�}t�d|�|��WY�W�dSd}~XYnXW5|��|��Xg}	g}
|��D]�}|j �r�q�|j!�rl|
�"|j#�|j$j%D]^}t&�'|j(|j)j*�dk�r|j+D]8\}
}|j,j-�.|
�}|�r*|j/�s*|	�"|j#��q�q*�q�q�|j0j1}d}|D]}||j2O}�q||�s�|	�"|j#��q�z(|j�3dd�}|�r�t�d�WdSWnt4j5k
�r�YnXt6|
�dk�r|
�7�t�dd�|
��t6|	�dk�rj|	�7�t�dd�|	��|��|�td�td�d�|	��|��dSdS) N)�targetrzTz5skipping kernel checks because we run inside a chrootz!Broken packages after upgrade: %srZcss |]}|js|jr|jVqdSr)Zis_inst_brokenZ
is_now_brokenrW)�.0�pr
r
r�	<genexpr>�sz&MyCache.distUpgrade.<locals>.<genexpr>zBAn unresolvable problem occurred while calculating the upgrade.

 r�ZforeignPkgsr�z�This 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.

�FalseZ
devReleasez�This 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.z�If none of this applies, then please report this bug using the command 'ubuntu-bug ubuntu-release-upgrader-core' in a terminal. z�If 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'Frr+ZAllowUnauthenticatedzAllowUnauthenticated set!z!Packages to downgrade found: '%s'� z$Unauthenticated packages found: '%s'z"Error authenticating some packagesz�It 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�	threadingZLock�acquireZThreadr�r2�start�releaser\r�Zupgrader�r�rrrr�r�r��_keepBaseMetaPkgsInstalled�_installMetaPkgs�_verifyChangesr�r=r�r6rFrxr�r>rvr�r�Zmarked_downgrader�rWrM�version_listr:Zversion_compareZver_str�	installedr��	file_listr�r�Z
find_indexZ
is_trustedrR�origins�trusted�
getboolean�configparser�
NoOptionErrorr[�sort)r!r2Z
serverModer5r4�trIZdetailsZ	error_msgZ	untrustedZ	downgraderPr�ZverFileIter�indexZ	indexfiler�r��origin�br
r
r�distUpgradefs�


$� 
��

��
�zMyCache.distUpgradecCstj�d�}|j�dd�}|��D]�}|jrX|�|j�rXt�	d|j�t
td�|j��|jr"|jj
dkr"|jj|dfkr"|j|kr"t�	d|j�t
td	�|j��q"|j�dd
�}|D]Z}|�d�\}}||kr�||jr�||jj|kr�||j�s||jr�t
td�|��q�dS)
zx this function tests if the current changes don't violate
            our constrains (blacklisted removals etc)
        zAPT::Architecturer+r�zHThe package '%s' is marked for removal but it's in the removal blacklistzJThe package '%s' is marked for removal but it is in the removal blacklist.T�allzDThe package '%s' is marked for removal but it's an ESSENTIAL packagez1The essential package '%s' is marked for removal.ZBadVersionsr�z*Trying to install blacklisted version '%s')r:r6rr7r�r��_inRemovalBlacklistrWrr�r=r�rMZ	essentialr�Zarchitecturer�rRr�r�r�)r!Z	main_archr�rPZbadVersionsZbvr�r�r
r
rr��s6
������zMyCache._verifyChangescCsn|jj�|j�}|dkr(td|j�dS|jdkrHtd|j���dS|j�d�\}}|jj�	||f�dS)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)
r�r�r�rM�printrWr��popr��lookup)r!rPr�rr�r
r
r�_lookupPkgRecords
zMyCache._lookupPkgRecordc	Cs�i}t�}|D]�}|�|�s.t�d|j�q|jjj�d�D]T}|�	d�r>|t
d�d��d�D].}|��}||kr�t�||<||�|j�qbq>q|D]P}d}|j
�dd�}||kr�d}||D]}||js�d}q�q�|r�|�|�q�|S)	Nz&no PkgRecord found for '%s', skipping r��Task:�,Tr+ZIgnoredTasksF)rHr�rr�rWr�r��recordr�r�r[rDrVr6r7rL)	r!�tasksZinstalled_tasksrP�line�taskr�Z
ignored_tasksr�r
r
r�installedTasks)s2



zMyCache.installedTaskscCs�t�d�|D]�}|js|jr q|�|�t|jjd�rB|jjjsTt�	d|j
�q|jjj�d�D]B}|�d�rd|t
d�d��d�D]}|��}||kr�|��q�qdqdS)Nzrunning installTasksr�zcan not find Record for '%s'r�r�r�T)rr�r�rLr�rqr�r�r�rrWr�r�r[rDrN)r!r�rPr�r�r
r
r�installTasksEs


zMyCache.installTaskscCs$|j�dd�D]}|�|d�qdS)Nr+�BaseMetaPkgsz%base meta package keep installed rule)r6r7r�)r!r2rPr
r
rr�Vsz"MyCache._keepBaseMetaPkgsInstalledcs���fdd�}�j�dd���j�dd�D]}�|��q*�D]t}z:|�kr|�|jr|�|jr|t�d|��|��Wq@tk
r�}zt�	d||f�W5d}~XYq@Xq@|��s�t�d���D]�}d	}�j�|d
�D]}||�ko��|jM}q�|r�t�d|�z�|��WnZtt
fk
�r~}z6t�d||f�|�td
�|td��WY�dSd}~XYnXt�d|�|j
f��q�q�|��s�d��dd��}|�td�td�|�df�dSd	S)NcsV�D]L}|�kr�|}|jr4|jr4t�d|j�|jr@|jrJ�|jrdSqdS)zy
            internal helper that checks if at least one meta-pkg is
            installed or marked install
            z(metapkg '%s' installed but marked_deleteTF)rLr�rr�rWr�)r�rP�r8r!r
r�metaPkgInstalled\s�z2MyCache._installMetaPkgs.<locals>.metaPkgInstalledr+r,r�zMarking '%s' for upgradez Can't mark '%s' for upgrade (%s)z$none of the '%s' meta-pkgs installedTr�z!guessing '%s' as missing meta-pkgz$failed to mark '%s' for install (%s)zCan't install '%s'z�It 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'rZrr-zCan't guess meta-packagez�Your 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.)r6r7rNrLZ
is_upgradablerr�r�r=r�KeyErrorr�r�r�r\)r!r2rrPr�rIr�Z	meta_pkgsr
r�rr�ZsX��&��

��	zMyCache._installMetaPkgscCs8|jD],}t�|��|�rt�d||f�dSqdS)Nz blacklist expr '%s' matches '%s'TF)rA�re�compile�matchrr�)r!r��exprr
r
rr��s

zMyCache._inRemovalBlacklistc

Cs�|�|j�rt�d|�dS||jkr:t�d|�dS|�|�rVt�d|�dS|j�dd�D]:}||krd||jrd||jj	|krdt�d|�dSqd||kr�dSz|j�
dd	�}Wntjk
r�d}YnXt
�|j�}||��z�||j|d
�|j��||k�rWdS|��D]^}|j|k�s^|j|k�s^|�|j��s^|j|jk�r&t�d||jf�|��WdS�q&WnNttfk
�r�}	z*t�d|t|	�|	f�|��WY�dSd}	~	XYnXdS)
Nz skipping running kernel pkg '%s'Fz skipping kernel metapackage '%s'z#skipping '%s' (in removalBlacklist)r+r�z'skipping '%s' (in KeepInstalledSection)TZPurgeObsoletes)�purgez8package '%s' produces an unwanted removal '%s', skippingz3_tryMarkObsoleteForRemoval failed for '%s' (%s: %s))�endswithrrr�rBr�r6r7r�r�r�r�r�r:r�r�r�r�r2r�r�rWr�r=rr�repr)
r!r�Zremove_candidatesZforced_obsoletes�foreign_pkgsr�rr�rPrIr
r
r�tryMarkObsoleteForRemoval�sZ

�


�
�
�z!MyCache.tryMarkObsoleteForRemovalcCs0t�}|D] }|jr
|�|�s
|�|j�q
|S�z1 get all package names that are not downloadable )rHrL�anyVersionDownloadablerVrW)r!Z
obsolete_pkgsrPr
r
r�_getObsoletesPkgs�s
zMyCache._getObsoletesPkgscCs|jjD]}|jrdSqdS)zA helper that checks if any of the version of pkg is downloadable TF)rMr�rS)r!rPr�r
r
rr�szMyCache.anyVersionDownloadablecCs4t�}|D]$}|jr
|j�|j�r
|�|j�q
|Sr)rHrLr�r�rMrVrW)r!Zunused_dependenciesrPr
r
r�_getUnusedDependencies�s
zMyCache._getUnusedDependenciesc	Cs�t�}|j�dd�}tj�|�rVt|��(}|D]}|�d�s.|�|�	��q.W5QRXt�}|D]<}||krnq`||}|j
r`|j�|j
�s`|jr�q`|�|�q`t|�S)z� return list of installed and demoted packages

            If a demoted package is a automatic install it will be skipped
        r+Z	Demotions�#)rHr6rFrrrergr�rVrDrLr�Zis_auto_installedrMr�r^)r!Z	demotionsZdemotions_fileZdemotions_fr�Zinstalled_demotionsZdemoted_pkgnamerPr
r
r�get_installed_demoted_packagess(

��z&MyCache.get_installed_demoted_packagescCs~t�}|D]n}|jr
|�|�r
|js&q
d}|jjD]4}||jkrN|j|krNd}||jkr2|j|kr2d}q2|r
|�|j�q
|S)zm get all packages that are installed from a foreign repo
            (and are actually downloadable)
        TF)	rHrLrSrRr��archiver�rVrW)r!Zallowed_originZfromDistZtoDistr	rPZforeignr�r
r
r�_getForeignPkgss$
�
�zMyCache._getForeignPkgsFcshGdd�dt�}�fdd�}g�i}i}td��x}|D]l}z|��\}}	}
}}}
Wn<tk
r�}zt�d||f�WY�q6W5d}~XYnX|	�kr6��|	�q6W5QRX�jtdd	�t	j
�d
�}d}t|d��r|j
�
d
dd��r|j
�d
d�}tj�|��st�|�t�d|�dddd||ddfD]�}tj�|�}||�}tj�|��rpt�|�}|j|j}nt�d|�d}||k�r�t�d|||f�|||||<n&t�d||f�|||<||�||<�q2~t�d|�d}|D]B}t�d|j��r�|j�s|j�r�t�d|jtf�|d7}�q�|t|dt}d}t|d��r�|j
�
d
dd��r�t�d �|j
�d
d�}|D]"}|j�s�|j�r�||jj 7}�q�d}|�r�|D]*}|j!�r�|j�s�|j"�r�||j#j 7}�q�t�d!|�||j$fd|j%fd|j&fd"d|fd#d$||fd|ff	D]h\}}|dk�rB�q,tj�|�}t�d%||||||j'f�||j'|8_'||j(|7_(�q,i}|D]�}||j'dk�r�t	�)t*t+||j'�d��}t,|t-��r�|�.t/�0��}t	�)||j(�}t,|t-��r|�.t/�0��}t1|||�|�|||�<�q�t|�dk�rdt�2d&d'd(�|D��t3t4|�5����dS))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@seZdZdZdd�ZdS)z)MyCache.checkFreeSpace.<locals>.FreeSpacez@ helper class that represents the free space on each mounted fs cSs||_d|_dSry)�freer�)r!ZinitialFreer
r
rr">sz2MyCache.checkFreeSpace.<locals>.FreeSpace.__init__Nr(r
r
r
r�	FreeSpace<srcs �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�)�dZmount_point�Zmountedr
r�
make_fs_idBs

z*MyCache.checkFreeSpace.<locals>.make_fs_idz/proc/mountsz-line '%s' in /proc/mounts not understood (%s)NT)r��reversezDir::Cache::archivesz/tmp/r6ZAufsZEnabledFZRWDirzcache 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)ri�z dir '%s' needs '%s' of '%s' (%f)zNot enough free space: %scSsg|]}t|��qSr
)r>)r�r�r
r
r�
<listcomp>�sz*MyCache.checkFreeSpace.<locals>.<listcomp>)6�objectrgr��
ValueErrorrr�r�r�r[r:r6r�rqrdrFrrrerf�realpath�statvfs�f_bavail�f_frsizerrrrWr�r��KERNEL_SIZE�INITRD_SIZErRZinstalled_sizerLr�r�r�r�r�rr�Zsize_to_str�float�abs�
isinstance�bytes�decode�locale�getpreferredencodingrr�r&r^�values)r!Zsnapshots_in_userrZmnt_mapZfs_freeZmountsr�Zwhat�whereZfsZoptions�ar�rIZ
archivedirZaufs_rw_dirrZfs_id�strZkernel_countrPZ
space_in_bootZrequired_for_aufsZrequired_for_snapshotsr�sizeZ
required_listZ
free_at_leastZfree_neededr
rr�checkFreeSpace3s�	
�



��
��
���
 ��zMyCache.checkFreeSpace)NT)N)T)T)T)r�)r�)r�)r�)F)<r
rrrTrUr"rQ�propertyrYrcrErvrxrr�r�r�r�r<r�r�r�r]r`rSr�r�r�r�r�r�r�rNr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r
rrrrr0r
r
r
rr)qs�
'	














	

#*

L
9
r)�__main__)�DistUpgradeConfig)�DistUpgradeViewZfoo�.zubuntu-desktop)/r?r:rr)rrrr�rlr�r��
subprocessrrZDistUpgradeGettextrr�rZutilsrr�rrrrr"r#rrr&r@r)r
�sysZDistUpgradeConfigParserr3r4r��cr0�exitr�r�r�r�r�r�r
r
r
r�<module>sX!
	k