Viewing File: /lib/python3.6/site-packages/dnf-plugins/__pycache__/system_upgrade.cpython-36.pyc

3

�f�h�@s�dZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZddlZddlZddlmZddlmZddlZddlmZmZddlZed	�ejd
�Zejd�Zejd�Zejd
�Z eZ!dZ"ed�Z#ed�Z$ed�Z%dZ&dd�Z'dd�Z(gfdd�Z)d7dd�Z*dd�Z+Gdd�de,�Z-Gdd �d e,�Z.e.�Z/Gd!d"�d"ej0j1�Z2d#d$�Z3d%d&�Z4d'd(�Z5d)d*�Z6d+d,dd-d.gZ7Gd/d0�d0ej8�Z9Gd1d2�d2ej:j;�Z<Gd3d4�d4e<�Z=Gd5d6�d6e<�Z>dS)8zGsystem_upgrade.py - DNF plugin to handle major-version system upgrades.�)�call�Popen�check_output�CalledProcessErrorN)�journal)�_�logger)�CliError)�ucd)�serialize_transaction�TransactionReplayzthe color of the skyZ 9348174c5cc74001a71ef26bd79d302eZ fef1cc509d5047268b83a3a553f54b43Z 3e0a5636d16b4ca4bbe5321d06c6aa62Z 8cec00a1566f4d3594f116450395f06cz/usr/bin/plymouthz<Need a --releasever greater than the current system version.z�Download complete! Use 'dnf {command} reboot' to start the upgrade.
To remove cached metadata and transaction use 'dnf {command} clean'zESorry, you need to use 'download --releasever' instead of '--network'�cCs.tjddd�rtjtd��ntddg�dS)NZDNF_SYSTEM_UPGRADE_NO_REBOOTF)�defaultz!Reboot turned off, not rebooting.Z	systemctl�reboot)�os�getenvr�inforr�rr�$/usr/lib/python3.6/system_upgrade.pyrEsrcCs|d}xrdD]j}yNt|��<}x4|D],}|j�}|j|�r |t|�d�jd�Sq WWdQRXWq
tk
rrw
Yq
Xq
WdS)NzUPGRADE_GUIDE_URL=�/etc/os-release�/usr/lib/os-release�")rr)�open�strip�
startswith�len�IOError)�key�pathZrelease_file�linerrr�get_url_from_os_releaseLs



(r cCs~tjj|�sdSxhtj|�D]Z}tjj||�}||kr8qy(tjj|�rTtjj|�n
tj|�Wqt	k
rtYqXqWdS)N)
rr�isdir�listdir�join�dnf�utilZrm_rf�unlink�OSError)r�ignore�entryZfullpathrrr�	clear_dir[sr*cCs6tjj|j�|jkrtt��|r2||jkr2tt��dS)N)r$�rpm�detect_releasever�installroot�
releaseverr	�RELEASEVER_MSG�CANT_RESET_RELEASEVER)�conf�targetrrr�check_release_verlsr3cCsPytdd�}|jd�Wn2tk
rJ}zttd�|�WYdd}~XnXdS)Nz	/dev/tty0�wbs[9;0]z%Screen blanking can't be disabled: %s)r�write�	Exception�printr)Ztty�errr�disable_blankingus

r9c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e	d�Z
e	d�Ze	d�Ze	d�Z
e	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�Ze	d�ZdS)�StatecCs||_i|_|j�dS)N)�	statefile�_data�_read)�selfr;rrr�__init__�szState.__init__cCspy&t|j��}tj|�|_WdQRXWnDtk
r@i|_Yn,tk
rji|_tjt	d�|j�YnXdS)Nz;Failed loading state file: %s, continuing with empty state.)
rr;�json�loadr<r�
ValueErrorr�warningr)r>�fprrrr=�s

zState._readc
CsFtjjtjj|j��t|jd��}tj	|j
|ddd�WdQRXdS)N�w�T)�indent�	sort_keys)r$r%�
ensure_dirrr�dirnamer;rr@�dumpr<)r>Zoutfrrrr5�szState.writecCs&tjj|j�rtj|j�|j�dS)N)rr�existsr;r&r=)r>rrr�clear�szState.clearcCs|S)Nr)r>rrr�	__enter__�szState.__enter__cCs|dkr|j�dS)N)r5)r>�exc_type�	exc_value�	tracebackrrr�__exit__�szState.__exit__cs"�fdd�}�fdd�}t||�S)Ncs||j�<dS)N)r<)r>�value)�optionrr�setprop�szState._prop.<locals>.setpropcs|jj��S)N)r<�get)r>)rTrr�getprop�szState._prop.<locals>.getprop)�property)rTrUrWr)rTr�_prop�szState._prop�
state_version�download_status�destdir�target_releasever�system_releasever�gpgcheck�gpgcheck_repos�repo_gpgcheck_repos�upgrade_status�upgrade_command�distro_sync�enable_disable_repos�module_platform_idN)�__name__�
__module__�__qualname__r?r=r5rMrNrRrYrZr[r\r]r^r_r`rarbrcrdrerfrrrrr:�s(
r:c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�PlymouthOutputz�A plymouth output helper class.

    Filters duplicate calls, and stops calling the plymouth binary if we
    fail to contact it.
    cCsd|_t�|_d|_dS)NT)�alive�dict�
_last_args�	_last_msg)r>rrrr?�szPlymouthOutput.__init__cGsj||jj|�k}|jr|s$|dkrdytt|f|�dk|_Wntk
rXd|_YnX||j|<|jS)Nz--pingrF)rmrVrkr�PLYMOUTHr')r>�cmd�argsZdupe_cmdrrr�	_plymouth�s
zPlymouthOutput._plymouthcCs
|jd�S)Nz--ping)rr)r>rrr�ping�szPlymouthOutput.pingcCs4|jr |j|kr |jdd|j�||_|jdd|�S)Nzhide-messagez--textzdisplay-message)rnrr)r>�msgrrr�message�szPlymouthOutput.messagecCsRd}y$ttdg�}tjdt|��r&d}Wnttfk
r@YnX|jdd|�S)NZupdatesz--helpz--system-upgradezsystem-upgradezchange-modez--)rro�re�searchr
rr'rr)r>�mode�srrr�set_mode�szPlymouthOutput.set_modecCs|jddt|��S)Nz
system-updatez
--progress)rr�str)r>Zpercentrrr�progress�szPlymouthOutput.progressN)
rgrhri�__doc__r?rrrsrurzr|rrrrrj�s

rjc@s$eZdZdd�Zdd�Zdd�ZdS)�PlymouthTransactionProgresscCs|j||||�dS)N)�_update_plymouth)r>�package�actionZti_doneZti_totalZts_doneZts_totalrrrr|�sz$PlymouthTransactionProgress.progresscCsd|dkrdS|tjjkr0tjtd||��ntjdtd||��tj|j||||��dS)N�g�V@�Zg$@)r$�callbackZ
PKG_VERIFY�Plymouthr|�intru�
_fmt_event)r>r�r��current�totalrrrr�sz,PlymouthTransactionProgress._update_plymouthcCs tjjj||�}d||||fS)Nz[%d/%d] %s %s...)r$�transactionZACTIONSrV)r>r�r�r�r�rrrr�sz&PlymouthTransactionProgress._fmt_eventN)rgrhrir|rr�rrrrr~�sr~ccsJtj�}|j|jdd�d}x(|D] }|d}||kr8q"|}|Vq"WdS)zVFind all boots with this message id.

    Returns the entries of all found boots.
    r)�
MESSAGE_IDZ_UIDN�_BOOT_ID)r�ReaderZ	add_match�hex)�
message_id�jZoldbootr)Zbootrrr�
find_bootss
r�c
Cstttd��d
}xJttt��D]:\}}tdj|d|d|d|jdd�|jdd���qW|dkrpttd	��dS)Nz3The following boots appear to contain upgrade logs:r�u){} / {.hex}: {:%Y-%m-%d %H:%M:%S} {}→{}r�Z__REALTIME_TIMESTAMP�SYSTEM_RELEASEVERz??�TARGET_RELEASEVERz-- no logs were found --���r�)r7r�	enumerater��ID_TO_IDENTIFY_BOOTS�formatrV)�nr)rrr�	list_logs s
r�cCsZtt|��}y(|dkrt�|dkr*|d8}||dStk
rTttd���YnXdS)Nrr�r�z!Cannot find logs with this index.)�listr��
IndexErrorr	r)r�r�Zbootsrrr�	pick_boot.sr�cCsDtt|�}tdd|jg�}|j�|j}|dkr@tjjt	d���dS)NZ
journalctlz--bootr�z%Unable to match systemd journal entry)
r�r�rr��wait�
returncoder$�
exceptions�Errorr)r�Zboot_idZprocessZrcrrr�show_log=s
r�ZdownloadZclean�upgrade�logcs eZdZdZ�fdd�Z�ZS)�SystemUpgradePluginzsystem-upgradecs8tt|�j||�|r4|jt�|jt�|jt�dS)N)�superr�r?Zregister_command�SystemUpgradeCommand�OfflineUpgradeCommand�OfflineDistrosyncCommand)r>�base�cli)�	__class__rrr?Ns


zSystemUpgradePlugin.__init__)rgrhri�namer?�
__classcell__rr)r�rr�Ksr�cs(eZdZdEZed�ZdZ�fdd�Zedd��Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!d9d:�Z"d;d<�Z#d=d>�Z$d?d@�Z%dAdB�Z&dCdD�Z'�Z(S)Fr��system-upgrade�fedupz+Prepare system for upgrade to a new releasezvar/lib/dnf/system-upgradecsjtt|�j|�tjj|jjj|j	�|_
tjj|j
d�|_tjj|jjjd�|_t
tjj|j
d��|_dS)Nzsystem-upgrade-transaction.jsonz
system-updatezsystem-upgrade-state.json)r�r�r?rrr#r�r1r-�DATADIR�datadir�transaction_file�
magic_symlinkr:�state)r>r�)r�rrr?\s
zSystemUpgradeCommand.__init__cCsJ|jdddtd�d�|jddtdd	jt�d
�|jdttd�d
�dS)Nz--no-downgraderdZstore_falsez=keep installed packages if the new release's version is older)�destr��help�tidr�z[%s]�|)�nargs�choices�metavarz--numberzwhich logs to show)�typer�)�add_argumentr�CMDSr#r�)�parserrrr�
set_argparserds
z"SystemUpgradeCommand.set_argparsercCs(tj||tj|jj|jjtjjd�dS)zLog directly to the journal.)r�ZPRIORITYr�r�ZDNF_VERSIONN)	r�sendZ
LOG_NOTICEr�r^r]r$�const�VERSION)r>rur�rrr�
log_statusnszSystemUpgradeCommand.log_statuscCs|jd�|jd�dS)NZcheck�
pre_configure)�	_call_sub)r>rrrr�ws
z"SystemUpgradeCommand.pre_configurecCs|jd�dS)N�	configure)r�)r>rrrr�{szSystemUpgradeCommand.configurecCs|jd�dS)N�run)r�)r>rrrr�~szSystemUpgradeCommand.runcCs|jd�dS)Nr�)r�)r>rrr�run_transaction�sz$SystemUpgradeCommand.run_transactioncCs|jd�dS)NZresolved)r�)r>rrr�run_resolved�sz!SystemUpgradeCommand.run_resolvedcCs.t||d|jjdd�}t|�r*|�dS)Nrr)�getattr�optsr��callable)r>r�Zsubfuncrrrr��szSystemUpgradeCommand._call_subcCs(|jjtkr$td�j|d�}t|��dS)NzFIncompatible version of data. Rerun 'dnf {command} download [OPTIONS]')�command)r�rZ�
STATE_VERSIONrr�r	)r>r�rtrrr�_check_state_version�sz)SystemUpgradeCommand._check_state_versioncCs*|j|jj_|jjr|jjnd|jj_dS)N)r�r�r1�cachedirr�r\)r>rrr�
_set_cachedir�sz"SystemUpgradeCommand._set_cachedircCs�ttjjtjjg�}ttjj�}i}i}xl|jjjD]^}|j	|krp|j
}|j|j|j
ji�jt|�i�|j	<q6|j	|kr6|j|jt|j
�i�|j	<q6W||fS)z�
        forward = {repoid:{pkg_nevra: {tsi.action: tsi.reason}}
        reverse = {pkg_nevra: {tsi.action: tsi.reason}}
        :return: forward, reverse
        )�setr$r�ZBACKWARD_ACTIONS�libdnfZ!TransactionItemAction_REINSTALLEDZFORWARD_ACTIONSr�r�r��pkg�reason�
setdefault�repo�idr{)r>Zbackward_actionZforward_actionsZforward�reverseZtsir�rrr�%_get_forward_reverse_pkg_reason_pairs�s
&
z:SystemUpgradeCommand._get_forward_reverse_pkg_reason_pairscCsb|j|jj_|jjr|jjnd|jj_d|jjkrJ|jjrJtt	d���nd|jjkr^d|j_dS)Nzoffline-distrosynczFCommand 'offline-distrosync' cannot be used with --no-downgrade optionzoffline-upgradeF)
r�r�r1r�r�r\r�rdr	r)r>rrr�pre_configure_download�sz+SystemUpgradeCommand.pre_configure_downloadcCs|j�dS)N)r�)r>rrr�pre_configure_reboot�sz)SystemUpgradeCommand.pre_configure_rebootcCs.|j�|jjr|jj|j_|jj|jj_dS)N)	r�r�rer��repos_edr]r�r1r.)r>rrr�pre_configure_upgrade�sz*SystemUpgradeCommand.pre_configure_upgradecCs|j�dS)N)r�)r>rrr�pre_configure_clean�sz(SystemUpgradeCommand.pre_configure_cleancCsd|jjksd|jjkr�tjtd��t�}|rLtd�}tj|jt|���|j	j
�r�td�}|j	jjs�|j	j
jdj|�dj|�d�r�tjtd	��tjd
�t|j	j|jjd�nd|jjkr�|jj|j�d
|jj_d
|jj_d
|jj_d
|jj_d
|jj_|j	jjdg7_dS)Nzsystem-upgrader�z\WARNING: this operation is not supported on the RHEL distribution. Proceed at your own risk.z-Additional information for System Upgrade: {}zyBefore you continue ensure that your system is fully upgraded by running "dnf --refresh upgrade". Do you want to continuez
{} [y/N]: z
{} [Y/n]: )rtZdefaultyes_msgzOperation aborted.r�)r2zoffline-upgradeTZtest)r�r�rrCrr rr�r
r�Z
_promptWantedr1Zassumeno�outputZuserconfirm�error�sys�exitr3r.r�Z _populate_update_security_filter�demands�	root_user�	resolving�available_repos�sack_activationZfreshest_metadataZtsflags)r>Zhelp_urlrtrrr�configure_download�s*






z'SystemUpgradeCommand.configure_downloadcCsd|jj_dS)NT)r�r�r�)r>rrr�configure_reboot�sz%SystemUpgradeCommand.configure_rebootcCs�d|jj_d|jj_d|jj_d|jj_|jj|j_|jj	dk	rN|jj	|j
j_	|jjdk	r�x$|j
j
j�D]}|j|jjk|_	qhW|jjdk	r�x$|j
j
j�D]}|j|jjk|_q�W|jj|j
j_d|jj_d|j
j_t�|jj_d|j
j_d|j
j_dS)NTF)r�r�r�r�r�r�r�rdr�r_r�r1r`�repos�valuesr�ra�
repo_gpgcheckrfZ	cacheonlyZ	assumeyesr~Ztransaction_displayZclean_requirements_on_removeZinstall_weak_deps)r>r�rrr�configure_upgrade�s&






z&SystemUpgradeCommand.configure_upgradecCsd|jj_dS)NT)r�r�r�)r>rrr�configure_cleansz$SystemUpgradeCommand.configure_cleancCsdS)Nr)r>rrr�
configure_logsz"SystemUpgradeCommand.configure_logcCs~|jjdksttd���|j|jj�|jj|jjkrRtd�j|jjd�}t|��t	j
j|j�rlttd���t
jj|j�dS)N�completezsystem is not ready for upgradezZthe transaction was not prepared for '{command}'. Rerun 'dnf {command} download [OPTIONS]')r�zupgrade is already scheduled)r�r[r	rr�r�r�rcr�rr�lexistsr�r$r%rIr�)r>rtrrr�check_rebootsz!SystemUpgradeCommand.check_rebootcCs�tjj|j�s$tjtd��td��tj|j�|j	krLtjtd��td��t
jjj
|j�|jj}|sp|jj}|j|�|jjdks�td�j|d�}t|��dS)Nz-trigger file does not exist. exiting quietly.rz1another upgrade tool is running. exiting quietly.�readyz/use 'dnf {command} reboot' to begin the upgrade)r�)rrr�r�rrr�
SystemExit�readlinkr�r$ZyumZmiscZunlink_fr�rcr�r�r�rbr�r	)r>r�rtrrr�
check_upgrades
z"SystemUpgradeCommand.check_upgradec	Cs,tj|j|j�|j�}d|_WdQRXdS)Nr�)r�symlinkr�r�r�rb)r>r�rrr�run_prepare,sz SystemUpgradeCommand.run_preparecCs6|j�|jjddksdS|jtd�t�t�dS)NrrzRebooting to perform upgrade.)r�r�r�r�r�REBOOT_REQUESTED_IDr)r>rrr�
run_reboot3s
zSystemUpgradeCommand.run_rebootc	s��jjr�jj�n
�jj��jjdkr��jj��fdd��jjjD�}|r\�jj|��fdd��jjj	D�}|r��jj|��j
�$}d|_�jjj
|_�jjj|_WdQRXdS)N�offline-upgrade�offline-distrosynccs$g|]}�jjjj|j�r|j�qSr)r��history�grouprVr�)�.0�g)r>rr�
<listcomp>Gsz5SystemUpgradeCommand.run_download.<locals>.<listcomp>cs$g|]}�jjjj|j�r|j�qSr)r�r��envrVr�)rr)r>rrrJsZdownloading)r�r�)r�rdr�Zupgrade_allr�Z
read_comps�comps�groupsZenv_group_upgradeZenvironmentsr�r[r1r.r]r\)r>Zinstalled_groupsZinstalled_environmentsr�r)r>r�run_download=s

z!SystemUpgradeCommand.run_downloadc
Cs�d}|j�}d|_|j}WdQRX|dkr4td�}n|dkrFtd�}ntd�}|j|t�tj�tjd�tj	|�t
�t|j|j
�|_|jj�dS)	N�Z
incompletezoffline-upgradez1Starting offline upgrade. This will take a while.zoffline-distrosyncz4Starting offline distrosync. This will take a while.z0Starting system upgrade. This will take a while.r)r�rbrcrr��UPGRADE_STARTED_IDr�rzr|rur9rr�r��replayr�)r>r�r�rtrrr�run_upgradeSs 



z SystemUpgradeCommand.run_upgradec	Csdtjtd��t|jjjtjj	|jjj�j
g�|j�$}d|_d|_
d|_d|_d|_WdQRXdS)NzCleaning up downloaded data...)rrrr*r�r1r�r$Z	persistorZTempfilePersistorZdb_pathr�r[rZrbrcr\)r>r�rrr�	run_cleanms
zSystemUpgradeCommand.run_cleancCs |jjrt|jj�nt�dS)N)r�Znumberr�r�)r>rrr�run_logzszSystemUpgradeCommand.run_logcCs|jj�dS)z5Adjust transaction reasons according to stored valuesN)r
Zpost_transaction)r>rrr�resolved_upgrade�sz%SystemUpgradeCommand.resolved_upgradecCs�|jjj�}|j�s&tjtd��dSt|�}yLt|j	d��"}t
j||ddd�|jd�WdQRXt
td�j|j	��Wn<tk
r�}z tjjtd�jt|����WYdd}~XnXtjj|jjj�}|j��}d	|_t|_|jj|_|jjj|_d
d�|jjj �D�|_!dd�|jjj �D�|_"||_#|jjj$|_%|jjj&|_&|jj'|_(|jjj)|_)|jj*|_+WdQRXt,j|jj*d
�}tj|�|j-td�t.�dS)NzKThe system-upgrade transaction is empty, your system is already up-to-date.rErFT)rGrH�
zTransaction saved to {}.zError storing transaction: {}r�cSsg|]}|jr|j�qSr)r_r�)rr�rrrr�sz=SystemUpgradeCommand.transaction_download.<locals>.<listcomp>cSsg|]}|jr|j�qSr)r�r�)rr�rrrr�s)r�zDownload finished.)/r�r�Zget_currentZpackagesrrrrrr�r@rKr5r7r�r'r$r�r	r{r+r,r1r-r�r[r�rZr�rdr_r�r�r`rar^r.r]rfr�rer\r�rc�DOWNLOAD_FINISHED_MSGr��DOWNLOAD_FINISHED_ID)r>r��data�fr8Z
system_verr�rtrrr�transaction_download�s:,


z)SystemUpgradeCommand.transaction_downloadcCs@tjtd��|jtd�t�|j�|jjddkr<t�dS)Nz.Upgrade complete! Cleaning up and rebooting...rr�)	r�rurr��UPGRADE_FINISHED_IDrr�r�r)r>rrr�transaction_upgrade�s
z(SystemUpgradeCommand.transaction_upgrade)r�r�))rgrhri�aliasesr�summaryr�r?�staticmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
rrrr�rr)r�rr�VsF
	
 


(r�c@seZdZdZed�ZdS)r��offline-upgradez%Prepare offline upgrade of the systemN)r)rgrhrirrrrrrrr��sr�c@seZdZdZed�ZdS)r��offline-distrosyncz(Prepare offline distrosync of the systemN)r)rgrhrirrrrrrrr��sr�)N)?r}�
subprocessrrrrr@rZos.pathrvr�ZuuidZsystemdrZdnfpluginscorerrr$Zdnf.clir	Zdnf.i18nr
Zdnf.transactionZdnf.transaction_srrrZlibdnf.confr�ZUUIDrr�r	rr�ror/rr0r�rr r*r3r9�objectr:rjr�r�ZTransactionProgressr~r�r�r�r�r�ZPluginr�r�ZCommandr�r�r�rrrr�<module>sd




	@.	e
Back to Directory File Manager
<