3 ÅÀf©hã@sädZddlmZmZmZmZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZddlZddlZddlmZddlmZddlZddlmZmZddlZed ƒe jd ƒZe jd ƒZe jd ƒZe jd ƒ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;ƒZdS)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Úfprrrr=†s   z State._readc CsFtjjtjj|jƒƒt|jdƒ�}tj |j |ddd�WdQRXdS)NÚwéT)ÚindentÚ sort_keys) r$r%Ú ensure_dirrrÚdirnamer;rr@Údumpr<)r>Zoutfrrrr5‘sz State.writecCs&tjj|jƒrtj|jƒ|jƒdS)N)rrÚexistsr;r&r=)r>rrrÚclear–s z State.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..setpropcs |jjˆƒS)N)r<Úget)r>)rTrrÚgetprop§szState._prop..getprop)Úproperty)rTrUrWr)rTrÚ_prop£s  z State._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__c Gsj||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-upgradez change-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|d krpttd ƒƒ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™c CsZtt|ƒƒ}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 d d „Z d 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 �|jd ttd ƒd �dS)Nz--no-downgraderdZ store_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“Z DNF_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 j j 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 j jdg7_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ÚoutputZ userconfirmÚ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 j j 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ú Gsz5SystemUpgradeCommand.run_download..cs$g|]}ˆjjjj|jƒr|j‘qSr)r©rÿÚenvrVrÙ)rr)r>rrrJsZ downloading)rýrþ)rÌrdr©Z upgrade_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..cSsg|]}|jr|j‘qSr)rîrÙ)rrØrrrr¤s)rÎzDownload finished.)/r©rÿZ get_currentZpackagesrrrr rr²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ƒ|jjddkrrrrÚ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ürr r 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_srr r Z libdnf.confrÔZUUIDrrûr rr–ror/rr0rÏrr r*r3r9Úobjectr:rjr…r„ZTransactionProgressr~r‘r™rœr¡r¾ZPluginr¤rªZCommandr¦r§r¨rrrrÚsd          @.  e