CasperSecurity

Current Path : /lib/python3/dist-packages/DistUpgrade/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/DistUpgrade/__pycache__/DistUpgradeCache.cpython-310.pyc

o

>I�c���@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 dkr�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&�.�dSdS)�N)�Popen�PIPE�)�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
rrrrr0rrcCs�d}d}t��d}t�d|�D]/}|d|kr"|tj�|�7}q|�d�dks7|�d�dks7|�d�dkr8q|tj�|�7}q|dkrLt�d�d	}|dkrWt�d
�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
    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)�kernel�initrd�kver�f�
initrd_bufferrrr�#estimate_kernel_initrd_size_in_boot4s4��r!c@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)�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)rrr
�__doc__r(r*rrrrr"Xsr"c@�eZdZdZdd�ZdS)�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__N�rrr
r+r(rrrrr-hsr-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&�Zdud'd(�Zdud)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zdvd:d;�Z dvd<d=�Z!dvd>d?�Z"dvd@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:dwdqdr�Z;dS)x�MyCacher�NTc
Cs"g|_g|_||_||_d|_d|_||_|j�dd�|_d|_	|rJz
t
��|��d|_Wnt
yI}zdt|�vrAt|��t|��d}~wwtj�||�|�dd�|_|j�|d�|_tdd	gtdd
���d��|_|��|�dd
�dkr�dtj vr�t
j�!dd�t
j�!dd�dS)NF�Distro�MetaPkgs���Tzdpkg --configure -a�RemovalDenylistFilerz-r)�stdout�universal_newlinesr�Sources�From�hardy�RELEASE_UPGRADE_NO_RECOMMENDSzAPT::Install-Recommends�truez"APT::AutoRemove::SuggestsImportant�false)"�
to_install�	to_remove�view�quirks�lock�partialUpgrade�config�getlist�metapkgs�
_listsLock�apt_pkg�pkgsystem_lock�lock_lists_dir�SystemError�strrr�apt�Cacher(�getListFromFile�removal_denylist�_get_linux_metapackage�linux_metapackagerr�communicate�stripr�_initAptLog�getr�environ�set)r'rDr@rA�progressrB�errrr(vsF
��
���
zMyCache.__init__cCs2|D]}|jrq|jjtjkr|jddd�qdS)z! honor the dselect install state F)�	auto_inst�auto_fixN)�is_installed�_pkg�selected_staterH�SELSTATE_INSTALL�mark_install�r'�pkgrrr�_apply_dselect_upgrade�s��zMyCache._apply_dselect_upgradecCsJt�}|D]}|jr|jjs"|jj|jks|jj|jkr"|�|j�q|S)zB return the packages not downloadable packages in reqreinst state )	rX�	candidate�downloadabler^�
inst_state�	ReInstReq�
HoldReInstReq�add�name)r'�	reqreinstrcrrr�req_reinstall_pkgs�s�zMyCache.req_reinstall_pkgscCs~|j}t|�dkr=tddt|��}tddt|��d�|�}|�||�r=|��gd�t|�}|���|�|�	�dSd	S)
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)
rm�lenr�join�askYesNoQuestion�release_lock�list�getTerminal�call�get_lock)r'r@rl�header�summary�cmdrrr�fix_req_reinst�s&��
�zMyCache.fix_req_reinstcCs�|j�ddd�}tj�|�st�|�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 file�Files�LogDirz/var/log/dist-upgradezDir::LogzDir::Log::Terminalzapt-term.logzapt.logi�z
Log time: %s
zutf-8zDebug::pkgProblemResolverr<zDebug::pkgDepCache::MarkerzDebug::pkgDepCache::AutoInstallN)rD�getWithDefaultrr�exists�makedirsrHrX�openrp�O_RDWR�O_CREAT�O_APPEND�logfd�datetime�now�write�encode)r'�logdirr�rwrrrrU�s 
�
�
zMyCache._initAptLogcCsZt|d�rt�|j�t�|j�t�d�|_t�d�|_t�|jd�t�|jd�dS)N�
old_stdoutrr)�hasattrr�closer��
old_stderr�dup�dup2r�r)rrr�_startAptResolverLog�s
zMyCache._startAptResolverLogcCs4t�d�t�d�t�|jd�t�|jd�dS)Nrr)r�fsyncr�r�r�r)rrr�_stopAptResolverLog�s

zMyCache._stopAptResolverLogcs�fdd�}|S)z3 decorator to ensure that the apt output is logged cs*|d���|i|��}|d��|S�Nr)r�r�)�args�kwargs�res�rrr�wrapper�sz(MyCache.withResolverLog.<locals>.wrapperr)rr�rr�r�withResolverLog�szMyCache.withResolverLogcCs,t�|j�}t��}|�||j|j�|jS)z< get the size of the packages that are required to download )rH�PackageManager�	_depcache�Acquire�get_archives�_list�_records�fetch_needed)r'�pm�fetcherrrr�required_download�szMyCache.required_downloadcCs|jjS)z9 get the size of the additional required space on the fs )r��usr_sizer)rrr�additional_required_spacesz!MyCache.additional_required_spacecCs z|jjWStyYdSw)z< get the extra size needed to install the snap replacements r)rA�extra_snap_space�AttributeErrorr)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:tj�d�d}t�|�|_|jdkrd|}t|��dS)NzDir::State::ListsrBrzCan not lock '%s' )rHrD�find_dirrvrGr)r'rkrZrrrrJs
�zMyCache.lock_lists_dircCs$|jdkrt�|j�d|_dSdS)Nrr4)rGrr�r)rrr�unlock_lists_dirs

�zMyCache.unlock_lists_dircCsH|��tj�||�}|��|r|jrttd���|dkr"td��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�rMrN�updaterJ�release_file_download_error�IOError�_)r'�	fprogressr�rrrr�"s
�zMyCache.updatecCs,t�d�|jr|��tj�|||�dS)Nzcache.commit())r�inforBrrrMrN�commit)r'r��	iprogressrrrr�1s
zMyCache.commitc
CsT|jr(z
t��d|_WdSty'}zt�d|�WYd}~dSd}~wwdS)NFzfailed to SystemUnLock() (%s) )rBrH�pkgsystem_unlockrKr�debug�r'�
pkgSystemOnlyrZrrrrr7����zMyCache.release_lockc
CsT|js(z
t��d|_WdSty'}zt�d|�WYd}~dSd}~wwdS)NTzfailed to SystemLock() (%s) )rBrHrIrKrr�r�rrrrv?r�zMyCache.get_lockcCsB|r
|j�|j�}n|jj}|dkrt�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_verr^�current_verrrrkrf)r'rc�useCandidate�verrrrrfGszMyCache.downloadablecCs|jo	|j�|j�S)z$ check if the pkg is auto-removable )r]r��
is_garbager^rbrrr�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)rrrr�Ws
zMyCache.fix_brokencCsLg|_g|_|��D]}|js|jr|j�|j�|jr#|j�|j�q
dS)z* create a snapshot of the current changes N)r>r?�get_changes�marked_install�marked_upgrade�appendrk�
marked_deleterbrrr�create_snapshot\s��zMyCache.create_snapshotcCs|j��dSr#)r��initr)rrr�clearfsz
MyCache.clearcCsZt�|j�}||��|jD]
}||}|��q|jD]
}||}|jddd�qdS)z restore a snapshot F)r\r[N)rH�ActionGroupr�r�r?�mark_deleter>ra)r'�actiongrouprkrcrrr�restore_snapshotis


�zMyCache.restore_snapshotcCs�|j�dd�}|D]8}||vr||jrt�d|�dSd}|j�|d�D]
}|||vo2||jM}q'|rAt�d|�dSq	t�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
        r2r3z@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)rDrEr]rr�)r'rF�key�
deps_foundrcrrr�need_server_modews
�
zMyCache.need_server_modecCsL|jr$zt�d�|��WdSty#|�td�td��YdSwdS)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�rK�errorr�)r'r@rrr�coherence_check�s

	�
��zMyCache.coherence_check�cKsXt�d||f�||vr*||jdi|��||js*||js*t�d|�dSdS)NzInstalling '%s' (%s)z Installing/upgrading '%s' failedFTr)rr�rar�r�r��r'rc�reason�flagsrrrra�szMyCache.mark_installcCsPt�d||f�||vr&||jr&||��||js&t�d|�dSdS)NzUpgrading '%s' (%s)zUpgrading '%s' failedFT)rr�r]�mark_upgrader�r��r'rcr�rrrr��s
zMyCache.mark_upgradecKs6t�d||f�||vr||jdi|��dSdS)NzRemoving '%s' (%s)r)rr�r�r�rrr�mark_remove���zMyCache.mark_removecCs6t�d||f�||vr|j�||jd�dSdS)NzPurging '%s' (%s)T)rr�r�r�r^r�rrr�
mark_purge�r�zMyCache.mark_purgecCs8||vr||jr||jr|�||�dSdSdSdSr#)r]r�ra)r'�pkgnamer�rrr�_keep_installed�s���zMyCache._keep_installedc	Cs\|j�dd�D]}|�|d�q|jD]"}||vr5||js#||jr5|j�|d�D]
}|�|d|�q*q|j�dd�dkr�t�d�|j�dd	�D] }|D]}|j	rj|j	j
rj|jrj|j	j|krj|�|j
d
|�qOqK|jD]<}||vr�||js||jr�|j�|d	�D]"}|D]}|j	r�|j	j
r�|jr�|j	j|kr�|�|j
d||f�q�q�qodSdS)
z[ run after the dist-upgrade to ensure that certain
            packages are kept installed r2�KeepInstalledPkgszDistro KeepInstalledPkgs rulez%s KeepInstalledPkgs rule�Options�withNetwork�Truez"Running KeepInstalledSection rules�KeepInstalledSectionz$Distro KeepInstalledSection rule: %sz %s KeepInstalledSection rule: %sN)rDrEr�rFr]r�rVrr�rerfr��sectionrk)r'r�r�r�rcrrr�keep_installed_rule�sH
��
���
������	zMyCache.keep_installed_rulecCs|js|j�d�dSdS)z. run before the upgrade was done in the cache �PreDistUpgradeCacheN)rCrA�runr)rrr�pre_upgrade_rule�s�zMyCache.pre_upgrade_rulecCs�d|jfd|jfd|jfd|jffD]@\}}|j�dd|�D]	}||d|�q|jD]%}||vrQ||js<||jrQ|j�|d|�D]}||d||f�qEq,q|j	s^|j
�d	�d
Sd
S)z- run after the upgrade was done in the cache �Install�Upgrade�Remove�Purger2z
PostUpgrade%szDistro PostUpgrade%s rulez%s PostUpgrade%s rule�PostDistUpgradeCacheN)rar�r�r�rDrErFr]r�rCrAr�)r'�rule�actionrcr�rrr�post_upgrade_rule�s$�
����zMyCache.post_upgrade_rulec
CsDt�d�zddlm}Wnttfy)}zt�d|�WYd}~dSd}~wwz]|dd�}|jD]}||vrF||jrF|�	|d	�n	q3t�
d
�WdS|��}t�d|�||vrht�d|�WdS||j
s�||js�||��t�
d
|�WdSWdSWdSty�}zt�d|�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)rr��NvidiaDetector.nvidiadetectorr��ImportError�SyntaxErrorr��oldPackagesr]r�r��selectDriverrr�r�ra�	Exception)r'r�rZ�nv�	oldDriver�driverrrr�checkForNvidiasF
��

�
�����zMyCache.checkForNvidiacCs&|D]}|j�d�r|jrdSqdS)Nzlinux-headers-TF)rk�
startswithr]rbrrr�_has_kernel_headers_installed/s��z%MyCache._has_kernel_headers_installedc
Cs�t�d|j�z|j�d�\}}}Wnty-}zt�d|�WYd}~dSd}~wwtdgtd���d}d	|vrBt�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?)NF�dmesg)r6rsWARNING: NR_CPUS limitzUP kernel on SMP system!?!T)	rr�r�splitr�rrrrS)r'�version�build�flavourrZr�rrr�checkForKernel6s��
zMyCache.checkForKernelcCs�d}|j�dd�}|D]@}|jj�|j�}|r%|jdkr%t�d|j	�q|j
rK|j
jrK|jsK|j
sK|j	|vrKd|j	vrK|j
j|vrK|�|j	d|�qdS)N)�requiredr2�RemoveEssentialOkrzPackage %s has no priority set�:z;priority in required set '%s' but not scheduled for install)rDrE�_pcacher�r�r^�priorityrr�rkrerfr]r�ra)r'�need�removeEssentialOkrcr�rrr�
checkPriorityFs$��

��zMyCache.checkPrioritycCsZd}|��r!|ddkr|��|��t�d�|d7}|��s|jdd�|��dS)Nr�g{�G�z�?rT)�finished)�locked�
pulseProgress�
processEvents�time�sleep)r'r@rB�irrr�	updateGUI[s
�zMyCache.updateGUIc
Csrt��}|��tj|j|j|fd�}|��z�zK|��|�d�|�	�|�
�t�r3t�
d�n|��|��|��|�|�|sK|�|�|��|jrbttd�d�dd�|D����Wnwty�}zktd�}|j�d	d
�dkr|td�7}n|j�d	d
�d
kr�|j�d	d�dkr�|td�7}|r�|td�7}n|td�7}|td�7}|��|�td�|�t|�}t�d|�|��WYd}~W|��|��dSd}~wwW|��|��n	|��|��wg}	g}
|��D]^}|j r�q�|j!�r:|
�"|j#�|j$j%D].}t&�'|j(|j)j*�dk�r7|j+D]\}
}|j,j-�.|
�}|�r5|j/�s5|	�"|j#�n�q�q
q�|j0j1}d}|D]}||j2O}�qB|�sT|	�"|j#�q�z|j�3dd�}|�rht�
d�WdSWnt4j5�ytYnwt6|
�dk�r�|
�7�t�dd�|
��t6|	�dk�r�|	�7�t�dd�|	��|��|�td�td�d�|	��|��dSdS) N)�targetr�Tz5skipping kernel checks because we run inside a chrootz!Broken packages after upgrade: %srncss"�|]}|js
|jr|jVqdSr#)�is_inst_broken�
is_now_brokenrk)�.0�prrr�	<genexpr>�s� z&MyCache.distUpgrade.<locals>.<genexpr>zBAn unresolvable problem occurred while calculating the upgrade.

 r��foreignPkgsr�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.

�False�
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'Frr2�AllowUnauthenticatedzAllowUnauthenticated 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�	threading�Lock�acquire�Threadrr@�startr��upgraderr�rrrrr�r��_keepBaseMetaPkgsInstalled�_installMetaPkgs�_verifyChangesr�rKr�rprDrVr�r�rLr��releaser�r��marked_downgrader�rkr^�version_listrH�version_compare�ver_str�	installedr�	file_listrr��
find_index�
is_trustedre�origins�trusted�
getboolean�configparser�
NoOptionErrorro�sort)r'r@�
serverModerCrB�trZ�details�	error_msg�	untrusted�	downgradercr��verFileIter�index�	indexfiler4r5�origin�brrr�distUpgradefs�


 ����-
�

����
����
�zMyCache.distUpgradecCstj�d�}|j�dd�}|��D]A}|jr,|�|j�r,t�	d|j�t
td�|j��|jrR|jj
dkrR|jj|dfvrR|j|vrRt�	d|j�t
td	�|j��q|j�dd
�}|D],}|�d�\}}||vr�||jr�||jj|kr�||js�||jr�t
td�|��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.T�allzDThe package '%s' is marked for removal but it's an ESSENTIAL packagez1The essential package '%s' is marked for removal.�BadVersionsr�z*Trying to install deny listed version '%s')rHrDrrEr�r��_inRemovalDenylistrkrr�rKr�r^�	essentialr0�architecturerrerr�r�)r'�	main_archrrc�badVersions�bvr�r�rrrr*�s2
����zMyCache._verifyChangescCsn|jj�|j�}|durtd|j�dS|jdur$td|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)
rr�r�r^�printrkr1�popr��lookup)r'rcr�rrArrr�_lookupPkgRecords
zMyCache._lookupPkgRecordc	Cs�i}t�}|D]C}|�|�st�d|j�q|jjj�d�D]*}|�	d�rI|t
d�d��d�D]}|��}||vr@t�||<||�|j�q1qq|D](}d}|j
�dd�}||vr^d}||D]}||jsmd}nqb|ru|�|�qM|S)	Nz&no PkgRecord found for '%s', skipping r!�Task:�,Tr2�IgnoredTasksF)rXrQrr�rkrr��recordrr�rorTrjrDrEr])	r'�tasks�installed_tasksrc�line�taskr0�
ignored_tasksr�rrr�installedTasks)s:


��
�
�zMyCache.installedTaskscCs�t�d�|D]M}|js|jrq|�|�t|jjd�r!|jjjs*t�	d|j
�q|jjj�d�D]!}|�d�rS|t
d�d��d�D]}|��}||vrR|��qDq2qdS)Nzrunning installTasksrUzcan not find Record for '%s'r!rRrST)rr�r�r]rQr�rr�rUrrkrr�rorTra)r'rVrcrXrYrrr�installTasksEs"


��zMyCache.installTaskscCs$|j�dd�D]}|�|d�qdS)Nr2�BaseMetaPkgsz%base meta package keep installed rule)rDrEr�)r'r@rcrrrr(Vs�z"MyCache._keepBaseMetaPkgsInstalledcs���fdd�}�j�dd���j�dd�D]}�|��q�D]:}z|�vr>�|jr>�|jr>t�d|��|��Wq tyZ}zt�	d||f�WYd}~q d}~ww|�s�t�d���D]d}d	}�j�|d
�D]
}||�vo}�|jM}qr|r�t�d|�z�|��Wn+tt
fy�}zt�d||f�|�td
�|td��WYd}~dSd}~wwt�d|�|j
f�nqg|�s�d��dd��}|�td�td�|�df�dSd	S)NcsV�D]&}|�vr(�|}|jr|jrt�d|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]r�rr�rkr�)r�rc�rFr'rr�metaPkgInstalled\s��z2MyCache._installMetaPkgs.<locals>.metaPkgInstalledr2r3r]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'rnrr4zCan'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.)rDrErar]�
is_upgradablerr�r�rKr�KeyErrorr�r�r�rp)r'r@r_rcr�rZr��	meta_pkgsrr^rr)Zsd���������
�

��	zMyCache._installMetaPkgscCs8|jD]}t�|��|�rt�d||f�dSqdS)Nzdenylist expr '%s' matches '%s'TF)rP�re�compile�matchrr�)r'r��exprrrrrH�s
��zMyCache._inRemovalDenylistc

Cs�|�|j�rt�d|�dS||jkrt�d|�dS|�|�r+t�d|�dS|j�dd�D]}||vrO||jrO||jj	|krOt�d|�dSq2||vrVdSz	|j�
dd	�}Wntjykd}Ynwt
�|j�}||��zF||j|d
�|j��||vr�WdS|��D]*}|j|vs�|j|vs�|�|j�s�|j|jkr�t�d||jf�|��WdSq�WdSttfy�}	zt�d|t|	�|	f�|��WYd}	~	dSd}	~	ww)
Nz skipping running kernel pkg '%s'Fz skipping kernel metapackage '%s'z"skipping '%s' (in removalDenylist)r2r�z'skipping '%s' (in KeepInstalledSection)T�PurgeObsoletes)�purgez8package '%s' produces an unwanted removal '%s', skippingz3_tryMarkObsoleteForRemoval failed for '%s' (%s: %s))�endswithrrr�rRrHrDrEr0r�r6r7r8rHr�r�r�r�r@rr�rkr�rKrar�repr)
r'r��remove_candidates�forced_obsoletes�foreign_pkgsr�rhr�rcrZrrr�tryMarkObsoleteForRemoval�s`

��



������z!MyCache.tryMarkObsoleteForRemovalcCs0t�}|D]}|jr|�|�s|�|j�q|S�z1 get all package names that are not downloadable )rXr]�anyVersionDownloadablerjrk)r'�
obsolete_pkgsrcrrr�_getObsoletesPkgs�s
�zMyCache._getObsoletesPkgscCs|jjD]}|jrdSqdS)zA helper that checks if any of the version of pkg is downloadable TF)r^r-rf)r'rcr�rrrrp�s
�zMyCache.anyVersionDownloadablecCs4t�}|D]}|jr|j�|j�r|�|j�q|Sro)rXr]r�r�r^rjrk)r'�unused_dependenciesrcrrr�_getUnusedDependencies�s�zMyCache._getUnusedDependenciescCs�t�}|j�dd�}tj�|�r5t|��}|D]}|�d�s%|�|�	��qWd�n1s0wYt�}|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~r�r�rjrTr]r��is_auto_installedr^r�rs)r'�	demotions�demotions_file�demotions_frX�installed_demotions�demoted_pkgnamercrrr�get_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<|�|j�q|S)zm get all packages that are installed from a foreign repo
            (and are actually downloadable)
        TF)	rXr]rfrer4�archiverCrjrk)r'�allowed_origin�fromDist�toDistrmrc�foreignrCrrr�_getForeignPkgss$



��zMyCache._getForeignPkgsFcshGdd�dt�}�fdd�}g�i}i}td��>}|D]3}z|��\}}	}
}}}
WntyD}zt�d||f�WYd}~qd}~ww|	�vrN��|	�qWd�n1sYwY�jtdd	�t	j
�d
�}d}t|d�r�|j
�
d
dd�r�|j
�d
d�}tj�|�s�t�|�t�d|�dddd||ddfD]R}tj�|�}||�}tj�|�r�t�|�}|j|j}n	t�d|�d}||vr�t�d|||f�|||||<q�t�d||f�|||<||�||<q�~t�d|�d}|D] }t�d|j��r|j�s|j�rt�d|jtf�|d7}q�|t|dt}d}t|d��rX|j
�
d
dd��rXt�d �|j
�d
d�}|D]}|j�sP|j�rV||jj 7}�qFd}|�r||D]}|j!�rs|j�sm|j"�rs||j#j 7}�q_t�d!|�||j$fd|j%fd|j&fd"d|fd#d$||fd|ff	D]4\}}|dk�r��q�tj�|�}t�d%||||||j'f�||j'|8_'||j(|7_(�q�i}|D]G}||j'dk�rt	�)t*t+||j'�d��}t,|t-��r�|�.t/�0��}t	�)||j(�}t,|t-��r	|�.t/�0��}t1|||�|�|||�<�q�t|�dk�r2t�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@r,)z)MyCache.checkFreeSpace.<locals>.FreeSpacez@ helper class that represents the free space on each mounted fs cSs||_d|_dSr�)�freer
)r'�initialFreerrrr(?s
z2MyCache.checkFreeSpace.<locals>.FreeSpace.__init__Nr/rrrr�	FreeSpace=sr�cs �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_point��mountedrr�
make_fs_idCs

�z*MyCache.checkFreeSpace.<locals>.make_fs_idz/proc/mountsz-line '%s' in /proc/mounts not understood (%s)NT)r��reversezDir::Cache::archivesz/tmp/rD�Aufs�EnabledF�RWDirzcache 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)r�i )z/tmpiP)r�i�z dir '%s' needs '%s' of '%s' (%f)zNot enough free space: %scSsg|]}t|��qSr)rL)rrrrr�
<listcomp>�sz*MyCache.checkFreeSpace.<locals>.<listcomp>)6�objectr�r�
ValueErrorrr�r�r9rorHrDr�r�r}rVrrr~r�realpath�statvfs�f_bavail�f_frsizerrcrerkr�r��KERNEL_SIZE�INITRD_SIZEre�installed_sizer]r�r0r�r�r�r�r
�size_to_str�float�abs�
isinstance�bytes�decode�locale�getpreferredencodingr"r�r-rs�values)r'�snapshots_in_user�r��mnt_map�fs_free�mountsrX�what�where�fs�options�arDrZ�
archivedir�aufs_rw_dirr��fs_id�str��kernel_countrc�
space_in_boot�required_for_aufs�required_for_snapshotsr%�size�
required_list�
free_at_least�free_neededrr�r�checkFreeSpace4s�	
��
���

�


���
��
�����
 ���zMyCache.checkFreeSpace)NTr#)T)r�)F)<rrr
rhrir(rd�propertyrmrzrUr�r�r�r�r�r�r�rJr�r�r�rrrvrfr�r�r�r�r�r�r�rar�r�r�r�r�r�r�r�r�rrrrEr*rQr[r\r(r)rHrnrrrprtr}r�r�rrrrr0qs�
'	














	
#*

L
9
r0�__main__)�DistUpgradeConfig)�DistUpgradeView�foo�.zubuntu-desktop)/rMrHrr�rrcrrr�r"r7�
subprocessrr�DistUpgradeGettextrr�r�utilsrr�r	rrr!r�r�r�r"r-rNr0r�sys�DistUpgradeConfigParserr�r�rN�cr��exitr�r�r[r\r�r�rrrr�<module>s\
!	l�
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY