a jԽ@sdZddlmZddlmZddlmZzddlmZWneyVddlmZYn0ddlm Z ddl Z ddl m Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZd d lmZdd lmZdd lmZmZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zddl%Zddl&Zddl'Zddl(Zddl)Zddl*Zddl+Zddl,Zddl-Zddl.Zddl/Zddl0Zddl1Zddl2Zddl3Zddl4Zddl5Zddl6Zddl7Zddl8Zddl9Zddl:Zddl;ZddlZddl?Zddl@ZddlAZddlBZddlCZddlDZddlEZddlFZe Gd ZHdddZIddZJddZKddZLGdddejMZNGdddeOZPdS)z/ Command line interface yum class and related. )print_function)absolute_import)unicode_literals)Sequence) defaultdictN)fnmatch)output)CliError)ucd_dnfcCs|t|jdt|jt|}t|j}t|j}d|fd|fd|ffD],\}}|||d|||d7<qJdS)zl Get the length of each pkg's column. Add that to data. This "knows" about simpleList and printVer. rnaverridrN)lennamearchZevrZ _from_repo setdefault)datapkgindentrrrdvr//usr/lib/python3.9/site-packages/dnf/cli/cli.py_add_pkg_simple_list_lens_s    rcCsiiid}|j|j|j|j|j|jfD]}|D]}t||q0q(t|jdkrx|j D] \}}t||t||ddqV|d|d|dg}|j |dd }|d |d |d  fS) zA Work out the dynamic size of the columns to pass to fmtColumns. )rrrrz )rrrrr)Zremainder_column) installed availableextras autoremoveupdatesrecentrr obsoletesobsoletesTuplesZ calcColumns)r yplrZlstrZnpkgZopkgcolumnsrrr_list_cmd_calc_columnsjs  r)c Csdd}tj|}d}|j|dD]}|r.sm_ui_timeF)rrT0z%s-%s.%sz %s:%s-%s.%sz Installed: %s-%s at %sz Built : %s at %s)r sack rpmdb_sackqueryrfiltermprintZepochversionreleasertermboldrr Z installtimeZpackagerZ buildtime) pkgsbaser r.r1Zdonerrrrrrprint_versions{s&    r;c Cs:td}|D]$\}}t|||d|dqdS)NzTThe operation would result in switching of module '{0}' stream '{1}' to stream '{2}'rr)r itemsloggerwarningformat)switchedModulesZmsg1Z moduleNameZstreamsrrrreport_module_switchsrAcseZdZdZd!fdd Zd"fdd Zdd Zd d Zd d ZddZ d#ddZ ddZ ggdfddZ d$ddZ d%ddZfddZdd ZZS)&BaseCliz#This is the base class for yum cli.Ncs4|p tj}tt|j|dt||j|_dS)N)conf)r rCZConfsuperrB__init__r ZOutput)selfrC __class__rrrEszBaseCli.__init__rc stjjrJ|jjsJt|j}|rJt|t dj tj j d}tj ||j}|j|}|rjt||rg}g}d}|D]>} | jtjjvr|| jq~| jtjjvr~d}|| jq~|`|s|j|n|j|||s|js|jrZ|jjs|jjrZ|jj r6tt dj tj j!dn(d|jj"vr^tt dj tj j!dtj j#$ot%j&'|jj(dko|jj } d } d} | r|jj)d krtt d t*t d |jj)d vsJtj #} | +s>d} |jj)dkrtt dt*t d |jj)dks&J| ,s>tt dt-jj.|_/t0t1} |D]D}t2|j3D]2}|jj4D]"}t5||rn| |j6|qnqbqT| rtt d| 7D].\}}t||D]}td|q̐qt*t dn$|jj)dkrt*t dt-jj8|_/|9rD|jj:s8|j;sDt*t d | rl| rl| <ntt dd S|r|rtt dz|jj=}|>||jj?|Wn^tj j@y}z@tjAj BtC|}t dd|}tDtj |WYd }~n d }~00|E||jj rd StF|tGs.|g}tHgt1|}tItJ|K|}|d ur|jLM|gd}tjNjO|jL|jP}nd }|rtDtDdQ|jR|tD|D]&} | jSt-jjTkrtj t dq|S)zTake care of package downloading, checking, user confirmation and actually running the transaction. :param display: `rpm.callback.TransactionProgress` object(s) :return: history database transaction ID or None aQIt is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch. It is recommended to rather remove all installed content from the module, and reset the module using '{prog} module reset ' command. After you reset the module, you can install the other stream.progTFz7{prog} will only download packages for the transaction.testzP{prog} will only download packages, install gpg keys, and check the transaction./NZpersistz:Persistent transactions aren't supported on bootc systems.zOperation aborted.)auto transientrMzThis bootc system is configured to be read-only. Pass --transient to perform this transaction in a transient overlay which will reset when the system reboots.rNzA transient overlay will be created on /usr that will be discarded on reboot. Keep in mind that changes to /etc and /var will still persist, and packages commonly modify these directories.zThis operation would modify the following paths, possibly introducing inconsistencies when the transient overlay on /usr is discarded. See the usr_drift_protected_paths configuration option for more information.z %szeOperation aborted. Pass --setopt=usr_drift_protected_paths= to disable this check and proceed anyway.z;Transient transactions are only supported on bootc systems.zNothing to do.zDownloading Packages:zError downloading packages:z %sr zTransaction failed)Ur r:Z WITH_MODULESrCZmodule_stream_switchdictZ_moduleContainerZgetSwitchedStreamsrAr r?util MAIN_PROG exceptionsErrorZ transactionr Zlist_transactionr=infoactionZFORWARD_ACTIONSappendrZBACKWARD_ACTIONSZ_tsZreportRemoveSizeZreportDownloadSizeZ isChangedZ_historygroupenv downloadonlyMAIN_PROG_UPPERZtsflagsZ _BootcSystemZis_bootc_systemospathrealpath installrootZ persistencer Z is_writableZis_unlocked_transientlibdnfZ TransactionPersistence_TRANSIENTZ _persistencerlistsortedfilesZusr_drift_protected_pathsrnevrar<ZTransactionPersistence_PERSIST _promptWantedassumeno userconfirmZ make_writableZdownload_callback_total_cbZdownload_packagesprogressZ DownloadErrorcliZ indent_blockr r4 gpgsigcheck isinstancerZCliTransactionDisplayrDrBdo_transactionhistoryoldZdbZRPMTransactionZ_transjoinZpost_transaction_outputstateZTransactionItemState_ERROR)rFZdisplayr@msgZtransZpkg_strZ install_pkgsZrmpkgsZ install_onlyZtsiZis_bootc_transactionZ bootc_systemZbootc_system_needs_unlockZtransaction_protected_pathsrZ pkg_file_pathZprotected_patternrdZprotected_pathsZprotected_pathZtotal_cbeZspecificZerrstrtidrGrrrls                      "    zBaseCli.do_transactionc sg}|D]}|\}}|dkr&qq|dkrjjo>jj }tjrPtjsd|sdtj t dfdd}z ||Wqtjj t fy}z| t|WYd}~qd}~00q| |q|r|D]} t| qtj t ddS)aPerform GPG signature verification on the given packages, installing keys if possible. :param pkgs: a list of package objects to verify the GPG signatures of :raises: Will raise :class:`Error` if there's a problem rrzTRefusing to automatically import keys when running unattended. Use "-y" to override.cs jSN)r rg)r-yzrFrrcz%BaseCli.gpgsigcheck..NzGPG check FAILED)Z_sig_check_pkgrC assumeyesrfsysstdinisattyr rSrTr Z_get_key_for_package ValueErrorrWstrr=critical) rFr9Zerror_messagesporesulterrmsgZayfnrrrqrrwrrjKs& &  zBaseCli.gpgsigcheckcsVd|jjd|jD]&}|tj}|rtj|dq>qfdd|j D}|S)zBReturn list of changelogs for package newer then installed versionNrrcs$g|]}dus|dkr|qS)N timestampr).0ZchlogZnewestrr |sz-BaseCli.latest_changelogs..) Z_rpmconnZ readonly_tsZdbMatchrrpmZRPMTAG_CHANGELOGTIMEdatetimedateZ fromtimestamp changelogs)rFpackagemiZchangelogtimesZchlogsrrrlatest_changelogsrs zBaseCli.latest_changelogscCs4d|ddtj|dtj|df}|S)z*Return changelog formatted as in spec filez * %s %s %s rz%a %b %d %X %YZauthortext)r+r Zi18nr )rFZ changelogZ chlog_strrrrformat_changelogs  zBaseCli.format_changelogcCst}|D]}||jp|jg|q t|D]P}||}ttd d dd|D| |dD]}t| |qrq6dS)NzChangelogs for {}, cSsg|] }t|qSr)r)rrrrrrryz,BaseCli.print_changelogs..r) rPr source_namerrWrbkeysr4r r?rorr)rFZpackagesZbysrpmprZ bin_packagesZchlrrrprint_changelogss"zBaseCli.print_changelogsTFc CsJ|jd||d}|jjs |jjr@|jd||d}|j|_|j|_|rr: cli_commandscommandr riZdemandZ DemandSheetdemandsregister_commandZcommandsaliasZ AliasCommandr"ZAutoremoveCommandcheckZ CheckCommandZcleanZ CleanCommandZ distrosyncZDistroSyncCommandZdeplistZDeplistCommandZ downgradeZDowngradeCommandrXZ GroupCommandrmZHistoryCommandinstallZInstallCommandZ makecacheZMakeCacheCommandZmarkZ MarkCommandmoduleZ ModuleCommandZ reinstallZReinstallCommandremoveZ RemoveCommandrepolistZRepoListCommandZ repoqueryZRepoQueryCommandsearchZ SearchCommandshellZ ShellCommandZswapZ SwapCommandZ updateinfoZUpdateInfoCommandZupgradeZUpgradeCommandZupgrademinimalZUpgradeMinimalCommandZ InfoCommandZ ListCommandZProvidesCommandZCheckUpdateCommandZRepoPkgsCommandZ HelpCommand)rFr:rrrrEsBz Cli.__init__c Cs|j||jrZ|jD]<\}}|jjj||jj|gd}|||j |dfq|j r|j dd|j dd|j Dt }zt|jD]h\}}|jj|}|s|jjjr|dkrtd} tj| ||||dkr|q|qWnHtjjyH} z*t| |jtdWYd} ~ n d} ~ 00|D]}ttd |qN|jj } | dur|jj!} | D]$} |jj"| }|r|j#$q|jj%&\} |j_'|jj()| t%*|j|jj%}|jj(+|dS) N)Zbaseurlenabler)*disablecSsg|] }|dfqS)rr)rrrrrrryz(Cli._configure_repos..zUnknown repo: '%s'rzNo repository match: %s),r:Zread_all_reposZ repofrompathr<reposZ add_new_reporC_configure_from_optionsZrepos_edrWrepoinsertrsetZ get_matchingrr r rSZ RepoErroraddrr ConfigErrorr=r optparser print_helpr{exitr>Z_repo_persistorZget_expired_reposrget_repoexpirer Zsetup_progress_callbacksZ _ds_callbackrset_progress_barZ CliKeyImportZ_set_key_import)rFoptsZlabelr]Z this_repoZnotmatchrZ operationrrqrrZ expired_reposrZbarZ key_importrrr_configure_repossL          zCli._configure_reposcCsvtdjtjjdtjjttj j d|j ttj j d|j j jttj j d|j j jtd|j j jdS)Nz{prog} version: %srIz Command: %szInstallroot: %szReleasever: %sz cachedir: %s)r=debugr?r rQr[constVERSIONlogloggingDDEBUG cmdstringr:rCr_ releasevercachedirrwrrr_log_essentialss    zCli._log_essentialscCs|j}|jj}|jr.tjs.tjt d|j rH| D] }d|_ q<|j sX|jjj rd|jj_ |D]}|jtjjqjnD|jr| D]}|jqn$|js|D]}|jtjjq|jr|jj|jjrdnd|jjddS)Nz[This command has to be run with superuser privileges (under the root user on most systems).TrMF)load_system_repoZload_available_repos)rr:rZ root_userr rQZ am_i_rootrSrTr r iter_enabledZload_metadata_other cacheonlyrCvaluesrZsetSyncStrategyrZSYNC_ONLY_CACHEfreshest_metadatarZfresh_metadataZ SYNC_LAZYZsack_activationZ fill_sackrZavailable_repos)rFrrrrrr_process_demands s2      zCli._process_demandscCs|j}|j|}|dur~ttd|tjd|jj j r`ttdj t j jt j jd|nttdj t j jdt|||_tt jjd|tt jjd |dS) z,Check that the requested CLI command exists.Nz)No such command: %s. Please use %s --helprzLIt could be a {PROG} plugin command, try: "{prog} install 'dnf-command(%s)'")rJZPROGzRIt could be a {prog} plugin command, but loading of plugins is currently disabled.rIzBase command: %szExtra commands: %s)rrrr=rr r{argvr:rCZpluginsr?r rQrRr[r rrr)rFrrr command_clsrrr_parse_commands(s&        zCli._parse_commandsNc Cstjj}||}|dur*tjjn||_|j|}|j rpt tj j t |jjj|j|jjtd|jrd|_d|_|jrtj j|_|_zp|jr|jjd|jjjtjjd|j_|jj|||j |j!|j"d|vr|j#|jj_#|jj$Wntj%j&t'fyP}z&t()t*d|tdWYd}~nbd}~0t+y}z@d t,t-|t.|j/f}t()t*d|tdWYd}~n d}~00|j0dur|j0|jj_0|jjj1s|j2d vrt()t*d td|j3s|j4r&|j2d kr&t()t*d td|j5durHt67t89|j5d|j:|j;d|j<|j=|j>||j:|j;d|j2s|j?td||j_@|jjAd|_B|jj@D]}|jBd|7_Bq|Cz|D||WntEytdYn0|jFr(|j?|j2td|jG|j2|}|jHrR|jH|j_Id|j_J|jKrd|jK|j_K|jLrvd|jj_M|jNrd|jj_N|j2O|jP|jQ|R||jS|jj||j2T|jjj0rtjUV|jjj0|jjj0|jjWX_Y|jjjZdkr,|jjj[j\|jjjZdt]^ddvrd}|jjW_D]}|j`r\qLd|_`d}qL|jjjasd|jj_ad}|rt(bt*ddS)aParse command line arguments, and set up :attr:`self.base.conf` and :attr:`self.cmds`, as well as logger objects in base instance. :param args: a list of command line arguments :param option_parser: a class for parsing cli options NrrrTrzConfig error: %srz%s: %s)Zdownloadzsystem-upgradeZreposyncZ modulesynczb--destdir or --downloaddir must be used with --downloadonly or download or system-upgrade command.zconfig-managerz_--enable, --set-enabled and --disable, --set-disabled must be used with config-manager command.<mainZplugin z%s rM)colorz%_pkgverify_level)Z signaturerFzWarning: Enforcing GPG signature check globally as per active RPM security policy (see 'gpgcheck' in dnf.conf(5) for how to squelch this message))cr rialiasesZAliasesresolve option_parserZ OptionParserrZparse_main_argsr5r4rrr;r:rCZhistory_record_packagesr r{rquietZ debuglevelZ errorlevelrZ VERBOSE_LEVELrZ _set_valueZsystem_cachedirZ PRIO_DEFAULTrr_read_conf_filerreleasever_majorreleasever_minorrZ_adjust_conf_optionsrSrr~r=rr IOErrorr rreprfilenameZdestdirrZrZ set_enabledZ set_disabledZ sleeptimer*sleeprandomZ randrangeZ add_commandsrZ init_pluginsZ disablepluginZ enablepluginrrrJrrrr helpZparse_command_argsZ allowerasingZ allow_erasingZ_allow_erasingrZ debugsolverZ debug_solverr%Z pre_configureZpre_configure_pluginsZ_activate_persistorrZconfigure_plugins configurerQZ ensure_dirrrZpkgdirrr7ZreinitrZ expandMacrorZgpgcheckZlocalpkg_gpgcheckr>) rFrr r rrrrZforcingrrrrr>s                             z Cli.configurec Csxtjd}|jj}|d|d|d}|dtjj krft j |sftj td||jtjjd|d}|dtjj krd}|j}|j||ddd} d} |dur|jdurtj|j\}} } n|dkrtj|\}} } d d } | ||j|_| || |j|_| || |j|_|jdurJttd d D]} || qN|jj|||S) NZconfigZconfig_file_pathzConfig file "{}" does not exist)priorityZreposdirvarsdirrL)rcWs|D]}|dur|SqdSrtr)rrrrror_elses z$Cli._read_conf_file..or_elsezPUnable to detect release version (use '--releasever' to specify release version))rZlogdirZ persistdir) r rTimerr:rCZ_check_remote_fileZ_search_inside_installroot _get_valueZ _get_priorityZPRIO_COMMANDLINEr\r]isfilerSrr r?readZPRIO_MAINCONFIGZ substitutionsZupdate_from_etcrrZdetect_releaseversr_rrr=r>Zprepend_installroot_loggingZ_setup_from_dnf_conf) rFrrrZtimerrCrZ from_rootsubstZ det_majorZ det_minorroptrrrr s@       zCli._read_conf_fileeqcCs|dur|durdSg}|js"|r,|d|js6|r@|d|jsJ|rT|d|js^|rh|d|jj|||j|j|j |j ddS)zz :param opts: :param cmp_type: string supported "eq", "gte" :param all: :return: Nbugfix enhancement newpackagesecurity)typesadvisorybugzillacvesseverity) r"rWr#r$r%r:Zadd_security_filtersr'r(r)r*)rFrZcmp_typerr&rrr _populate_update_security_filters        z$Cli._populate_update_security_filtercCs4|dur|jjj||dur0|jjj|dS)z Change minimal logger level for terminal output to stdout and stderr according to specific command requirements @param stdout: logging.INFO, logging.WARNING, ... @param stderr:logging.INFO, logging.WARNING, ... N)r:rZstdout_handlerZsetLevelZstderr_handler)rFstdoutstderrrrrredirect_loggerszCli.redirect_loggercCs.tjj|}||jj_|jj|dSrt) r rirhZMultiFileProgressMeterr:r rrr)rFforhrrrredirect_repo_progress,s zCli.redirect_repo_progresscCs|jj}|durdS|jjj|jd}|}|jdd|}|D]}||krJ|}qJ||kr|td|td|dS)N)rr%)Z advisory_typez,Security: %s is an installed security updatez-Security: %s is the currently running version)r:r0Zget_running_kernelr2r3rrr4)rFZkernelqZikpkgrrrr_check_running_kernel1s   zCli._check_running_kernelcCs*t|jtjtd||dS)Nz)argument {}: not allowed with argument {})r4r print_usager rSrTr r?)rFZoption_string_1Zoption_string_2rrr_option_conflictCs zCli._option_conflictcCs8|jD],}||jvr(tjtd|||j|<qdS)zRegister a Command. :apizCommand "%s" already definedN)r rr rSrr )rFrrrrrrHs  zCli.register_commandc Cs||jjjr8ttddtt |jjj|jjj rhttddtt |jjj |jj D]h}|jrttd|j ddtt |j|j rtttd|j ddtt |j qt|jS)a2Call the base command, and pass it the extended commands or arguments. :return: (exit_code, [ errors ]) exit_code is:: 0 = we're done, exit 1 = we've errored, exit with error string 2 = we've got work yet to do, onto the next stage zExcludes in dnf.conf: rzIncludes in dnf.conf: zExcludes in repo z: zIncludes in repo )rr:rCZ excludepkgsr=rr rorbrZ includepkgsrridrrun)rFrrrrr6Os&   zCli.run)N)NNN)r!N)NN)rrrrErrrrrr r+r.r{r-r0r2r4rr6rrrrrs$3   9  r)r)QrZ __future__rrrcollections.abcr ImportError collectionsrrrrrr\rrr{r*rZlibdnf.transactionr`rr Zdnf.clir Zdnf.i18nr r r Zdnf.cli.aliasesZdnf.cli.commandsZdnf.cli.commands.aliasZdnf.cli.commands.autoremoveZdnf.cli.commands.checkZdnf.cli.commands.cleanZdnf.cli.commands.deplistZdnf.cli.commands.distrosyncZdnf.cli.commands.downgradeZdnf.cli.commands.groupZdnf.cli.commands.historyZdnf.cli.commands.installZdnf.cli.commands.makecacheZdnf.cli.commands.markZdnf.cli.commands.moduleZdnf.cli.commands.reinstallZdnf.cli.commands.removeZdnf.cli.commands.repolistZdnf.cli.commands.repoqueryZdnf.cli.commands.searchZdnf.cli.commands.shellZdnf.cli.commands.swapZdnf.cli.commands.updateinfoZdnf.cli.commands.upgradeZdnf.cli.commands.upgrademinimalZdnf.cli.demandZdnf.cli.formatZdnf.cli.option_parserZdnf.confZdnf.conf.substitutionsZ dnf.constZdnf.db.historyZdnf.exceptionsZ dnf.loggingZ dnf.persistorZ dnf.pluginZdnf.rpmZdnf.sackZdnf.transactionZdnf.utilZ dnf.yum.miscZ getLoggerr=rr)r;rAZBaserBobjectrrrrrs