3 f @stdZddlmZddlmZddlmZyddlmZWn ek rXddlmZYnXddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZdd lmZdd lmZmZddlZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zddl%Zddl&Zddl'Zddl(Zddl)Zddl*Zddl+Zddl,Zddl-Zddl.Zddl/Zddl0Zddl1Zddl2Zddl3Zddl4Zddl5Zddl6Zddl7Zddl8Zddl9Zddl:Zddl;ZddlZddl?Zddl@ZddlAZddlBZddlCZddlDZe jEd ZFdd dZGddZHddZIddZJGdddejKZLGdddeMZNdS)z/ Command line interface yum class and related. )print_function)absolute_import)unicode_literals)SequenceN)output)CliError)ucd_dnfcCst|jdt|jt|}t|j}t|j}xFd|fd|fd|ffD],\}}||j|d|||d7<qLWdS)zl Get the length of each pkg's column. Add that to data. This "knows" about simpleList and printVer. rnaverridrN)lennamearchZevrZ _from_repo setdefault)datapkgindentr rrdvr/usr/lib/python3.6/cli.py_add_pkg_simple_list_lens]s     rcCsiiid}x<|j|j|j|j|j|jfD]}x|D]}t||q4Wq*Wt|jdkrx*|j D] \}}t||t||d dq`W|d|d|dg}|j |d d }|d |d  |d  fS) zA Work out the dynamic size of the columns to pass to fmtColumns. )r rrr )rr rrr)Zremainder_columnz ) installed availableextras autoremoveupdatesrecentrr obsoletesobsoletesTuplesZ calcColumns)ryplrZlstrZnpkgZopkgcolumnsrrr_list_cmd_calc_columnshs   r)c Csdd}tjj|}d}x|jjj|dD]}|r>tdd}|jdkrbd|j|j |j f}nd |j|j|j |j f}|j j |j }ttd ||||jfttd |jr|jnd||jfq.WdS) NcSstjdtj|S)Nz%c)timestrftimeZgmtime)xrrr sm_ui_timezsz"print_versions..sm_ui_timeF)rr T0z%s-%s.%sz %s:%s-%s.%sz Installed: %s-%s at %sz Built : %s at %s)r sack rpmdb_sackqueryrfiltermprintZepochversionreleasertermboldrr Z installtimeZpackagerZ buildtime) pkgsbaserr-r0donerrrrrrprint_versionsys    r;cCs>td}x0|jD]$\}}tj|j||d|dqWdS)NzTThe operation would result in switching of module '{0}' stream '{1}' to stream '{2}'rr)r itemsloggerwarningformat)switchedModulesZmsg1Z moduleNameZstreamsrrrreport_module_switchsrAcseZdZdZd fdd Zfffdd ZddZd d Zd d Zd dZ fdddfddZ ddZ ggdfddZ dfdfddZ d!ddZfddZddZZS)"BaseCliz#This is the base class for yum cli.Ncs4|p tjj}tt|j|dtj||j|_dS)N)conf)r rCZConfsuperrB__init__rZOutput)selfrC) __class__rrrEszBaseCli.__init__cstjjrJ|jjsJt|jj}|rJt|t dj tj j d}tj j||j}|jj|}|rjtj||rg}g}d}xF|D]>} | jtjjkr|j| jq| jtjjkrd}|j| jqW|`|s|jj|n|jj|||s|jjs|jr|jjs|jjr|jj r:tjt dj tj j!dn(d|jj"krbtjt dj tj j!d|j#r|jj$s|jj% rt&t dntjt d d S|rD|r:tjt d y|jj'} |j(||jj)| Wn\tj j*k r8} z:tj+j j,t-| } t d d | } t.tj j| WYd d } ~ XnX|j/||jj rRd St0|t1sd|g}tj2gt3|}t4t5|j6|}|d k r|j7j8|gd}tj9jj:|j7|j;}nd }|rt.t.dj<|jj=|t.x.|D]&} | j>t?jj@krtj jt dqW|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.ZtestzP{prog} will only download packages, install gpg keys, and check the transaction.zOperation aborted.zNothing to do.NzDownloading Packages:zError downloading packages:z %sr zTransaction failed)Ar r9Z WITH_MODULESrCZmodule_stream_switchdictZ_moduleContainerZgetSwitchedStreamsrAr r?util MAIN_PROG exceptionsErrorZ transactionrZlist_transactionr=infoactionZFORWARD_ACTIONSappendrZBACKWARD_ACTIONSZ_tsZreportRemoveSizeZreportDownloadSizeZ isChangedZ_historygroupenv downloadonlyMAIN_PROG_UPPERZtsflags _promptWantedassumeno userconfirmrZdownload_callback_total_cbZdownload_packagesprogressZ DownloadErrorcliZ indent_blockr r3 gpgsigcheck isinstancerZCliTransactionDisplaylistrDrBdo_transactionhistoryoldZdbZRPMTransactionZ_transjoinZpost_transaction_outputstatelibdnfZTransactionItemState_ERROR)rFZdisplayr@msgZtransZpkg_strZ install_pkgsZrmpkgsZ install_onlyZtsiZtotal_cbeZspecificZerrstrtid)rGrrr^s              zBaseCli.do_transactionc sg}x|D]}j|\}}|dkr(q q |dkrĈjjo@jj }tj sVtjj rl| rltjj t dfdd}yj ||Wqtjj t fk r}z|j t|WYdd}~XqXq |j |q W|rx|D]} tj| qWtjj 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 jjS)N)rrX)r,yz)rFrr$sz%BaseCli.gpgsigcheck..NzGPG check FAILED)Z_sig_check_pkgrC assumeyesrWsysstdinisattyr rMrNr Z_get_key_for_package ValueErrorrQstrr=critical) rFr8Zerror_messagesporesulterrmsgZayfnrerdr)rFrr[ s&  " zBaseCli.gpgsigcheckcsXdx:|jjjd|jD]$}|tj}|rtjj|dPqWfdd|j D}|S)zBReturn list of changelogs for package newer then installed versionNrrcs$g|]}dks|dkr|qS)N timestampr).0Zchlog)newestrr =sz-BaseCli.latest_changelogs..) Z_rpmconnZ readonly_tsZdbMatchrrpmZRPMTAG_CHANGELOGTIMEdatetimeZdateZ fromtimestamp changelogs)rFpackageZmiZchangelogtimesZchlogsr)rwrlatest_changelogs3s zBaseCli.latest_changelogscCs4d|djdtjj|dtjj|df}|S)z*Return changelog formatted as in spec filez * %s %s %s ruz%a %b %d %X %YZauthortext)r+r Zi18nr )rFZ changelogZ chlog_strrrrformat_changelogAs  zBaseCli.format_changelogcCst}x&|D]}|j|jp|jgj|q Wxdt|jD]T}||}ttdj dj dd|Dx$|j |dD]}t|j |qzWq.r) rJr source_namerrQsortedkeysr3r r?rar}r)rFZpackagesZbysrpmprZ bin_packagesZchlrrrprint_changelogsIs "zBaseCli.print_changelogsTFc CsR|jd||d}|jjs |jjr@|jd||d}|j|_|j|_|rDt|j|}t|jdkri}|jj j d} | rx>t |jD]0} | j } t jj| r| jr| || j| jf<qW|jj} |jj} |jj|jdd||| | dd |r|j|jt|jdkrDttd x0t |jtjdd D]}|jj|d|d q(W|jpP|jS) z?Check updates matching given *patterns* in selected repository.Zupgrades)reponamer%rr7r r])=znot in)Z outputType highlight_nar(highlight_modeszObsoleting Packages)key)r()returnPkgListsrCr%verboser&r)rrr#r6MODErZlocalPkgospathexistsZverifyLocalPkgrrcolor_update_localcolor_update_remotelistPkgsrr3r operator itemgetterupdatesObsoletesList)rFpatternsrZprint_r{r'Ztyplr( local_pkgs highlightrqZlocalculcurobtuprrr check_updatesUs:    zBaseCli.check_updatescCsr|jj}t|dkr |jnx|D]}|j|q&W|jj|}|dkrn|jj rntd}tjj|dS)ab Upgrade or downgrade packages to match the latest versions available in the enabled repositories. :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 rz4No packages marked for distribution synchronization.N) Z_goalZ req_lengthrZ distro_syncZreq_has_distupgrade_allr r rMrN)rFZuserlistZoldcountpkg_specZcntrdrrrdistro_sync_userlist{s    zBaseCli.distro_sync_userlistc CsTd}xf|D]^}y|j||dd}Wq tjjk rf}z"tjtd|jjj |j WYdd}~Xq Xq Wx|D]}y|j ||dd}Wqrtjj k r}z$td} tj| |jjj |WYdd}~Xqrtjj k r}z"tjtd|jjj |jWYdd}~Xqrtjjk r4ds0tYqrXqrW|sPtjjtddS) aaAttempt to take the user specified list of packages or wildcards and downgrade them. If a complete version number is specified, attempt to downgrade them to the specified version :param specs: a list of names or wildcards specifying packages to downgrade :param file_pkgs: a list of pkg objects from local files F)strictTzNo match for argument: %sNzNo package %s available.z6Packages for argument %s available, but not installed.z!No packages marked for downgrade.)Zpackage_downgrader rMZ MarkingErrorr=rOr rr6r7locationZ downgrade_toZPackageNotFoundErrorZPackagesNotInstalledErrorrAssertionErrorrN) rFZspecsZ file_pkgsrrrrreargerrrdrrr downgradePkgss,   ( & "zBaseCli.downgradePkgsallc!CsDy$|jjjd}|j||||d}Wn0tjjk rT}zdt|gfSd}~XnXi}i} i} d} |dkrzt|j|} |r|j rxB|j |j |j D],} | j | jf} | |ks| || kr| || <qW|o|jrx8|jD].} | j | jf} | | ks| | | kr| | | <qW|rP|jrPx2t|jD]$}|jtjkr(|| |j |jf<q(W|jj}|jj}|jj}|jj}|jj|j td||| ||||dd}|jj}|jj}|jj}|jj }|jj|jtd || | ||||d d}|jj|j!td || d }|jj|j"td || d }|jj#}|jj$}|jj|jtd|| | ||dd}t%|j&dkr|dkrt%|j&}t'tdxLt|j(t)j*ddD]}|jj+|d| d qWn|jj|j&td|| d }|jj|j,td|| d } t%|r@| dkr@|dkr@|dkr@|dkr@|dkr@|dkr@|dkr@tjjtddS)zJOutput selection *pkgnarrow* of packages matching *patterns* and *repoid*.r7)installed_availablerrNr]zInstalled Packages)>r9 cli_commandscommandr rZZdemandZ DemandSheetdemandsregister_commandZcommandsaliasZ AliasCommandr"ZAutoremoveCommandZcheckZ CheckCommandZcleanZ CleanCommandZ distrosyncZDistroSyncCommandZdeplistZDeplistCommandZ downgradeZDowngradeCommandrRZ GroupCommandr_ZHistoryCommandZinstallZInstallCommandZ makecacheZMakeCacheCommandZmarkZ MarkCommandmoduleZ ModuleCommandZ reinstallZReinstallCommandremoveZ RemoveCommandrepolistZRepoListCommandZ repoqueryZRepoQueryCommandsearchZ SearchCommandshellZ ShellCommandZswapZ SwapCommandZ updateinfoZUpdateInfoCommandZupgradeZUpgradeCommandZupgrademinimalZUpgradeMinimalCommandZ InfoCommandZ ListCommandZProvidesCommandZCheckUpdateCommandZRepoPkgsCommandZ HelpCommand)rFr9rrrrEfsBz Cli.__init__cCs|jj||jr^xJ|jjD]<\}}|jjj||jj|gd}|j||jj |dfqW|j r|jj dd |jj dd|j Dt }yzxt|jD]j\}}|jjj|}|s|jjjr|dkrtd} tjj| ||j||dkr|jq|jqWWnFtjjk rP} z$tj| |jjtjd WYdd} ~ XnXx|D]}tjtd |qXW|jjj } | dkr|jjj!} x,| D]$} |jjj"| }|r|j#j$qW|jj%j&\} |j_'|jjj(j)| t%j*|j|jj%}|jjj(j+|dS) N)Zbaseurlenabler*disablecSsg|] }|dfqS)rr)rvrrrrrxsz(Cli._configure_repos..zUnknown repo: '%s'rzNo repository match: %s)rr),r9Zread_all_reposZ repofrompathr<reposZ add_new_reporC_configure_from_optionsZrepos_edrQrepoinsertrsetZ get_matchingrr r rMZ RepoErroraddrr ConfigErrorr=rp optparser print_helprkexitr>Z_repo_persistorZget_expired_reposrget_repoexpirerZsetup_progress_callbacksZ _ds_callbackrset_progress_barZ CliKeyImportZ_set_key_import)rFoptsZlabelrZ this_repoZnotmatchrZ operationrrdreZ expired_reposrZbarZ key_importrrr_configure_repossL            zCli._configure_reposcCsvtjdjtjjdtjjtjtj j d|j tjtj j d|j j jtjtj j d|j j jtjd|j j jdS)Nz{prog} version: %s)rHz Command: %szInstallroot: %szReleasever: %sz cachedir: %s)r=debugr?r rKrUconstVERSIONlogloggingDDEBUG cmdstringr9rC installroot releasevercachedir)rFrrr_log_essentialss      zCli._log_essentialscCs|j}|jj}|jr.tjjs.tjjt d|j rLx|j D] }d|_ q>W|j s\|jjj rd|jj_ xn|jD]}|jjtjjqpWnL|jrxD|j D]}|jjqWn(|jsx |jD]}|jjtjjqW|jr|jj|jjrdnd|jjddS)Nz[This command has to be run with superuser privileges (under the root user on most systems).TautoF)load_system_repoZload_available_repos)rr9rZ root_userr rKZ am_i_rootrMrNr r{ iter_enabledZload_metadata_other cacheonlyrCvaluesrZsetSyncStrategyrZSYNC_ONLY_CACHEfreshest_metadatarZfresh_metadataZ SYNC_LAZYZsack_activationZ fill_sackrZavailable_repos)rFrrrrrr_process_demandss.    zCli._process_demandscCs|j}|jj|}|dkr~tjtd|tjd|jj j r`tjtdj t j jt j jd|ntjtdj t j jdt|||_tjt jjd|tjt 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)'")rHZPROGzRIt could be a {prog} plugin command, but loading of plugins is currently disabled.)rHzBase command: %szExtra commands: %s)rrrr=rpr rkargvr9rCZpluginsr?r rKrLrUrrrr)rFrrr command_clsrrr_parse_commandss      zCli._parse_commandsNc Cstjjj}|j|}|dkr*tjjjn||_|jj|}|j rpt tj j t |jjj|j|jjtjd|jrd|_d|_|jrtj j|_|_yh|jr|jjjd|jjjtjjd|j_|jjj||j|j d|kr|j!|jj_!|jjj"Wntj#j$t%fk rF}z t&j't(d|tjdWYdd}~XnXt)k r}z:d t*t+|t,|j-f}t&j't(d|tjdWYdd}~XnX|j.dk r|j.|jj_.|jjj/ r|j0dkrt&j't(dtjd|j1s|j2r|j0dkrt&j't(dtjd|j3dk r>t4j5t6j7|j3d|jj8|j9d|jj:|j;|j<||jj8|j9d|j0s|jj=tjd||j_>|jj?d|_@x$|jj>D]}|j@d|7_@qW|jAy|jB||Wn tCk rtjdYnX|jDr$|jj=|j0tjd|jjE|j0|}|jFrN|jF|j_Gd|j_H|jIr`|jI|j_I|jJrrd|jj_K|jLrd|jj_L|j0jM|jjN|jjO|jP||jjQ|jjj||j0jR|jjj.rtjSjT|jjj.|jjj.|jjUjV_W|jjjXdkr(|jjjYjZ|jjjXdt[j\ddkrd}x,|jjUj]D]}|j^rZqJd|_^d}qJW|jjj_sd|jj__d}|rt&j`t(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: %sdownloadsystem-upgradereposync 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.<mainZpluginrz%s r)colorz%_pkgverify_level signaturerFzWarning: Enforcing GPG signature check globally as per active RPM security policy (see 'gpgcheck' in dnf.conf(5) for how to squelch this message))rrrr)rr)ar rZaliasesZAliasesZresolve option_parserZ OptionParserrZparse_main_argsr4r3rrr;r9rCZhistory_record_packagesrrkrquietZ debuglevelZ errorlevelrZ VERBOSE_LEVELrZ _set_valueZsystem_cachedirZ PRIO_DEFAULTrr_read_conf_filerrZ_adjust_conf_optionsrMrrnr=rpr IOErrorr roreprfilenameZdestdirrTrZ set_enabledZ set_disabledZ sleeptimer*ZsleeprandomZ randrangeZ add_commandsrZ init_pluginsZ disablepluginZ enablepluginrrrHrrrrhelpZparse_command_argsZ allowerasingZ allow_erasingZ_allow_erasingrZ debugsolverZ debug_solverr%Z pre_configureZpre_configure_pluginsZ_activate_persistorrZconfigure_plugins configurerKZ ensure_dirrrZpkgdirrr6ZreinitryZ expandMacrorZgpgcheckZlocalpkg_gpgcheckr>) rFrrrrrerZforcingrrrrrs                                z Cli.configurecCsBtjjd}|jj}|jd|jd|jd}|jdtjj krht j j | rhtj jtdj||jtjjd|jd}|jdtjj krd}|j}|j||jdd|dkr|jdkrtjj|j}n|dkrtjj|}|dk r||_|jdkrtjtd xd D]}|j|qW|jjj|||S)NconfigZconfig_file_pathzConfig file "{}" does not exist)ZpriorityZreposdirvarsdir/)rzPUnable to detect release version (use '--releasever' to specify release version)rlogdir persistdir)rrr)r rZTimerr9rCZ_check_remote_fileZ_search_inside_installrootZ _get_valueZ _get_priorityZPRIO_COMMANDLINErrisfilerMrr r?readZPRIO_MAINCONFIGZ substitutionsZupdate_from_etcrryZdetect_releaseverrr=r>Zprepend_installroot_loggingZ_setup_from_dnf_conf)rFrZtimerrCrZ from_rootZsubstoptrrrrs6        zCli._read_conf_fileeqcCs|dkr|dkrdSg}|js"|r,|jd|js6|r@|jd|jsJ|rT|jd|js^|rh|jd|jj|||j|j|j |j ddS)zz :param opts: :param cmp_type: string supported "eq", "gte" :param all: :return: Nbugfix enhancement newpackagesecurity)typesadvisorybugzillacvesseverity) r rQr r r r9Zadd_security_filtersrrrr)rFrZcmp_typerrrrr _populate_update_security_filters        z$Cli._populate_update_security_filtercCs4|dk r|jjjj||dk r0|jjjj|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)r9rZstdout_handlerZsetLevelZstderr_handler)rFstdoutstderrrrrredirect_loggerszCli.redirect_loggercCs.tjjj|}||jj_|jjjj|dS)N) r rZrYZMultiFileProgressMeterr9rrrr)rFZforYrrrredirect_repo_progresss zCli.redirect_repo_progresscCs|jjj}|dkrdS|jjjj|jd}|j}|jdd|}x|D]}||krL|}qLW||krtd|td|dS)N)rr )Z advisory_typez,Security: %s is an installed security updatez-Security: %s is the currently running version)r9r/Zget_running_kernelr1r2rrr3)rFZkernelqZikpkgrrrr_check_running_kernels    zCli._check_running_kernelcCs*t|jjtjjtdj||dS)Nz)argument {}: not allowed with argument {})r3rZ print_usager rMrNr r?)rFZoption_string_1Zoption_string_2rrr_option_conflicts zCli._option_conflictcCs<x6|jD],}||jkr*tjjtd|||j|<qWdS)zRegister a Command. :apizCommand "%s" already definedN)rrr rMrr )rFrrrrrrs  zCli.register_commandcCs|j|jjjr8tjtddjtt |jjj|jjj rhtjtddjtt |jjj xx|jj j D]h}|jrtjtd|j ddjtt |j|j rvtjtd|j ddjtt |j qvW|jjS)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: z, zIncludes in dnf.conf: zExcludes in repo z: zIncludes in repo )rr9rCZ excludepkgsr=rr rarrZ includepkgsrridrrun)rFrrrrrs  " "(,zCli.run)N)N)r N)NN)rrrrErrrrrrrrrkrrrrrrrrrrres$3   -  r)r )OrZ __future__rrrcollections.abcr ImportError collectionsrzrrrrryrkr*rZlibdnf.transactionrcr rZdnf.clirZdnf.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       O