3 ©ft`ÙAã@sŽddlmZddlmZmZddlmZddlmZddl m Z ddl Z ddl Z ddl Z ddlZddlZddlZ ddlZ Gdd„dejƒZdS) é)Úprint_function)ÚcommandsÚCliError)Ú_)ÚNoModuleException)ÚloggerNc s*eZdZGdd„dejƒZGdd„deƒZGdd„deƒZGdd„deƒZGd d „d eƒZ Gd d „d eƒZ Gd d„deƒZ Gdd„deƒZ Gdd„deƒZ Gdd„deƒZGdd„deƒZGdd„deƒZeeee e e e e eeeh ZehZd%ZedƒZ‡fdd„Zdd„Zdd „Zd!d"„Zd#d$„Z‡ZS)&Ú ModuleCommandcs,eZdZ‡fdd„Zdd„Zdd„Z‡ZS)zModuleCommand.SubCommandcs(ttj|ƒj|ƒtjjj|jƒ|_dS)N) ÚsuperrÚ SubCommandÚ__init__ÚdnfÚmoduleÚ module_baseZ ModuleBaseÚbase)ÚselfÚcli)Ú __class__©ú/usr/lib/python3.6/module.pyr (sz!ModuleCommand.SubCommand.__init__c Cs°tƒ}x¤|jjD]˜}|jj|ƒ\}}|dkr.q|jr:|jnd}|jrJ|jnd}|jr^|jdksd|jrxt j t dƒj |ƒƒ|j r„|j nd}|jjj||dd|ƒ}|j|ƒqW|S)NÚézjOnly module name, stream, architecture or profile is used. Ignoring unneeded information in argument: '{}'éÿÿÿÿ)ÚsetÚoptsÚ module_specrÚ _get_modulesÚnameÚstreamÚversionÚcontextrÚinforÚformatÚarchrÚ_moduleContainerÚqueryÚupdate) rÚmodules_from_specsrÚ__Znsvcaprrr"ÚmodulesrrrÚ#_get_modules_from_name_stream_specs,s zs   z3ModuleCommand.SubCommand._get_module_artifact_names)Ú__name__Ú __module__Ú __qualname__r r)r,Ú __classcell__rr)rrr &s r c@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.ListSubCommandÚlistz,list all module streams, profiles and statescCs|jj}d|_d|_dS)NT)rÚdemandsÚavailable_reposÚsack_activation)rr2rrrÚ configureRsz&ModuleCommand.ListSubCommand.configurecCs¬|j}|jjr&|j|jjtjjjƒ}nV|jj rF|j|jjtjjj ƒ}n6|jj rf|j|jjtjjj ƒ}n|j|jjtjjj ƒ}|rŒt|ƒdS|jjr¨tdƒ}tjj|ƒ‚dS)NzNo matching Modules to list)rrÚenabledZ_get_brief_descriptionrÚlibdnfr ÚModulePackageContainerZModuleState_ENABLEDÚdisabledZModuleState_DISABLEDÚ installedZModuleState_INSTALLEDZModuleState_UNKNOWNÚprintrr Ú exceptionsÚError)rZmodsÚoutputÚmsgrrrÚ run_on_moduleWs(z*ModuleCommand.ListSubCommand.run_on_moduleN)r1)r-r.r/ÚaliasesrÚsummaryr5r@rrrrÚListSubCommandMsrCc@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.InfoSubCommandr z)print detailed information about a modulecCs|jj}d|_d|_dS)NT)rr2r3r4)rr2rrrr5tsz&ModuleCommand.InfoSubCommand.configurecCsf|jjr|jj|jjƒ}n*|jjr4|jj|jjƒ}n|jj|jjƒ}|rRt|ƒnt j j t dƒƒ‚dS)NzNo matching Modules to list) rÚverboserZ_get_full_inforÚprofileZ_get_info_profilesZ _get_infor;r r<r=r)rr>rrrr@ys z*ModuleCommand.InfoSubCommand.run_on_moduleN)r )r-r.r/rArrBr5r@rrrrÚInfoSubCommandosrFc@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.EnableSubCommandÚenablezenable a module streamcCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4Ú resolvingÚ root_user)rr2rrrr5Šs z(ModuleCommand.EnableSubCommand.configurecCs†y|jj|jjƒWnltjjk r€}zL|jjj rb|j s@|j rD|‚|j rb|j dt jjjkrb|‚tjt|ƒƒWYdd}~XnXdS)Nr)rrGrrr r<Ú MarkingErrorsrÚconfÚstrictÚno_match_group_specsÚerror_group_specsÚmodule_depsolv_errorsr7r r8Ú!ModuleErrorType_ERROR_IN_DEFAULTSrÚerrorÚstr)rÚerrrr@‘s   z,ModuleCommand.EnableSubCommand.run_on_moduleN)rG)r-r.r/rArrBr5r@rrrrÚEnableSubCommand…srTc@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.DisableSubCommandÚdisablez%disable a module with all its streamscCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5¢s z)ModuleCommand.DisableSubCommand.configurecCs†y|jj|jjƒWnltjjk r€}zL|jjj rb|j s@|j rD|‚|j rb|j dt jjjkrb|‚tjt|ƒƒWYdd}~XnXdS)Nr)rrUrrr r<rJrrKrLrMrNrOr7r r8rPrrQrR)rrSrrrr@©s   z-ModuleCommand.DisableSubCommand.run_on_moduleN)rU)r-r.r/rArrBr5r@rrrrÚDisableSubCommand�srVc@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.ResetSubCommandÚresetzreset a modulecCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5ºs z'ModuleCommand.ResetSubCommand.configurecCsby|jj|jjƒWnHtjjk r\}z(|jjj r>|j r>|‚t j t |ƒƒWYdd}~XnXdS)N)rrWrrr r<rJrrKrLrMrrQrR)rrSrrrr@Ás z+ModuleCommand.ResetSubCommand.run_on_moduleN)rW)r-r.r/rArrBr5r@rrrrÚResetSubCommandµsrXc@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.InstallSubCommandÚinstallz/install a module profile including its packagescCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5Ïs z)ModuleCommand.InstallSubCommand.configurecCspy|jj|jj|jjjƒWnNtjj k rj}z.|jjjrL|j sH|j rL|‚t j t|ƒƒWYdd}~XnXdS)N)rrYrrrrKrLr r<rJrMrNrrQrR)rrSrrrr@Ös  z-ModuleCommand.InstallSubCommand.run_on_moduleN)rY)r-r.r/rArrBr5r@rrrrÚInstallSubCommandÊsrZc@s(eZdZdZedƒZdd„Zdd„ZdS) zModuleCommand.UpdateSubCommandr%z0update packages associated with an active streamcCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5äs z(ModuleCommand.UpdateSubCommand.configurecCs&|jj|jjƒ}|r"tdj|ƒƒ‚dS)Nz, )rZupgraderrrÚjoin)rZ module_specsrrrr@ësz,ModuleCommand.UpdateSubCommand.run_on_moduleN)r%)r-r.r/rArrBr5r@rrrrÚUpdateSubCommandßsr\c@s(eZdZd ZedƒZdd„Zdd„ZdS) zModuleCommand.RemoveSubCommandÚremoveÚerasez3remove installed module profiles and their packagescCs0|jj}d|_d|_d|_d|_d|_d|_dS)NTF)rr2Z allow_erasingr3Zfresh_metadatarHrIr4)rr2rrrr5õsz(ModuleCommand.RemoveSubCommand.configurec Csâ|jj|jjƒ}|jjrÂ|jƒ}|j|tƒƒ\}}|j|jj j ƒ|ƒ\}}|jj j ƒj ƒj|d�}|jj j ƒj ƒj|d�}xF|D]>}||kr¦tdƒj|ƒ} tj| ƒq€|jjj||jjjd�q€W|sÊdStjtjj|d�ƒdS)N)rz0Package {} belongs to multiple modules, skipping)Z clean_deps)rM)rr]rrÚallr)r,rrr#ZgetModulePackagesÚsackr$r:Úfiltermrr!rr Zgoalr^rKZclean_requirements_on_removerQr r<rJ) rZskipped_groupsr&Zremove_names_from_specr'Z keep_namesZ remove_queryZ keep_queryÚpkgr?rrrr@þs&  z,ModuleCommand.RemoveSubCommand.run_on_moduleN)r]r^)r-r.r/rArrBr5r@rrrrÚRemoveSubCommandðs rcc@s(eZdZdZedƒZdd„Zdd„ZdS) z ModuleCommand.SwitchToSubCommandú switch-toz7switch a module to a stream and distrosync rpm packagescCs.|jj}d|_d|_d|_d|_d|jj_dS)NT) rr2r3r4rHrIrrKZmodule_stream_switch)rr2rrrr5s z*ModuleCommand.SwitchToSubCommand.configurecCsry|jj|jj|jjjd�WnNtjj k rl}z.|jjjrN|j sJ|j rN|‚t j t|ƒƒWYdd}~XnXdS)N)rL)rZ switch_torrrrKrLr r<rJrMrNrrQrR)rrSrrrr@"s  z.ModuleCommand.SwitchToSubCommand.run_on_moduleN)rd)r-r.r/rArrBr5r@rrrrÚSwitchToSubCommandsrec@s(eZdZdZedƒZdd„Zdd„ZdS) z ModuleCommand.ProvidesSubCommandÚprovideszlist modular packagescCs|jj}d|_d|_dS)NT)rr2r3r4)rr2rrrr50sz*ModuleCommand.ProvidesSubCommand.configurecCs |jj|jjƒ}|rt|ƒdS)N)rZ_what_providesrrr;)rr>rrrr@5sz.ModuleCommand.ProvidesSubCommand.run_on_moduleN)rf)r-r.r/rArrBr5r@rrrrÚProvidesSubCommand+srgc@s(eZdZdZedƒZdd„Zdd„ZdS) z!ModuleCommand.RepoquerySubCommandÚ repoqueryz#list packages belonging to a modulecCs|jj}d|_d|_dS)NT)rr2r3r4)rr2rrrr5?sz+ModuleCommand.RepoquerySubCommand.configurec Csætƒ}x*|jjD]}|jj|ƒ\}}|j|ƒqW|j|tƒƒ\}}tƒ}|jjs\|jj r�|j j j ƒjƒj |d�}x|D]} |j t| ƒƒqzW|jjrÌ|j j j ƒjƒj |d�}x|D]} |j t| ƒƒq¶Wdjt|ƒƒ} t| ƒdS)N)Z nevra_strict)rÚ )rrrrrr%r,Ú availabler:rr`r$rar+rRr[Úsortedr;) rr&rr(r'Znames_from_specZspec_artifactsZpackage_stringsr$rbr>rrrr@Ds"  z/ModuleCommand.RepoquerySubCommand.run_on_moduleN)rh)r-r.r/rArrBr5r@rrrrÚRepoquerySubCommand:srlr zInteract with Modules.cs>tt|ƒjˆƒ‡fdd„|jDƒ}d|_dd„|Dƒ|_dS)Nc3s|]}|ˆƒVqdS)Nr)Ú.0Úsubcmd)rrrú dsz)ModuleCommand.__init__..cSsi|]}|jD] }||“qqSr)rA)rmrnÚaliasrrrú fsz*ModuleCommand.__init__..)r rr ÚSUBCMDSrnÚ_subcmd_name2obj)rrZ subcmd_objs)r)rrr bs zModuleCommand.__init__cCs|jƒ}|jdddtdƒd�|jdddtdƒd�|jd d dtd ƒd�|jd d dtdƒd�|jdddtdƒd�|jdddtdƒd�g}g}xHt|jdd„d�D]2}|j|jdƒ|jdj|jd|jpÔdƒƒq¨W|jdd|ddj |ƒd�|jd d!d"td#ƒd$�dS)%Nz --enabledr6Ú store_truezshow only enabled modules)ÚdestÚactionÚhelpz --disabledr9zshow only disabled modulesz --installedr:z'show only installed modules or packagesz --profilerEzshow profile contentz --availablerjzshow only available packagesz--allr_zremove all modular packagescSs |jdS)Nr)rA)ÚxrrrÚ~sz-ModuleCommand.set_argparser..)Úkeyrz{}: {}rrnrzri)ÚnargsÚchoicesÚmetavarrwrz module-specÚ*zModule specification)r}r{rw) Zadd_mutually_exclusive_groupÚ add_argumentrrkrrÚappendrAr!rBr[)rÚparserZnarrowsZsubcommand_choicesZsubcommand_helprnrrrÚ set_argparseris8       "  zModuleCommand.set_argparserc CsZy|j|jjd|_Wn(ttfk r@|jjjƒt‚YnX|j|j_|jjƒdS)Nr) rsrrnrÚKeyErrorrZ optparserZ print_usager5)rrrrr5‡s   zModuleCommand.configurecCs|jƒ|jjƒdS)N)Úcheck_required_argumentrnr@)rrrrÚrun�szModuleCommand.runcCsRdd„|jDƒ}|jjd|krN|jjsNttdƒjtjj |jj |jjdƒƒ‚dS)NcSsg|]}|jD]}|‘qqSr)rA)rmrnrprrrú •sz9ModuleCommand.check_required_argument..rz{} {} {}: too few arguments) ÚSUBCMDS_NOT_REQUIRED_ARGrrnrrrr!r ÚutilZ MAIN_PROGZcommand)rZnot_required_argumentrrrr„”s z%ModuleCommand.check_required_argument)r )r-r.r/rÚCommandr rCrFrTrVrXrZr\rcrergrlrrr‡rArrBr r‚r5r…r„r0rr)rrr%s.'"%   r)Z __future__rZdnf.clirrZdnf.i18nrZdnf.module.exceptionsrZdnf.utilrr ÚsysÚosr*r7Zdnf.module.module_baseZdnf.exceptionsr‰rrrrrÚs