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: //usr/lib/python3/dist-packages/DistUpgrade/__pycache__/DistUpgradeController.cpython-38.pyc
U

٪zc���@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZmZmZmZmZmZmZmZmZddlmZddlm Z dd	l!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm'Z'dd
l(m)Z)ddl*m+Z+ddl*m,Z,e+j-e,_-ddl.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z6ddl4m7Z7ddl5Z5ddl#m8Z8m9Z9m:Z:ddl;m<Z<dZ=dd�Z>Gdd�de?�Z@Gdd�deA�ZBeCdk�r�ddlDmDZDejEejFd�eD�ZGeBeG�ZHeH�I�eH�J�dS) �N)�
NoOptionError)�ConfigParser�)�get)	�country_mirror�url_downloadable�check_and_fix_xbit�get_arch�iptables_active�
inside_chroot�)get_string_with_no_auth_from_source_entry�is_child_of_process_name�
inhibit_sleep)�Template)�urlsplit)�Step)�MyCache)�DistUpgradeConfig)�DistUpgradeQuirks)�AptCdrom)�distinfo)�sourceslist)�SourcesList�	is_mirror)�
get_distro�NoDistroTemplateException)�gettext)�ngettext)�CacheExceptionDpkgInterrupted�CacheExceptionLockingFailed�NotEnoughFreeSpaceError)�
run_apportz/var/run/reboot-requiredcCs>ddddg}z|�|�WStk
r8t|�dYSXdS)zB key() function for sorted to ensure "correct" component ordering �main�
restrictedZuniverseZ
multiverserN)�index�
ValueError�len)�aZordering�r(�C/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py�component_ordering_keyOs
r*c@seZdZdS)�NoBackportsFoundExceptionN)�__name__�
__module__�__qualname__r(r(r(r)r+Zsr+c@s�eZdZdZd_dd�Zd`dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdadd�Z
dd�Zdd�Zdd�Zdbdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dcdMdN�Z(dddOdP�Z)dQdR�Z*dSdT�Z+dUdV�Z,dWdX�Z-dYdZ�Z.d[d\�Z/d]d^�Z0dS)e�DistUpgradeControllerz3 this is the controller that does most of the work NcCs�d}|dks|dkr*t��}tj�|d�}||_||_t�d|�t�d�t	�
d|jj�||_
|j
�td��d|_d|_|jr�|jjdkr�d|_n
|jj|_|r�|j}nd}t||�|_t|�|_d|j�dd	�|_|j�d
�|j�d
dt|j��|j�d
dd
�|j�r2|jj�r2|j�d
dd�|j�dd�|_|j�dd�|_ |j�dd�|_!t"�|_#dtj$k�r�t	�
d�t%j�dd�d|_&t'||j�|_(t)�|_*dtj$d<dtj$d<dt��dtj$dftj$d<t+d�|j�,dd �}t%j�d!t|��t%j�d"td#��t%j�d$td%��t%j�d&d'�t%j�d(d'�t%j�d)d*�|j�-d+d,�|_.|j�/dd-�|_0g|_1|j�2d.��r�d/d0�|j�3d.�D�|_1d1|_4d2|_5i|_6dS)3Nz/usr/share/locale/�.Zmozubuntu-release-upgraderzUsing '%s' viewz
Reading cacheTZFilesZ	BackupExt�Options�withNetworkZ
devRelease�False�True�SourcesZFromZToZValidOriginZ"RELEASE_UPGRADE_NO_FORCE_OVERWRITEzenable dpkg --force-overwritezDPkg::Options::z--force-overwriteF�1ZRELEASE_UPGRADE_IN_PROGRESSZPYCENTRAL_FORCE_OVERWRITEz%s:%sz	/imported�PATHz./imported/invoke-rc.d�Network�
MaxRetrieszAcquire::Retriesz
Dpkg::MaxArgsizDpkg::MaxArgBytesizAcquire::http::TimeoutZ20zAcquire::ftp::TimeoutzApt::Get::List-Cleanup�false�Distro�ForcedObsoletesZValidMirrorsZThirdPartyMirrorscSsg|]}|d�qS)rr()�.0Zpairr(r(r)�
<listcomp>�sz2DistUpgradeController.__init__.<locals>.<listcomp>i��)7�os�getcwd�path�join�datadir�optionsr�bindtextdomain�
textdomain�logging�debug�	__class__r,�_view�updateStatus�_�cache�fetcherr2�
useNetworkZ	cdromPathr�aptcdromr�configr�sources_backup_extZadd_section�set�str�
devel_release�fromDist�toDist�originr	�arch�environ�apt_pkg�_partialUpgrader�quirksrZinhibitor_fdr�getint�getlist�forced_obsoletesZgetListFromFile�
valid_mirrors�valid_3p_mirrors�has_section�items�_aptCronJobPerms�_uid�	_user_env)�selfZdistUpgradeViewrErDZ	localedir�	cdrompath�
maxRetriesr(r(r)�__init__asz






�
�zDistUpgradeController.__init__TFc
Cs�t�d�|jdkr"|j�d�n|j��|j��d}d}z|�|�WStk
r�}zr|d7}|j	�
�t�d�t�d|�||kr�t�
d|�|j	�
td	�td
��|r�|��n
t�d�W5d}~XYq>Xq>dS)NzopenCache()ZPreCacheOpen�rr皙�����?z'failed to lock the cache, retrying (%i)zCache can not be locked (%s)zUnable to get exclusive lockz�This usually means that another package management application (like apt-get or aptitude) already running. Please close that application first.)rHrIrNr^�run�release_lock�unlock_lists_dir�
_openCacherrK�
processEvents�time�sleep�errorrM�abort�sys�exit)ri�lock�restore_sources_list_on_failZMAX_LOCK_RETRIESZ
lock_retry�er(r(r)�	openCache�s0





��
zDistUpgradeController.openCachec	Cs�z*t|j|j|j|j��|�|_|j|_Wnntk
r�t�	d�dddg}t
j�d�dkrh|�
d�|j���|�t|j|j|j|j���|_YnX|j|j_t�dt|j��dS)	Nz-dpkg interrupted, calling dpkg --configure -a�
/usr/bin/dpkg�--configure�-a�DEBIAN_FRONTEND�noninteractive�--force-confoldz/openCache(), new cache size %i)rrRrKr^�getOpCacheProgressrNZ	apt_cacherrH�warningr@r[r�append�getTerminal�callr]ZpartialUpgraderIr&)rirz�cmdr(r(r)rr�s*�


�
z DistUpgradeController._openCachecCs$|j�dd�}|jjj|kr dSdS)z�
      Returns True if this view support upgrades over ssh.
      In theory all views should support it, but for savety
      we do only allow text ssh upgrades (see LP: #322482)
      �ViewZ
SupportSSHTF)rRr`rKrJr,)riZ	supportedr(r(r)�_viewSupportsSSHsz&DistUpgradeController._viewSupportsSSHcCs�tj�d�}tj�|�s�tj�d�r�td�r�|��sbt�d�|j	�t
d�t
d��t�d�dSd	}|j	�
t
d
�t
d�|�}|dkr�t�d�t�dd
d|dt|�g�}|dkr�t
d�}t
d�|}t�r�d|}|t
d�|7}|j	�||�dS)z� this will check for server mode and if we run over ssh.
            if this is the case, we will ask and spawn a additional
            daemon (to be sure we have a spare one around in case
            of trouble)
        z"/var/run/release-upgrader-sshd.pidz/procZsshdzupgrade over ssh not allowedz.Upgrading over remote connection not supportedz�You are running the upgrade over a remote ssh connection with a frontend that does not support this. Please try a text mode upgrade with 'do-release-upgrade'.

The upgrade will abort now. Please try without ssh.rFi�zContinue running under SSH?aThis session appears to be running under ssh. It is not recommended to perform a upgrade over ssh currently because in case of failure it is harder to recover.

If you continue, an additional ssh daemon will be started at port '%s'.
Do you want to continue?z/usr/sbin/sshdz-oz
PidFile=%sz-przStarting additional sshdz�To make recovery in case of failure easier, an additional sshd will be started on port '%s'. If anything goes wrong with the running ssh you can still connect to the additional one.
z-iptables -I INPUT -p tcp --dport %s -j ACCEPTz�If you run a firewall, you may need to temporarily open this port. As this is potentially dangerous it's not done automatically. You can open the port with e.g.:
'%s'T)r@rBrC�exists�isdirr
r�rHrvrKrMrxry�askYesNoQuestion�
subprocessr�rUr
�information)riZpidfileZport�res�summaryZdescrr�r(r(r)�	_sshMagicsT
��
�

��

����zDistUpgradeController._sshMagiccCs�ddlm}ddlm}d}|jdksD|jdksD|jdksD|jdkrHd	}|d|d
�}|j��|j�d�sv|j��q^|jdkr�t	�
d
�dS|j��}||j||j|jd�}|�
�dS)z� this is a helper that is run if we are started from a CD
            and we have network - we will then try to fetch a update
            of ourself
        r)�MetaReleaseCore)�DistUpgradeFetcherSelfFZdapperZhardyZlucidZpreciseT)ZuseDevelopmentRelease�forceLTSrnNzNo new dist found)�new_dist�progressrEZview)ZMetaReleaser�r��releaserKrsZ
downloaded�waitr�rHrv�getAcquireProgressrEro)rir�r�r��mr�rOr(r(r)�_tryUpdateSelfJs6
����



�z$DistUpgradeController._tryUpdateSelfc
Cs t�d�dg}|D�]\}}d|}tj�|�rt�}t|��}|�|�W5QRXz|�dd�}Wn*t	k
r�t�d||f�YdSXzt�
d|�}Wn8tk
r�}	zt�d	|	�WY�dSd
}	~	XYnX||tj�
d|�fkrt�d|||tj�
d|�f�dSqd
S)z� sanity check that /usr/bin/python3 points to the default
            python version. Users tend to modify this symlink, which
            breaks stuff in obscure ways (Ubuntu #75557).
        z_pythonSymlinkCheck run)�python3r�z/usr/share/%s/debian_defaultsZDEFAULTzdefault-versionz'no default version for %s found in '%s'Fz/usr/bin/%szos.readlink failed (%s)Nz/usr/binz8%s symlink points to: '%s', but expected is '%s' or '%s'T)rHrIr@rBr��SafeConfigParser�openZreadfprr�readlink�OSErrorrvrC)
riZbinaries_and_dirnames�binary�dirnameZdebian_defaultsrR�fZexpected_defaultZfs_default_versionr|r(r(r)�_pythonSymlinkCheckis4

�
�z)DistUpgradeController._pythonSymlinkCheckc
Cs�tjdddgtjdd���d��|_}t�d|�||jks�||j	ks�t�
d||jf�|j�
td	�td
||j	f��t
�d�|j�rF|jj�rFt��d}t�d
|�t�dt�|d��tj�|d�r�tj�d|d�tj�|d��rtj�d|d�|d}tj�|��rFt�d|�t�tj|�|��|���s�t�
d�|j�
td	�td��t
�d�z|��Wn8tk
�r�}zt�
d|�WY�dSd}~XYnX|j� |j��s�dS|j�!�|_"|j"�r�dtj#d<n
dtj#d<|�$��st�
d�dSddl%m&}|D]X}tj�|��r.t�'|tj(��s.t�
d |�|j�
td!�|td"�|�|�)��q.|j*�r�|j�r�|jj+dk�r�|j�,td#�td$�d%�}||_-|j�d&d't.|j-��t�d(|�|�r�|�/�dS))z: initial cache opening, sanity checking, network checking Zlsb_releasez-cz-sT)�stdout�universal_newlinesrzlsb-release: '%s'zBad upgrade: '%s' != '%s' zCan not upgradez=An upgrade from '%s' to '%s' is not supported with this tool.rz
/backportszusing backports in '%s' zhave: %sz/*.udebr~zDir::Bin::dpkgz/usr/lib/apt/methodszDir::Bin::methodsz/etc/apt/apt.conf.d/01ubuntuzadding config '%s'z%pythonSymlinkCheck() failed, abortingzMYour python3 install is corrupted. Please fix the '/usr/bin/python3' symlink.zopenCache() failed: '%s'FNZserverZRELEASE_UPGRADE_MODEZdesktopzcheckViewDepends() failed)�SYSTEM_DIRSz%s not writablezCan not write to '%s'z�Its not possible to write to the system directory '%s' on your system. The upgrade can not continue.
Please make sure that the system directory is writable.z)Include latest updates from the Internet?a�The upgrade system can use the internet to automatically download the latest updates and install them during the upgrade.  If you have a network connection this is highly recommended.

The upgrade will take longer, but when it is complete, your system will be fully up to date.  You can choose not to do this, but you should install the latest updates soon after upgrading.
If you answer 'no' here, the network is not used at all.ZYesr1r2z#useNetwork: '%s' (selected by user))0r��Popen�PIPE�communicate�stripr�rHrIrWrXrvrKrMrxryrE�havePrerequistsr@rA�info�globrBr�r\rRrTZread_config_filer�r�r}�SystemErrorrNZsanity_check�need_server_mode�
serverModer[�checkViewDependsZDistUpgradeMainr��access�W_OKrwrQr2r�rPrUr�)rir��backportsdir�confr|r�Z	systemdirr�r(r(r)�prepare�s�����


�




���zDistUpgradeController.preparecCs>t�d|�|js"t�d�dSd|j|jf}t|tj�S)zf
        helper that checks if a sources.list entry points to 
        something downloadable
        zverifySourcesListEntry: %sz(skipping downloadable check (no network)Tz%s/dists/%s/Release)rHrIrP�uri�distr)ri�entryr�r(r(r)�_sourcesListEntryDownloadable�s
z3DistUpgradeController._sourcesListEntryDownloadablecsv	|rt�d�n
t�d��j�dd�}�j�ddd�sBdtjkrPt�d�d}d}|d	k�r�j�r�t��j�d
d���j�d
d�D�]X}t�d|�|�j	k�s�j	|j
�rt�j	|j
j�d
k�s�j	|j
r�t�j	|j
j�dkr��j	|j
jd
j
dkr�t�d|�z.t�}|��j�|�d�d	}t�d�Wn�tk
�r�}zvt�d|�t�d�d}ddg}d}	�j�d|	�j||��j�d|	�jd||��j�dd�jd||�W5d}~XYnX�q�q��j�dd�}
�jg�fdd�|
D�}�jg�fdd�|
D�}d�_g}
�jjdd�D]D}d |jk�rT�q@|j�d!��rf�q@|j�d"��rx�q@|
�|��q@|
�j_d}i�_i}�jjdd�D�]}|j|k�r�d#||j<|j�s�|j�rܐq�|j�d$��r|j �jk�rt�d%|�d	|_�q�nX|j�d$��rjt!j�"d&�}tj#�$d'|t!�%|j�d(|j d)f��s�t�d*|�d	|_�q�d+�j}|j�s�|j�d,��r�|j |k�r��j|_ d-g|_&t�d.|��q�|j�s�|j�d/�j��r�t�d0�d	|_�q�|j�sP�j'�rP�j'j(d	k�rPd1�j|j k�rPt�d2�d1�j|_ |j)t*d3��j7_)d	|_�q�|j�s�d4|jk�r�t�d5�d6t+�dfD]Z}	t,�,|�}|	|_�j|_ ��-|��r|t�.d7|	�|	|_|j|k�r�d8||j<�qؐq|t�d9t/|����0|j�}|�p��1|j�}|�s|�rLd	}|j�sj|j2d:k�sjd;|jk�sjd<�j|j k�sjd=�j|j k�sjd>|jk�rnd}|j |k�r�t�d?t/|��||O}n�|j |k�rL||jd#k�r�||O}t,�,|�}�j|_ ��-|��s�d@||j<n
d8||j<||jd@k�rd	|_d	�_t�dAt/|��n,||O}||�3|j �|_ t�dBt/|��n6|j2d:k�r^�q�n$|�r�d	|_d	�_t�dCt/|��|j2dk�r�dD|jk�rȈj4dEk�s��j4dFk�r�t�dG�j4�dH|_dI�jdJ�jd<�jfD]b}�j�5|t6��|j�s�|j |k�r�|j2dk�r�|j&D]$}||k�r0�q�j|�|��q�q�q�|j �jk�rb�j|_ dKt*dL��j}t7|j)t8��r�|j)|�9dM�7_)n|j)|7_)d	|_d	�_t�dNt/|��|�r�|j |k�r�||�3|j �|_ |j |k�r��q�dI�jdJ�jd<�jfD]Z}�j�5|t6��|j |k�r|j2dk�r|j&D]$}||k�rX�qF�j|�|��qF�qt�dO|j2|j |j&f�d}	d}�j�|j2|	|j |j&|��q��jjdd�D]�}|j�s�|j�s�|j2d:k�s�|j�d$��s�|j �jk�	r�q�|j �jk�r��j�j�j|j }|�r�t�.dPt/|��|j&�:t;|t<dQ��t�.dRt/|���j|j =�q�|S)SNz&rewriteSourcesList() with mirror_checkzrewriteSourcesList()r5Z
ComponentsZAllowThirdPartyFZ"RELEASE_UPGRADER_ALLOW_THIRD_PARTYz,mirror check skipped, *overriden* via configTr;�BaseMetaPkgszChecking pkg: %srrZnowz)BaseMetaPkg '%s' has no candidate.originsr"z/get_distro().enable_component("main") succeededz$NoDistroTemplateException raised: %sz]get_distro().enable_component("main") failed, overwriting sources.list instead as last resortz* auto generated by ubuntu-release-upgraderr#� http://archive.ubuntu.com/ubuntu�deb�-updatesz!http://security.ubuntu.com/ubuntu�	-securityZPocketscsg|]}d�j|f�qS�z%s-%s)rW�r=�x�rir(r)r>5s�z<DistUpgradeController.rewriteSourcesList.<locals>.<listcomp>csg|]}d�j|f�qSr�)rXr�r�r(r)r>7s�z/extras.ubuntu.comzE## This software is not part of Ubuntu, but is offered by third-partyz5## developers who want to ship their latest software.�unknownzcdrom:z,disabled '%s' cdrom entry (dist == fromDist)zDir::State::listsz
%s/%s%s_%s_%sZdistsZReleasez:disabling cdrom source '%s' because it has no Release filez
%s-commercialzhttp://archive.canonical.comZpartnerz transitioned commercial to '%s' z*http://landscape.canonical.com/packages/%sz&commenting landscape.canonical.com outz%s-proposedz2upgrade to development release, disabling proposedz5Not for humans during development stage of release %szold-releases.ubuntu.com/z-upgrade from old-releases.ubuntu.com detectedz"http://%sarchive.ubuntu.com/ubuntuz%transition from old-release.u.c to %sZpassedzexamining: '%s'zdeb-srcz/security.ubuntu.comz%s-securityz%s-backportsz/archive.canonical.comz%entry '%s' is already set to new distZfailedz)entry '%s' was disabled (no Release file)zentry '%s' updated to new distz&entry '%s' was disabled (unknown dist)zports.ubuntu.comZpowerpcZsparcz-moving %s source entry to 'ports.ubuntu.com' z%http://ports.ubuntu.com/ubuntu-ports/�%s�
%s-updates� zdisabled on upgrade to %szUTF-8z(entry '%s' was disabled (unknown mirror)zAdding entry: %s %s %sz)fixing components inconsistency from '%s')�keyzto new entry '%s')=rHrIrRr`�getWithDefaultr@r[r�rPrN�	candidater&�origins�archiverZget_sources�sourcesZenable_componentr�	exception�addrXrW�sources_disabled�listr��line�
startswithr��found_components�invalid�disabledr�r\�find_dirrBr�Zuri_to_filename�compsrErV�commentrMr�copyr�r�r�isMirror�isThirdPartyMirror�typer$rZ�
setdefaultrT�
isinstance�bytes�encode�extend�sortedr*)ri�mirror_checkZsync_componentsZmain_was_missing�pkgname�distror|r�r�r�ZpocketsZ	fromDistsZtoDistsZnew_listr�ZfoundToDistZentry_uri_test_results�listdirZcdistZ
test_entryZvalidMirrorZthirdPartyMirrorZvalidTo�d�compZdisable_commentZcomponent_diffr(r�r)�rewriteSourcesList�s�
�

��
���

�������

��

���

��
�
�


�����


�����

�


�
�
�z(DistUpgradeController.rewriteSourcesListcs&t�d�t�jd��_�j��j�t�fdd��jD��sf�j�	t
d�t
d��j�}|sf����j
dd��s`t�d	��j�	t
d	�t
d
��j�jf�}|�rXt�jd��_�j
dd��s`�j�r`t
d�}t
d
��j�jf}�j�	||�s����t�d�d}ddg}�j�d|�j|��j�d|�jd|��j�dd�jd|�n����j��zt��}|��Wnvtk
�r�t�d�tj�d��rΈj�t
d�t
d��t�ddg�n �j�t
d�t
d��t�d�YdSX�j�r�j�t
d�t
d��t�� �j�dS) NzupdateSourcesList()�ZmatcherPathc3s$|]}|jdko|j�jkVqdS)r�N)r�r�rW)r=r|r�r(r)�	<genexpr>%sz:DistUpgradeController.updateSourcesList.<locals>.<genexpr>z!No valid sources.list entry foundz�While scanning your repository information no entry about %s could be found.

An upgrade might not succeed.

Do you want to continue anyway?T)r�zNo valid mirror foundaWWhile scanning your repository information no mirror entry for the upgrade was found. This can happen if you run an internal mirror or if the mirror information is out of date.

Do you want to rewrite your 'sources.list' file anyway? If you choose 'Yes' here it will update all '%s' to '%s' entries.
If you select 'No' the upgrade will cancel.FzGenerate default sources?z�After scanning your 'sources.list' no valid entry for '%s' was found.

Should default entries for '%s' be added? If you select 'No', the upgrade will cancel.z"Generated new default sources.listr�r"r#r�r�z"http://security.ubuntu.com/ubuntu/r�z<Repository information invalid after updating (we broke it!)�/usr/bin/apport-bugzRepository information invalidzlUpgrading the repository information resulted in a invalid file so a bug reporting process is being started.�
apport-bug�ubuntu-release-upgrader-corez�Upgrading the repository information resulted in a invalid file. To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.�.Missing apport-bug, bug report not autocreatedzThird party sources disabledz�Some third party entries in your sources.list were disabled. You can re-enable them after the upgrade with the 'software-properties' tool or your package manager.)!rHrIrrDr�ZbackuprS�anyrKr�rMrWrwr�rvrXrPr�r�Zsaver\Z
SourceList�read_main_listr�r@rBr�r�r�r�r��
get_telemetryZset_using_third_party_sources)rir�ZprimZseconr�r�rr(r�r)�updateSourcesLists|
��

��
�
�
�

��
�z'DistUpgradeController.updateSourcesListcCst�d�g}g}g}g}g}|jD]r}|jr<|�|j�q$|jrP|�|j�q$|jrd|�|j�q$|jr~|j	r~|�|j�q$|jr$|j
r$|�|j�q$t�dd�|��t�dd�|��t�dd�|��t�dd�|��t�dd�|��dS)Nz$About to apply the following changeszKeep at same version: %sr�zUpgradable, but held- back: %sz
Remove: %szInstall: %szUpgrade: %s)rHrIrNZmarked_installr��nameZmarked_upgradeZ
marked_delete�is_installedZ
is_upgradableZmarked_keeprC)ri�instZupZrmZheldZkeep�pkgr(r(r)�_logChanges�s,

z!DistUpgradeController._logChangescCs�t�d�|j�d�|js dSt|jj�dkrPt�d�|j�|j	�|�
�t|jj�dkr�|jj}tddt|��}tdd	t|��d
�|�}|j	�
||�dSg}|j�dd�D]$}||jkr�|j|jr�|�|�q�t�d
d�t|���|j��|_|j�|j|j|j�|_t|j�dk�r:|j�ddd�n|j�ddd�|j�r\|jj|_t�dd�t|j���t�dd�t|j���dS)N�doPostInitialUpdateZPostInitialUpdateFrz-packages in reqReinstall state, trying to fixzPackage in inconsistent statezPackages in inconsistent statez�The package '%s' is in an inconsistent state and needs to be reinstalled, but no archive can be found for it. Please reinstall the package manually or remove it from the system.z�The packages '%s' are in an inconsistent state and need to be reinstalled, but no archive can be found for them. Please reinstall the packages manually or remove them from the system.z, r;�MetaPkgszMetaPkgs: %sr�r1ZforeignPkgsr4r3�Foreign: %s�Obsolete: %sT)rHrIr^rorNr&Zreq_reinstall_pkgsr�Zfix_req_reinstrKr}rrCrvrRr`r�r�r��_getObsoletesPkgs�
obsolete_pkgs�_getForeignPkgsrYrWrX�foreign_pkgsrTr�ZinstalledTasks�tasks)riZ	reqreinst�headerr�Z	meta_pkgsr�r(r(r)r��sJ

��
�
z)DistUpgradeController.doPostInitialUpdatec
Cs�t�d|�|js"t�d�dS|jj��|j��}d}|dk	rJ|}n|j�	dd�}d}||kr�z|j�
|�WnPttfk
r�}z.t
|�}t�d||f�|d	7}WY�q\W5d}~XYnXdSt�d
�|r�|j�td�td�d
|�dS)Nz"running doUpdate() (showErrors=%s)zBdoUpdate() will not use the network because self.useNetwork==falseTrr8r9r?zHIOError/SystemError in cache.update(): '%s'. Retrying (currentRetry: %s)rzdoUpdate() failed completelyzError during updatez�A problem occurred during the update. This is usually some sort of network problem, please check your network connection and retry.r�F)rHrIrPrNZ_listr�rKr�rRr_�updater��IOErrorrUrvrM)ri�
showErrors�forceRetriesr��currentRetryrkZ	error_msgr|r(r(r)�doUpdate�s6


�zDistUpgradeController.doUpdatecs>tj�d�st�d�dSdddddd	g}t�fd
d�|D��sNt�d�dSd
}td���}|D]�}|��}z|��\}}}}}	}
Wn<t	k
r�}zt�d||f�WY�q`W5d}~XYnX|dkr�q`d}d|�d�kr`t�d|�W5QR�dSq`W5QRX|�s$�j
�td�td��n�j
�td�td��d
S)z= check that /boot/efi is a mounted partition on an EFI systemz/sys/firmware/efizNot an UEFI systemTzshim-signedzgrub-efi-amd64z
grub-efi-ia32zgrub-efi-armzgrub-efi-arm64Z
sicherbootc3s$|]}|�jko�j|jVqdS�N)rNr�)r=Zblr�r(r)r��sz6DistUpgradeController._checkBootEfi.<locals>.<genexpr>z'UEFI system, but no UEFI grub installedFz/proc/mountsz-line '%s' in /proc/mounts not understood (%s)Nz	/boot/efiZrw�,zFound writable ESP %sz%EFI System Partition (ESP) not usablezxYour EFI System Partition (ESP) is not mounted at /boot/efi. Please ensure that it is properly configured and try again.zzThe EFI System Partition (ESP) mounted at /boot/efi is not writable. Please mount this partition read-write and try again.)
r@rBr�rHrIr�r�r��splitr%rKrvrM)riZbootloadersZmountedZmountsr�Zwhat�whereZfsrEr'�br|r(r�r)�
_checkBootEfi�s<


��z#DistUpgradeController._checkBootEficCs>td�}td�}td�}td�}td�}td�}td�}|j�dd	d
�rVt�d�dS|��}z|j�|�Wn�tk
�r8}	z�t	j�
d
�}
d}|
|d|d|d|d|d|i}|	jD]^}
|dkr�|d7}|
j|kr�||j
|
j|
j|
j||
jd�7}q�||j
|
j|
j|
jdd�7}q�|j�||�WY�d
Sd}	~	XYnXdS)z: this checks if we have enough free space on /var and /usrzNot enough free disk spacez�The upgrade has aborted. The upgrade needs a total of {str_total} free space on disk '{str_dir}'. Please free at least an additional {str_needed} of disk space on '{str_dir}'. {str_remedy}zIRemove temporary packages of former installations using 'sudo apt clean'.z�You can remove old kernels using 'sudo apt autoremove' and you could also set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs.zbEmpty your trash and remove temporary packages of former installations using 'sudo apt-get clean'.z!Reboot to clean up files in /tmp.r?Z	FreeSpaceZ	SkipCheckFz,free space check skipped via config overrideT�Dir::Cache::archivesz/varz/boot�/z/tmpz/usrr�)Z	str_totalZstr_dirZ
str_neededZ
str_remedyN)rMrRr�rHr�� _is_apt_btrfs_snapshot_supportedrNZcheckFreeSpacer r\r�Zfree_space_required_list�dir�formatZ
size_totalZsize_neededrKrv)riZerr_sum�err_msgZremedy_archivedirZremedy_bootZremedy_rootZ
remedy_tmpZ
remedy_usrZwith_snapshotsr|�
archivedirZerr_longZremedyZreqr(r(r)�_checkFreeSpacesV
�

�
�
z%DistUpgradeController._checkFreeSpacecCs�|j�td��|j�|j|j|j�s*dS|jrB|j�|j�sBdS|j�	�}|j�
�|��|j�
�|��stdS|�
�s�dS|j�
�|j��|_t|j�dkr�|j��t�dd�dd�|jD���t�d|j�|j�
�|S)	N�Calculating the changesFrz
demoted: '%s'r�cSsg|]
}|j�qSr(�r�r�r(r(r)r>wsz9DistUpgradeController.calcDistUpgrade.<locals>.<listcomp>zfound components: %s)rKrLrMrNZdistUpgrader�r]ZinstallTasksr�get_changesrsr�rrZget_installed_demoted_packages�installed_demotionsr&�sortrHrIrCr�)ri�changesr(r(r)�calcDistUpgradeXs,




 
z%DistUpgradeController.calcDistUpgradecCs0|��}|sdS|j�td�||j|jj�}|S)NFz!Do you want to start the upgrade?)r!rK�confirmChangesrMrrNZrequired_download)rir r�r(r(r)�askDistUpgrade~s�z$DistUpgradeController.askDistUpgradecCs t��}|�|j�otj�d�S)Nz2/var/snap/canonical-livepatch/common/machine-token)�distro_info�UbuntuDistroInfo�is_ltsrWr@rB�isfile)ri�dir(r(r)�_isLivepatchEnabled�sz)DistUpgradeController._isLivepatchEnabledcsZt��}���r|��j�r dSt�fdd�|�d�D��j�}�j�dt	d�|�}|S)NTc3s |]}|j�jkr|jVqdSr
)ZseriesrX�version)r=�rr�r(r)r��sz5DistUpgradeController.askLivepatch.<locals>.<genexpr>�objectzdLivepatch security updates are not available for Ubuntu %s. If you upgrade, Livepatch will turn off.)
r$r%r)r&rX�nextZget_allrKZaskCancelContinueQuestionrM)rir(r*r�r(r�r)�askLivepatch�s ��z"DistUpgradeController.askLivepatchcCs0tj�d�r,t�dt|j��t�dd�dS)N�/etc/cron.daily/aptzdisabling apt cron job (%s)i�)r@rBr�rHrI�octrf�chmodr�r(r(r)�_disableAptCronJob�sz(DistUpgradeController._disableAptCronJobcCs(tj�d�r$t�d�t�d|j�dS)Nr/zenabling apt cron job)r@rBr�rHrIr1rfr�r(r(r)�_enableAptCronJob�s
z'DistUpgradeController._enableAptCronJobc

Cs�|��d}|j��}|j�ddd�}|rxzt��d�d�d}Wnt�	d�d}YnX|j�
��d||f�|j�dd	�}d
}d}||k�rXz.t
�|jj�}t
�|�|_|j�|j|�Wn�tjjk
�r
}	z t�d�d}|	}WY��qXW5d}	~	XYnJtk
�rR}	z*t�d
|	|f�|d7}|	}WY�q�W5d}	~	XYnXdS|�rv|j�td�td��n&t�d�|j�td�td�d|�|��|��dS)Nrr;ZSlideshowUrlrM�getdefaultlocaleZenz%s#locale=%sr8r9Fz
user canceledT�:IOError in cache.commit(): '%s'. Retrying (currentTry: %s)rzUpgrade canceledzwThe upgrade will cancel now and the original system state will be restored. You can resume the upgrade at a later time.�+giving up on fetching after maximum retries�Could not download the upgradesz�The upgrade has aborted. Please check your Internet connection or installation media and try again. All files downloaded so far have been kept.r�)r2rKr�rRr��localer4rrHr�ZgetHtmlViewr�r_r\ZPackageManagerrN�	_depcacheZAcquirerOZ_fetch_archives�aptZFetchCancelledExceptionr�rrvr�rMr3rw)
rir�	fprogressZurlZlangrkZ
user_canceledr�Zpmr|r(r(r)�doDistUpgradeFetching�sR




�
�z+DistUpgradeController.doDistUpgradeFetchingcCsdzddl}Wntk
r"YdSXz|��}|��}Wnt�d�YdSXt�d|�|S)z' check if apt-btrfs-snapshot is usable rNzfailed to check btrfs supportFz!apt btrfs snapshots supported: %s)�apt_btrfs_snapshot�ImportError�AptBtrfsSnapshotZsnapshots_supportedrHr�rI)rir=�	apt_btrfsr�r(r(r)r�s
z6DistUpgradeController._is_apt_btrfs_snapshot_supportedcCsF|��sdSddl}|��}d|j}|�|�}t�d||f�dS)z2 create btrfs snapshot (if btrfs layout is there) Nrzrelease-upgrade-%s-z#creating snapshot '%s' (success=%s))rr=r?rXZcreate_btrfs_root_snapshotrHr�)rir=r@�prefixr�r(r(r)� _maybe_create_apt_btrfs_snapshots

z6DistUpgradeController._maybe_create_apt_btrfs_snapshotcCs�i}tjdg|d<dtjd<dD]$}tj�|�||d<tj�|�q"z|��W�S|D] }||D]}tj�||�qfqZXdS)Nzdir::bin::dpkgz	/bin/true)zdpkg::pre-invokezdpkg::pre-install-pkgszdpkg::post-invokezdpkg::post-install-pkgsz::)r\rRZ
value_list�clearrT�
doDistUpgrade)riZbackupsZlst�itemr(r(r)�doDistUpgradeSimulation
s
z-DistUpgradeController.doDistUpgradeSimulationc
Cs�d}|j��}|j�|j�}|j�dd�}|jsD|j�d�|�	�d}d}||k�r�z"|j�
||�}t�d|�W�n(t
k
�r�}�z<t�d|�|}tj�d��rHtd��}|��}W5QRXt�d	|�d
dg}	|	D]b}
t|��|
�r�t�d�|��td
�}|dt|�7}|td�7}|j�td�|�|��q�td�}|j�spt��sp|td|�7}|j�td�|�dddg}tj�d�dk�r�|�d�|j���|�|��WY�dSd}~XYn�tk
�r}z*t�d||f�|d7}|}WY�qLW5d}~XYn�t k
�r�}zdt�!d�|}|j"dk�r�|��td
�}|dt|�7}|td�7}|j�td�|�|��W5d}~XYnX|��dSt�d�|j�td�td �d!|�|��dS)"Nrr8r9ZStartUpgradeFzcache.commit() returned %sz#SystemError from cache.commit(): %sz./var/run/ubuntu-release-upgrader-apt-exceptionzfound exception: '%s'z;E:Internal Error, Could not perform immediate configurationz E:Couldn't configure pre-depend z-detected preconfigure error, restorting state�Error during commitz
'%s'
�Restoring original system statezCould not install the upgradeszrThe upgrade has aborted. Your system could be in an unusable state. A recovery will run now (dpkg --configure -a).z�

Please report this bug in a browser at http://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+filebug and attach the files in /var/log/dist-upgrade/ to the bug report.
%sr~rr�r�r�r�r5rzcache.commit()�Tr6r7zdThe upgrade has aborted. Please check your Internet connection or installation media and try again. r�)#rKr��getInstallProgressrNrRr_r]r^rorB�commitrHrIr�rvr@rBr�r��readrUr�r3rMrwr!r[rr�r�r�rr�r��errno)
rirr;�	iprogressrkr�r�r|r�Zpre_configure_errorsZ
preconf_error�msgr�r(r(r)rDs�


�

�



�z#DistUpgradeController.doDistUpgradec
Cs�t��d�tj�tj�d��}|jj	D]D}tj�tj�
|j��|kr(zt�|j�Wq(t
k
rjYq(Xq(|��|j�d�|j�tj�|j�td��|j��}|j�|j|j|j�}t�dd�t |���t�dd�t |���|j�!dd	�D]&}||kr�t�"d
|�t#�}�q&q�|j�$ddd��sFt�d
�dS|j�!dd�D]6}||jk�rT|j|j%�rT|j&�'|j�!|d���qTt�d|j&�|j(�r�||j)}nt#dd�|j*D��}|t#|j&�O}|j�+�}t�dd�|��|t#|�O}|j�$ddd��st�d�t#�}t�d|�t�d�|j�,�}t-|�D]^\}	}
|�.|	t/t0|��d�|
|j1k�rH|j�2�|j�3|
||j&|j1��sHt�d|
��qHt�d�|�4�|j�5�}t�dd�dd�|D���td�}td�td�g}
t0|�dk�r�|j�6||gd|
d ��r�|j�7�}|j�8|j�}z|j�9||�WnRt:t;fk
�r�}z.t�"d!|�|j�"td"�td#�d$|�W5d}~XYnX|j�d%�|j<�s�|�=�dS)&NZPOSTUPGRADErZPostUpgradezSearching for obsolete softwarerr�r�r;r�zXthe BaseMetaPkg '%s' is in the obsolete list, something is wrong, ignoring the obsoletesZRemoveObsoletesTzSkipping obsolete Removalr�r<zforced_obsoletes: %scSsg|]
}|j�qSr(r)r=�pr(r(r)r>�sz7DistUpgradeController.doPostUpgrade.<locals>.<listcomp>zUnused dependencies: %sz0Skipping RemoveObsoletes as stated in the configzremove_candidates: '%s'z Start checking for obsolete pkgsgY@z:'%s' scheduled for remove but not safe to remove, skippingz!Finish checking for obsolete pkgsz1The following packages are marked for removal: %scSsg|]
}|j�qSr(r)r=r�r(r(r)r>�szRemove obsolete packages?Z_KeepZ_RemoverFz,cache.commit() in doPostUpgrade() failed: %srGz[A problem occurred during the clean-up. Please see the below message for more information. r�ZPostCleanup)>r�Z	add_stager@rBr�r\rRr�rOre�abspathZdestfile�unlinkr�r}r^rorK�setSteprZCLEANUPrLrMrNrrrYrWrXrHrIrCr�r`rvrTr�r�rar�rPrrZ_getUnusedDependenciesr��	enumerater�floatr&rrsZtryMarkObsoleteForRemoval�donerr"r�rJrKr�rr]�runPostInstallScripts)rirrEZnow_obsoleteZnow_foreignr�Zremove_candidatesZunused_dependenciesr��ir�r r�Zactionsr;rNr|r(r(r)�
doPostUpgrade�s�
�








�
�z#DistUpgradeController.doPostUpgradecCs�|jr|j��|j��|j�dd�D]�}tj�|�sHt�	d|�q(t�
d|�z"t|�|j�
�j|gdd�Wq(tk
r�}zt�d||f�W5d}~XYq(Xq(|jr�|j��dS)	z� 
        scripts that are run in any case after the distupgrade finished 
        whether or not it was successful

        Cache lock is released during script runs in the event that the
        PostInstallScripts require apt or dpkg changes.
        r;ZPostInstallScriptsz!PostInstallScript: '%s' not foundzRunning PostInstallScript: '%s'T)Zhiddenz(got error from PostInstallScript %s (%s)N)rNrprqrRr`r@rBr�rHr�rIrrKr�r��	Exceptionrv�get_lock)riZscriptr|r(r(r)rW�s

&z+DistUpgradeController.runPostInstallScriptscCsjt�d�t|d�r"|j�|j�t|d�r:|j�|j�|j�t	d��|j�
�|��t�
d�dS)z2 abort the upgrade, cleanup (as much as possible) zabort calledr�rQrHrN)rHrI�hasattrr�Zrestore_backuprSrQrKrLrMrwr}rxryr�r(r(r)rws



zDistUpgradeController.abortc	Cs�t�|�D]�}t�d|�|D]v}|d}|d}|d}||jkr\t�d|�dS|j|}t|jdd�}|dkr t�|||�d	kr d	Sq q
t�d
|�dS)z+ check if a given depends can be satisfied zchecking: '%s' rr�z_checkDep: '%s' not in cacheFr*NTzdepends '%s' is not satisfied)	r\Z
parse_dependsrHrIrNrv�getattrZ	installedZ	check_dep)	riZdepstrZor_group�depZdepname�verZoperr�Zinstverr(r(r)�	_checkDeps"

�zDistUpgradeController._checkDepcCs�t�d�d}|j�dd�}|�|j�|jjjd��|D]F}t�d|�||�|�M}|s:|j�	t
d�t
d|��t�d�q:|S)	z  check if depends are satisfied zcheckViewDepends()Tr�ZDependsz
depends: '%s'z!Required depends is not installedz/The required dependency '%s' is not installed. r)
rHrIrRr`r�rKrJr,rarvrMrxry)rir�Zdependsr_r(r(r)r�'s"
���z&DistUpgradeController.checkViewDependscCs�|j�dd�}d}tj�dd�}|j�dd�}||kr�|jdd	�|��|D]$}||jkrNt�	d
|�t
|��qN|�|�r�q�t�d�tj�
dd�|d
7}q.||kr�t�	d�dStj�
d|�dS)N�PreRequists�PackagesrzAcquire::http::No-Cacher:r8r9F)r	zCan not find backport '%s'z>setting a cache control header to turn off caching temporarily�truerz+pre-requists item is NOT trusted, giving upT)rRr`r\�findr_rr}rNrHrvr+�_allBackportsAuthenticatedrIrT)ri�
backportslistrXZnoCacherkr�r(r(r)�_verifyBackports;s*





z&DistUpgradeController._verifyBackportscCs�tj�dd�dkr t�d�dSz|j�dd�}|r:WdSWntk
rPYnX|D]8}|j|}|jspdS|jj	D]}|j
rxqVqxdSqVdS)NzAPT::Get::AllowUnauthenticatedFTzIskip authentication check because of APT::Get::AllowUnauthenticated==truer;ZAllowUnauthenticated)r\rRZfind_brHr�Z
getbooleanrrNr�r�Ztrusted)rirgrr�r�Zcandr(r(r)rfVs$


z0DistUpgradeController._allBackportsAuthenticatedc
Cs�|�d�}t|�\}}}}}d|kr2|�d�d}d|||f}|jD]J}|�d�}t||�rddS|�d�d}	|�|	�rFt�d|�dSqFdS)	z  check if uri is a known mirror r�@rz	%s://%s%sTz//z)found apt-cacher/apt-torrent style uri %sF)�rstriprrrbr�endswithrHrI)
rir�Zraw_uriZschemeZnetlocrBZqueryZfragment�mirrorZmirror_host_partr(r(r)r�ls




zDistUpgradeController.isMirrorcCs4|�d�}|jD]}|�d�}t||�rdSqdS)z2 check if uri is a whitelisted third-party mirror rTF)rjrcr)rir�rlr(r(r)r��s



z(DistUpgradeController.isThirdPartyMirrorcCs�d}tdd�}|jD]�}|js|jr&q|jdkr|jdkr|�|j�rd|jkrd|j|j	kr|j�
d�s|j�
d	�sd
|j|jf}||kr||7}q|S)z7 get sources.list snippet lines for the current mirror r?r0r�r�Fr"r�zhttp://security.ubuntu.comzhttp://archive.ubuntu.comzdeb %s %s-updates main
)rr�r�r�r�r�r�r�rWr�r�)ri�dumb�linesr�r�Znew_liner(r(r)�_getPreReqMirrorLines�s,


�
���
�
�
z+DistUpgradeController._getPreReqMirrorLinesc	
Cs|t�d|�|�|�}t|d��P}t|��<}|D]0}t|�}|j|d�}|�|�t�d|�q2W5QRXW5QRXdS)z9 add prerequists based on template into the path outfile z*writing prerequists sources.list at: '%s' �w)rlzadding '%s' prerequistsT)rHrIror�rZsafe_substitute�write)	ri�template�outrmZmirrorlines�outfileZinfiler�Zoutliner(r(r)�_addPreRequistsSourcesList�s

$z0DistUpgradeController._addPreRequistsSourcesListc
Cs&t�d�d}tj�t��d�}tj�|�s6t�|�|j�	dd�}|j
�r�|j�s�t�d�tj�|j
jdt
j�d��}t�}t�|d	�D]2}t�d
||f�|�tj�|��d�d�q�t|��|�s�t�d
t|�|f�dS|j��tjddgt�|d	�tjtjdd�}d}|dk�rL|��}|j��t� d��q"|jjdd�|j�!�t�"d|�t�d|�#�d�|dk�r�dS|�$�Sd}|j�%d|d|j&��r�|d|j&}|j�'d|�}tj�|��s�t�d|�dStj�t
j�(d�|�}	tj�t
j�(d�|�}
|�)||
�z|�*�Wnht+k
�r�|j)||
dd�z|�*�Wn2t+k
�r�}zt�,d|�W5d}~XYnXYdSX|D]�}|j|}
|jj-�.|
j/�}|�s�t�d|�t�0|	�dS|j1dk�rt�d|�t�0|	�dSt�d|�|
j2ddd ��q�d}z"|j�3|j�4�|j�5|j��}Wnjt6k
�r�}zt�d!|�d}W5d}~XYn6t7k
�r�}zt�d"|�d}W5d}~XYnX|dk�r�t�,d#�zt�0|
�Wn2t8k
�r}zt�d$|�W5d}~XYnX|�$�S)%z5 download the backports specified in DistUpgrade.cfg zgetRequiredBackports()TZ	backportsrbrcz#Searching for pre-requists on CDROMz*dists/stable/main/dist-upgrader/binary-%s/zAPT::Architecturez*_*.debzfound pre-req '%s' to '%s'rMrz%Expected backports: '%s' but got '%s'Fr~z-i)r��stderrr�Ng{�G�z�?)Zfinishedz'installing backport debs exit code '%s'zdpkg output:
%srz-%szsourceslist not found '%s'zDir::Etc::sourceparts)rmzno backport for '%s' foundzNo candidate for '%s'zNo ver.file_list for '%s'zmarking '%s' for install)Z	auto_instZauto_fixzfetch_archives returned '%s'zinstall_archives returned '%s'z,_fetch_archives for backports returned Falsez(failed to unlink pre-requists file: '%s')9rHrIr@rBrCrAr��mkdirrRr`rQrPrjr\rerTr�r��basenamer�issubsetrvrNrpr�r�r�ZSTDOUTZpollrKZ
pulseProgressrtrur[r�r��setupRequiredBackportsZ
has_optionrZrr�rurhr+r�r9Zget_candidate_verZ_pkgrRZ	file_list�mark_installrKr�rJrr�rZ)rir�r�rgrPZ
found_pkgsr�Zconf_optionZprereq_templateZoutpathrtr|r�r�r`r(r(r)�getRequiredBackports�s�


�
�



 


�

 z*DistUpgradeController.getRequiredBackportscCsxdtjd<t��t�dd�tjdg}|jr<|�	d�n
|�	d�t�
d�ttjd	�t�tjd	|tj�dS)
Nz$/usr/lib/release-upgrader-python-apt�
PYTHONPATHz/var/log/dist-upgrade/main.logz&/var/log/dist-upgrade/main_pre_req.logz--have-prerequistsz--with-networkz--without-networkzrestarting upgraderr)
r@r[rHZshutdown�shutilr�rx�argvrPr�r�r�execve)ri�argsr(r(r)rz*s
�

z,DistUpgradeController.setupRequiredBackportsc
Csb|j�td��|j�tj�|��s�t�d�t	j
�d�rb|j�td�td��t�
ddg�n |j�td�td��t�d	�|��|j�d
��r|j�r|jjdk�rt�d�|���st	j
�d�r�|j�td
�td��t�
ddg�n |j�td
�td��t�d	�|��|���s.|��|jddd�|��|���sV|���z�|j�tj�|j�td��|���s�|��|j�r�|j�|j��s�|j�td�td��|��|���s�|��|j�td��|jdd�|j��|_ |j!�"�|j�#dd�D]�}||jk�s6|j�$|j|��st�d|�||jk�r^t�d|�|j�$|j|��s�t�d|�|j�td�td�|�t	j
�d��r�t�
ddg�n
t�d	�|���q|j�td��|�%��s�|��|�&�|j�tj'�|j�td��|�(��s0|�)�|��|j�tj*�|j�td ��|�+��sv|j�td!�td"��|��|j�,�d}z|jd#�-�d}Wn<t.k
�r�}zd$t/|�k�r�t�d%�W5d}~XYnXWnt0k
�r�|��YnX|�rH|j�tj*�|j�td ��|�1��sH|j�2td&�td'��t3�4d�|jdd�|j��|_ |j!�"�|j�td��|�5��s�|��|j�tj*�|j�td ��|�1��s�|�6�|j�2td(�td)��t3�4d�|�7�|j�r�|j�8�t	j
�d*��rt	�9d*�|j�tj:�|j�td+��t;��<�t=��s^|j�>��r^t�
d,�t3�4d-�dS).NzChecking package managerzself.prepare() failedr�zPreparing the upgrade failedzXPreparing the system for the upgrade failed so a bug reporting process is being started.r�r�z�Preparing the system for the upgrade failed. To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.r�rbFzneed backportsz$Getting upgrade prerequisites failedz�The system was unable to get the prerequisites for the upgrade. The upgrade will abort now and restore the original system state.

Additionally, a bug reporting process is being started.z�The system was unable to get the prerequisites for the upgrade. The upgrade will abort now and restore the original system state.

To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.r)r	r
zUpdating repository informationzFailed to add the cdromz+Sorry, adding the cdrom was not successful.T)r{r;r�z@No '%s' available/downloadable after sources.list rewrite+updatez'%s' was not in the cachez'%s' was not downloadablezInvalid package informationa�After updating your package information, the essential package '%s' could not be located. This may be because you have no official mirrors listed in your software sources, or because of excessive load on the mirror you are using. See /etc/apt/sources.list for the current list of configured software sources.
In the case of an overloaded mirror, you may want to try the upgrade again later.r�Fetching�	UpgradingzUpgrade infeasiblezQThe upgrade could not be completed, there were errors during the upgrade process.Zlibc6ZpkgProblemResolverz'Unable to mark libc6 alone for install.zUpgrade incompletezUThe upgrade has partially completed but there were errors during the upgrade process.�Upgrade complete�KThe upgrade has completed but there were errors during the upgrade process.z:/var/lib/ubuntu-release-upgrader/release-upgrade-availablezSystem upgrade is complete.�/sbin/rebootr)?rKrLrMrSr�PREPAREr�rHrvr@rBr�r�r�rwrRrdrEr�rIr|r.rr}r��MODIFY_SOURCESr�rQr�rSrNr�r�r^Z+ensure_recommends_are_installed_on_desktopsr`ZanyVersionDownloadabler#�_inhibitIdle�FETCHr<r3�INSTALLrFrCr{r�rU�KeyboardInterruptrDr�rxryr!rWrYZcomment_out_cdrom_entryrR�REBOOTr�rVr�confirmRestart)rir�Zlibc6_possibler|r(r(r)�fullUpgrade?s
��
�
�

��	



��

���



�


�



�



�

z!DistUpgradeController.fullUpgradecCs|j��|��Sr
)rKrsr�r�r(r(r)ro*s
zDistUpgradeController.runcCs|j�tj�|j�tj�|j�tj�d|_|��|�	�sDdS|�
�sPdS|j�tj�|j�t
d��|��szdS|j�tj�|j�t
d��|��s�|j�t
d�t
d��dS|��s�|j�t
d�t
d��dStj�t�r�|j��r�t�d�n|j�t
d�t
d��dS)	z, partial upgrade mode, useful for repairing TFr�r�r�r�r�z"The partial upgrade was completed.)rKrSrr�ZhideStepr�r�r]r�r�r#r�rLrMr<r�rDr�rYr@rBr��REBOOT_REQUIRED_FILEr�r�r�r�r(r(r)�doPartialUpgrade.s@��
�z&DistUpgradeController.doPartialUpgradec	Cstj�d��rtj�dd�|_|js4tj�dd�|_|jsRt�d�t�d�dS|�	�|j
sddSt�t|j��t�d�zb|j
�dd�}|s�t�d	�t�d�WdSt
jd
ddd
g|j
t
jd�|j�td�td��Wn$ttfk
�rt�d�YnXt�t���dS)Nz/usr/bin/gnome-session-inhibitZSUDO_UIDr?Z
PKEXEC_UIDz"failed to determine user upgradingz$failed to inhibit gnome-session idlezinhibit gnome-session idleZXDG_CURRENT_DESKTOPz"failed to find XDG_CURRENT_DESKTOPzgnome-session-inhibitz	--inhibitZidlez--inhibit-only)�envr�zLock screen disabledzMYour lock screen has been disabled and will remain disabled until you reboot.)r@rBr�r[rrgrHrIrv�_getUserEnvrh�seteuid�intr�r�ZDEVNULLrKr�rMr�r%r��getuid)riZxdg_desktopr(r(r)r�Us@




���z"DistUpgradeController._inhibitIdlec
Cs�z�t�dd|jdg�}|���d�d}td|dd��}|���d	�}W5QRX|D]*}t|�rX|�d
d�}|d|j|d<qXWnDtj	k
r�}z$|j
dkr�t�d�n
t�
d
�W5d}~XYnXdS)NZpgrepz-uz
gnome-session�
rz/proc/z/environr+��=rz"gnome-session not running for userzfailed to read user env)r�Zcheck_outputrg�decoderr�rLr&rhZCalledProcessError�
returncoderHrIr�)ri�pidr��datar�r�r|r(r(r)r�ws�
z!DistUpgradeController._getUserEnv)NN)TF)T)TN)F)F)1r,r-r.�__doc__rlr}rrr�r�r�r�r�r�r�r�r�r�rrrr!r#r)r.r2r3r<rrBrFrDrYrWrwrar�rhrfr�r�rorur|rzr�ror�r�r�r(r(r(r)r/^sb
h
#;`
+e3
$/:&
J
fm
	

zl'"r/�__main__)�DistUpgradeViewText)�level)Kr:r\r$rxr@r�r8rHr~r�rtr��configparserrrr�Z	telemetryrr�Zutilsrrrr	r
rrr
r�stringrZurllib.parserZDistUpgradeViewrZDistUpgradeCacherZDistUpgradeConfigParserrrZDistUpgradeAptCdromrZ
aptsourcesrrZDistInfoZaptsources.sourceslistrrr�rrZDistUpgradeGettextrrMrrrr ZDistUpgradeApportr!r�r*rZr+r,r/r,r�ZbasicConfig�DEBUG�vZdcr2r3r(r(r(r)�<module>sv,	<