3 ft`{}@sdZddlmZddlmZddlmZddlmZddlZ ddl Z ddl Z ddl Z ddl Z ddlZe jdZedd Zed d Zed Zd dZffddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZdS)z< Classes for subcommands of the yum command line interface. )print_function)unicode_literals) OptionParser)_Ndnfz+To diagnose the problem, try running: '%s'.zrpm -Va --nofiles --nodigestzDYou probably have corrupted RPMDB, running '%s' might fix the issue.zrpm --rebuilddba You have enabled checking of packages via GPG keys. This is a good thing. However, you do not have any GPG public keys installed. You need to download the keys for packages you wish to install and install them. You can do that by running the command: rpm --import public.gpg.key Alternatively you can specify the url to the key you would like to use for a repository in the 'gpgkey' option in a repository section and {prog} will install it for you. For more information contact your distribution or package provider.cCsp|jjs dS|jslxV|jjD]H}|js0|jr |j r tjdt j t j j dtjtd|t jjq WdS)zVerify that there are gpg keys for the enabled repositories in the rpm database. :param base: a :class:`dnf.Base` object. :raises: :class:`cli.CliError` Nz %s )progzProblem repository: %s)confZgpgcheckZ_gpg_key_checkreposZ iter_enabledZ repo_gpgcheckZgpgkeyloggerZcriticalgpg_msgformatrutilMAIN_PROG_UPPERrcliCliError)baserrepor/usr/lib/python3.6/__init__.py _checkGPGKey:srcCs||jjrdSxD|D]<}|jdr2tjj|r2dStjjj|d}|d krdSqWt dj d j |j j }tjj|dS) zVerify that there is at least one enabled repo. :param base: a :class:`dnf.Base` object. :param possible_local_files: the list of strings that could be a local rpms :raises: :class:`cli.CliError`: Nz.rpmrhttpftpfilehttpsz*There are no enabled repositories in "{}".z", ")rrrr)r Z _any_enabledendswithospathexistsrZpycompZurlparserr joinrZreposdirrr)rZpossible_local_filesZlfileschememsgrrr_checkEnabledRepoKs  r!c@seZdZdZgZdZdZddZeddZ edd Z ed d Z d d Z ddZ ddZddZddZddZddZdS)Commandz%Abstract base class for CLI commands.NcCs ||_dS)N)r)selfrrrr__init__fszCommand.__init__cCs|jjS)N)rr)r$rrrrjsz Command.basecCs |jdS)Nr)aliases)r$rrr_basecmdoszCommand._basecmdcCs |jjjS)N)rroutput)r$rrrr(sszCommand.outputcCsdS)z4Define command specific options and arguments. #:apiNr)r$parserrrr set_argparserwszCommand.set_argparsercCsdS)z*Do any command-specific pre-configuration.Nr)r$rrr pre_configure{szCommand.pre_configurecCsdS)z&Do any command-specific configuration.Nr)r$rrr configureszCommand.configurecCs&t|tjjrttfStd|dS)z.Get suggestions for resolving the given error.zerror not supported yet: %sN) isinstancer exceptionsZTransactionCheckError _RPM_VERIFY_RPM_REBUILDDBNotImplementedError)r$errorrrrget_error_outputszCommand.get_error_outputcCsdS)zExecute the command.Nr)r$rrrrunsz Command.runcCsdS)z$Finalize operation after resolvementNr)r$rrr run_resolvedszCommand.run_resolvedcCsdS)z%Finalize operations post-transaction.Nr)r$rrrrun_transactionszCommand.run_transaction)__name__ __module__ __qualname____doc__r&summaryoptsr%propertyrr'r(r*r+r,r3r4r5r6rrrrr"_s   r"c @sReZdZdZdZedZdZddddd d d d eh Ze d dZ ddZ ddZ dS) InfoCommandzRA class containing methods needed by the cli to execute the info command. infoz4display details about a package or group of packagesall available installedextrasupdatesupgrades autoremoverecent obsoletesc Cs|j}|jdddddtdd|jddddtd d |jd ddd td d |jddddtdd |jddddtdd |jddddtdd |jddddtdd |jddddtdd |jddtd|j|jtjtdddS) Nz--all_packages_action store_constr@zshow all packages (default))destactionconstdefaulthelpz --availablerAzshow only available packages)rKrLrMrOz --installedrBzshow only installed packagesz--extrasrCzshow only extras packagesz --updatesrEzshow only upgrades packagesz --upgradesz --autoremoverFzshow only autoremove packagesz--recentrGz#show only recently changed packagespackages*PACKAGEzPackage name specification)nargsmetavarchoicesrNrLrO)add_mutually_exclusive_group add_argumentr pkgnarrowsDEFAULT_PKGNARROWrPkgNarrowCallback)clsr)narrowsrrrr*s:        zInfoCommand.set_argparsercCs||jj}d|_|jjr"|jj|j_|jjdkr4d|_|jjrd|jjr\|jjdd|jjnd|j_|jjdkrxd|j_dS)NTrBz --obsoletesz--rHrDrE) rdemandssack_activationr<rIpackages_actionavailable_reposrH_option_conflict)r$r]rrrr,s   zInfoCommand.configurecCs&|jj|j|jjd|jj|jjS)Nr?)r _populate_update_security_filterr<routput_packagesr_rP)r$rrrr4szInfoCommand.runN)r?) r7r8r9r:r&rr;rYrX classmethodr*r,r4rrrrr>s   r>c@s$eZdZdZdZedZddZdS) ListCommandzRA class containing methods needed by the cli to execute the list command. listlsz$list a package or groups of packagescCs&|jj|j|jjd|jj|jjS)Nrf)rrbr<rrcr_rP)r$rrrr4szListCommand.runN)rfrg)r7r8r9r:r&rr;r4rrrrresrec@s8eZdZdZd ZedZeddZdd Z d d Z d S)ProvidesCommandzVA class containing methods needed by the cli to execute the provides command. provides whatprovidesprovz*find what package provides the given valuecCs|jddtdtdddS)N dependency+ZPROVIDEz#Provide specification to search for)rSrTrO)rWr)r)rrrr*szProvidesCommand.set_argparsercCs|jj}d|_d|_d|_dS)NTF)rr]r`Zfresh_metadatar^)r$r]rrrr,szProvidesCommand.configurecCstjtd|jj|jjS)NzSearching Packages: )r debugrrrir<rl)r$rrrr4szProvidesCommand.runN)rirjrk) r7r8r9r:r&rr; staticmethodr*r,r4rrrrrhs  rhc@s8eZdZdZd ZedZeddZddZ d d Z d S) CheckUpdateCommandzZA class containing methods needed by the cli to execute the check-update command. check-update check-upgradez$check for available package upgradescCs0|jddddtdd|jddtd d dS) Nz --changelogs changelogsF store_truezshow changelogs before update)rKrNrLrOrPrQrR)rSrT)rWr)r)rrrr*s z CheckUpdateCommand.set_argparsercCs6|jj}d|_d|_d|_|jjr(d|_t|jdS)NT) rr]r^r`Zplugin_filtering_enabledr<rsr!r)r$r]rrrr, szCheckUpdateCommand.configurecCsR|jj|jdd|jj|jjd|jjd}|r:d|jj_|jj j rN|jj dS)NZgte)Zcmp_typeT)print_rsd) rrbr<r check_updatesrPrsr]success_exit_statusrZautocheck_running_kernelZ_check_running_kernel)r$foundrrrr4s   zCheckUpdateCommand.runN)rqrr) r7r8r9r:r&rr;ror*r,r4rrrrrps   rpc seZdZdZGdddeZGdddeZGdddeZGdd d eZGd d d eZ Gd d d eZ GdddeZ GdddeZ GdddeZ GdddeZGdddeZeeeee e e e e eeh Zd%ZedZfddZdd Zd!d"Zd#d$ZZS)&RepoPkgsCommandz2Implementation of the repository-packages command.c@s$eZdZdZdZddZddZdS) z%RepoPkgsCommand.CheckUpdateSubCommandz'Implementation of the info sub-command. check-updatecCs|jj}d|_d|_dS)NT)rr]r`r^)r$r]rrrr,(sz/RepoPkgsCommand.CheckUpdateSubCommand.configurecCs*|jj|jj|jdd}|r&d|jj_dS)z?Execute the command with respect to given arguments *cli_args*.T)rurvN)rrwr< pkg_specsreponamerr]rx)r$ryrrr run_on_repo-s  z1RepoPkgsCommand.CheckUpdateSubCommand.run_on_repoN)r{)r7r8r9r:r&r,r~rrrrCheckUpdateSubCommand#src@s$eZdZdZdZddZddZdS) zRepoPkgsCommand.InfoSubCommandz'Implementation of the info sub-command.r?cCsh|jj}d|_|jjr"|jj|j_|jjdkr4d|_|jjrd|jjr\|jjdd|jjnd|j_dS)NTrBz --obsoletesz--rH) rr]r^r<_pkg_specs_actionpkg_specs_actionr`rHra)r$r]rrrr,9s  z(RepoPkgsCommand.InfoSubCommand.configurecCs.|jj|j|jjd|jj|jj|jdS)z?Execute the command with respect to given arguments *cli_args*.r?N)rrbr<rrcrr|r})r$rrrr~Fsz*RepoPkgsCommand.InfoSubCommand.run_on_repoN)r?)r7r8r9r:r&r,r~rrrrInfoSubCommand4s rc@s$eZdZdZdZddZddZdS) z!RepoPkgsCommand.InstallSubCommandz*Implementation of the install sub-command.installcCs$|jj}d|_d|_d|_d|_dS)NT)rr]r`r^ resolving root_user)r$r]rrrr,Qs z+RepoPkgsCommand.InstallSubCommand.configurecCs|jj|jt|j|jd}|jjsjy|jjd|jWn&tj j k rbt j t dYqXd}nvxt|jjD]h}y|jj||jWnJtj j k r}z*dj|j|jjjj|}t j |WYdd}~XqtXd}qtW|stj jt ddS)NFrQzNo package available.Tz{}: {}zNo packages marked for install.)rrbr<rrr|rr}rr. MarkingErrorr r?rr valuer(termboldError)r$donepkg_specer rrrr~Xs$z-RepoPkgsCommand.InstallSubCommand.run_on_repoN)r)r7r8r9r:r&r,r~rrrrInstallSubCommandLsrc@seZdZdZdZddZdS)zRepoPkgsCommand.ListSubCommandz'Implementation of the list sub-command.rfcCs.|jj|j|jjd|jj|jj|jdS)z?Execute the command with respect to given arguments *cli_args*.rfN)rrbr<rrcrr|r})r$rrrr~zsz*RepoPkgsCommand.ListSubCommand.run_on_repoN)rf)r7r8r9r:r&r~rrrrListSubCommandusrc@s$eZdZdZdZddZddZdS) z RepoPkgsCommand.MoveToSubCommandz*Implementation of the move-to sub-command.move-tocCs$|jj}d|_d|_d|_d|_dS)NT)rr]r^r`rr)r$r]rrrr,s z*RepoPkgsCommand.MoveToSubCommand.configurecCst|j|jd}|jjsy|jjd|jdWn`tjj k rVt j t dYn@tjj k rzt j t dYntjjk rYnXd}nx|jjD]}y|jj||jdWntjj k rt d}t j ||Yqtjj k rd}z\xT|jD]J}d}|jjj|}|r.t d |}t d }t j ||jjj||qWWYd d }~Xqtjjk r|YqXd}qW|stjjt d d S) z?Execute the command with respect to given arguments *cli_args*.FrQ)Z new_reponamezNo package installed.zNo package available.TzNo match for argument: %sr#z (from %s)z%Installed package %s%s not available.NzNothing to do.)rrrr<r| reinstallr}rr.PackagesNotInstalledErrorr r?rPackagesNotAvailableErrorrrPhistoryrr(rrr)r$rrr errpkgxmsgpkgreporrrr~s>  .z,RepoPkgsCommand.MoveToSubCommand.run_on_repoN)r)r7r8r9r:r&r,r~rrrrMoveToSubCommandsrc@s$eZdZdZdZddZddZdS) z&RepoPkgsCommand.ReinstallOldSubCommandz0Implementation of the reinstall-old sub-command. reinstall-oldcCs$|jj}d|_d|_d|_d|_dS)NT)rr]r^r`rr)r$r]rrrr,s z0RepoPkgsCommand.ReinstallOldSubCommand.configurecCst|j|jd}|jjsy|jjd|j|jWndtjj k r\t d}t j |Yn@tjj k rt j t dYntjjk rYnXd}nx|jjD]}y|jj||j|jWntjj k rt d}t j ||Yqtjj k rl}z\xT|jD]J}d}|jjj|}|r6t d|}t d }t j ||jjj||qWWYd d }~Xqtjjk rYqXd}qW|stjjt d d S) z?Execute the command with respect to given arguments *cli_args*.FrQz)No package installed from the repository.zNo package available.TzNo match for argument: %sr#z (from %s)z%Installed package %s%s not available.NzNothing to do.)rrrr<r|rr}rr.rrr r?rrrPrrr(rrr)r$rr rrrrrrrrr~sB    .z2RepoPkgsCommand.ReinstallOldSubCommand.run_on_repoN)r)r7r8r9r:r&r,r~rrrrReinstallOldSubCommandsrcs4eZdZdZd ZfddZddZddZZS) z#RepoPkgsCommand.ReinstallSubCommandz,Implementation of the reinstall sub-command.rcs,ttj|j|tj|tj|f|_dS)zInitialize the command.N)superrzReinstallSubCommandr%rrwrapped_commands)r$r) __class__rrr%sz,RepoPkgsCommand.ReinstallSubCommand.__init__cCs6d|jj_x&|jD]}|j|_|j|_|jqWdS)NT)rr]r`rr<r}r,)r$commandrrrr,s   z-RepoPkgsCommand.ReinstallSubCommand.configurec Cs\t|j|jxH|jD].}y |jWntjjk r@wYqXPqWtjjtddS)z?Execute the command with respect to given arguments *cli_args*.z!No packages marked for reinstall.N) rrrrr~rr.rr)r$rrrrr~s  z/RepoPkgsCommand.ReinstallSubCommand.run_on_repo)r) r7r8r9r:r&r%r,r~ __classcell__rr)rrrs  rc@s,eZdZdZd ZddZddZddZd S) z,RepoPkgsCommand.RemoveOrDistroSyncSubCommandz8Implementation of the remove-or-distro-sync sub-command.remove-or-distro-synccCs$|jj}d|_d|_d|_d|_dS)NT)rr]r`r^rr)r$r]rrrr,s z6RepoPkgsCommand.RemoveOrDistroSyncSubCommand.configurec s|jjjjtjj|}|j|jjj}|jjjfdd|j D}|s`tj j d||j }|jjj j}xD|D]<}|j|j|jdr|jjjj|qz|jjjj||dqzWdS)z;Synchronize a package with another repository or remove it.csg|]}j|kr|qSr)r).0r)rr}rr #szIRepoPkgsCommand.RemoveOrDistroSyncSubCommand._replace..zno package matched)namearch) clean_depsN)rrZsackZ disable_reporsubjectZSubjectZget_best_queryrrBr.rrArZclean_requirements_on_removefilterrrZ_goalZ distupgradeZerase) r$rr}rZmatchesrBrArpackager)rr}r_replaces    z5RepoPkgsCommand.RemoveOrDistroSyncSubCommand._replacec Cst|j|jd}|jjs^y|jd|jWn*tjj k rVt d}t j |YqXd}nVxT|jjD]H}y|j||jWn,tjj k rt d}t j ||YqhXd}qhW|stjj t ddS)z?Execute the command with respect to given arguments *cli_args*.FrQz)No package installed from the repository.TzNo match for argument: %szNothing to do.N)rrrr<r|rr}rr.rrr r?r)r$rr rrrrr~0s$z8RepoPkgsCommand.RemoveOrDistroSyncSubCommand.run_on_repoN)r)r7r8r9r:r&r,rr~rrrrRemoveOrDistroSyncSubCommands rc@s$eZdZdZdZddZddZdS) z+RepoPkgsCommand.RemoveOrReinstallSubCommandz6Implementation of the remove-or-reinstall sub-command.remove-or-reinstallcCs$|jj}d|_d|_d|_d|_dS)NT)rr]r^r`rr)r$r]rrrr,Rs z5RepoPkgsCommand.RemoveOrReinstallSubCommand.configurec Cst|j|jd}|jjs~y|jjd|j|jddWn@tjj k r`t d}t j |Yqtjj k rvYqXd}nvxt|jjD]h}y|jj||j|jddWnBtjj k rt d}t j ||Yqtjj k rYqXd}qW|s tjjt ddS) z?Execute the command with respect to given arguments *cli_args*.FrQT)Z old_reponameZnew_reponame_neqZ remove_naz)No package installed from the repository.zNo match for argument: %szNothing to do.N)rrrr<r|rr}rr.rrr r?rr)r$rr rrrrr~Ys4  z7RepoPkgsCommand.RemoveOrReinstallSubCommand.run_on_repoN)r)r7r8r9r:r&r,r~rrrrRemoveOrReinstallSubCommandMsrc@s$eZdZdZdZddZddZdS) z RepoPkgsCommand.RemoveSubCommandz)Implementation of the remove sub-command.removecCs*|jj}d|_d|_d|_d|_d|_dS)NTF)rr]r^Z allow_erasingr`rr)r$r]rrrr,s z*RepoPkgsCommand.RemoveSubCommand.configurecCsd}|jjsRy|jjd|jWn*tjjk rJtd}t j |YqXd}n`x^|jjD]R}y|jj||jWn4tjjk r}zt j t |WYdd}~Xq\Xd}q\W|st j tddS)z?Execute the command with respect to given arguments *cli_args*.FrQz)No package installed from the repository.TNzNo packages marked for removal.) r<r|rrr}rr.rrr r?strZwarning)r$rr rrrrrr~s  z,RepoPkgsCommand.RemoveSubCommand.run_on_repoN)r)r7r8r9r:r&r,r~rrrrRemoveSubCommand~src@s$eZdZdZd ZddZddZdS) z!RepoPkgsCommand.UpgradeSubCommandz*Implementation of the upgrade sub-command.upgrade upgrade-tocCs$|jj}d|_d|_d|_d|_dS)NT)rr]r^r`rr)r$r]rrrr,s z+RepoPkgsCommand.UpgradeSubCommand.configurec Cst|j|jd}|jjs.|jj|jd}nTxR|jjD]F}y|jj||jWn(tj j k rxt j t d|Yq8Xd}q8W|stj jt ddS)z?Execute the command with respect to given arguments *cli_args*.FTzNo match for argument: %szNo packages marked for upgrade.N)rrrr<r|Z upgrade_allr}rrr.rr r?rr)r$rrrrrr~sz-RepoPkgsCommand.UpgradeSubCommand.run_on_repoN)rr)r7r8r9r:r&r,r~rrrrUpgradeSubCommandsrrepository-packages repo-pkgs repo-packagesrepository-pkgsz7run commands on top of all packages in given repositorycs>tt|jfdd|jD}d|_dd|D|_dS)zInitialize the command.c3s|]}|VqdS)Nr)rsubcmd)rrr sz+RepoPkgsCommand.__init__..NcSsi|]}|jD] }||qqSr)r&)rraliasrrr sz,RepoPkgsCommand.__init__..)rrzr%SUBCMDSr_subcmd_name2obj)r$rZ subcmd_objs)r)rrr%s zRepoPkgsCommand.__init__c Cs`|j}|jdddddtdd|jddddtd d |jd ddd td d |jddddtdd |jddddtdd |jddddtdd |jddddtdd |jddddtdd |jddtjtdtddd d!|jD}d"d!|jD}|jd#dd$|d%j|d&d}|d dddd'ddh}|jd(d)td*||tjtd+d,dS)-Nz--allrrJr@zshow all packages (default))rKrLrMrNrOz --availablerAzshow only available packages)rKrLrMrOz --installedrBzshow only installed packagesz--extrasrCzshow only extras packagesz --updatesrEzshow only upgrades packagesz --upgradesz --autoremoverFzshow only autoremove packagesz--recentrGz#show only recently changed packagesr}ZREPOIDz Repository ID)rSrLrTrOcSsg|]}|jdqS)r)r&)rrrrrrsz1RepoPkgsCommand.set_argparser..cSsg|]}|jD]}|qqSr)r&)rrrrrrrsrZ SUBCOMMANDz, )rSrTrUrOrHr|rQrRzPackage specification)rSrTrUrNrLrO)rVrWrrZ_RepoCallbackEnablerrrZ)r$r)r\Zsubcommand_choicesZsubcommand_choices_allrYrXrrrr*sP         zRepoPkgsCommand.set_argparsercCsy|j|jjd|_Wn>tjjtfk rV}z|jjjtjjWYdd}~XnX|j|j_|jj d|j_ |jj dS)z8Verify whether the command can run with given arguments.rN) rr<rrrrKeyError optparserZ print_usager}r,)r$rrrrr,s  zRepoPkgsCommand.configurecCs|jjdS)z>Execute the command with respect to given arguments *extcmds*.N)rr~)r$rrrr4szRepoPkgsCommand.run)rrrr)r7r8r9r:r"rrrrrrrrrrrrr&rr;r%r*r,r4rrr)rrrz s0) 79>1(# + rzc@s0eZdZdZd ZedZeddZddZ dS) HelpCommandzRA class containing methods needed by the cli to execute the help command. rOzdisplay a helpful usage messagecCs*|jddtdtdjtjjdddS)Ncmd?ZCOMMANDz{prog} command to get help for)r)rSrTrO)rWrr rr r)r)rrrr*szHelpCommand.set_argparsercCsN|jj s|jj|jjkr(|jjjn"|jj|jj}|jjj||dS)N)r<rrZ cli_commandsrZ print_help)r$rrrrr4$s  zHelpCommand.runN)rO) r7r8r9r:r&rr;ror*r4rrrrrs  r)r:Z __future__rrZdnf.cli.option_parserrZdnf.i18nrZdnf.clirZdnf.exceptionsZ dnf.pycompZdnf.utilZloggingrZ getLoggerr r/r0r rr!objectr"r>rerhrprzrrrrrs:       9?$y