a !cA@sddlmZddlmZmZddlmZddlmZddl m Z ddl Z ddl Z ddl Z ddlZddlZddlZ ddlZ GdddejZdS) )print_function)commandsCliError)_)NoModuleException)loggerNc s*eZdZGdddejZGdddeZGdddeZGdddeZGd d d eZ Gd d d eZ Gd ddeZ GdddeZ GdddeZ GdddeZGdddeZGdddeZeeee e e e e eeeh ZehZdZedZfddZddZdd Zd!d"Zd#d$ZZS)% ModuleCommandcs,eZdZfddZddZddZZS)zModuleCommand.SubCommandcs(ttj||tjj|j|_dSN) superr SubCommand__init__dnfmodule module_baseZ ModuleBasebase)selfcli __class__;/usr/lib/python3.9/site-packages/dnf/cli/commands/module.pyr (sz!ModuleCommand.SubCommand.__init__c Cst}|jjD]}|j|\}}|dur,q|jr8|jnd}|jrH|jnd}|jr\|jdksb|jrvt t d ||j r|j nd}|jj||dd|}||q|S)NzjOnly module name, stream, architecture or profile is used. Ignoring unneeded information in argument: '{}')setopts module_specr _get_modulesnamestreamversioncontextrinforformatarchr_moduleContainerqueryupdate) rmodules_from_specsr__Znsvcaprrr#modulesrrr#_get_modules_from_name_stream_specs,s   z||fS)N)Zforms) rrr$ZisModuleActiver&Z getArtifactshawkeyZSubjectZget_nevra_possibilitiesZ FORM_NEVRAradd) rZ use_modulesZ skip_modulesZ artifactsZ pkg_namesrZartifactZsubjZ nevra_objrrr_get_module_artifact_names>s  z3ModuleCommand.SubCommand._get_module_artifact_names)__name__ __module__ __qualname__r r*r- __classcell__rrrrr &s r c@s(eZdZdZedZddZddZdS)zModuleCommand.ListSubCommand)listz,list all module streams, profiles and statescCs|jj}d|_d|_dSNTrdemandsavailable_repossack_activationrr5rrr configureRsz&ModuleCommand.ListSubCommand.configurecCs|j}|jjr&||jjtjjj}nV|jj rF||jjtjjj }n6|jj rf||jjtjjj }n||jjtjjj }|rt|dS|jjrtd}tj|dSNzNo matching Modules to list)rrenabledZ_get_brief_descriptionrlibdnfrModulePackageContainerZModuleState_ENABLEDdisabledZModuleState_DISABLED installedZModuleState_INSTALLEDZModuleState_UNKNOWNprintrr exceptionsError)rZmodsoutputmsgrrr run_on_moduleWs0z*ModuleCommand.ListSubCommand.run_on_moduleNr.r/r0aliasesrsummaryr9rErrrrListSubCommandMsrIc@s(eZdZdZedZddZddZdS)zModuleCommand.InfoSubCommand)r!z)print detailed information about a modulecCs|jj}d|_d|_dSr3r4r8rrrr9tsz&ModuleCommand.InfoSubCommand.configurecCsf|jjr|j|jj}n*|jjr4|j|jj}n|j|jj}|rRt|nt j t ddSr:) rverboserZ_get_full_inforprofileZ_get_info_profilesZ _get_infor@r rArBrrrCrrrrEys z*ModuleCommand.InfoSubCommand.run_on_moduleNrFrrrrInfoSubCommandosrMc@s(eZdZdZedZddZddZdS)zModuleCommand.EnableSubCommand)enablezenable a module streamcCs$|jj}d|_d|_d|_d|_dSr3rr5r6r7 resolving root_userr8rrrr9s z(ModuleCommand.EnableSubCommand.configurec Csz|j|jjWnntjjy}zR|jjj r`|j s>|j rB||j r`|j dt jjjkr`|tt|WYd}~n d}~00dSN)rrNrrr rA MarkingErrorsrconfstrictno_match_group_specserror_group_specsmodule_depsolv_errorsr<rr=!ModuleErrorType_ERROR_IN_DEFAULTSrerrorstrrerrrrEs  z,ModuleCommand.EnableSubCommand.run_on_moduleNrFrrrrEnableSubCommandsr_c@s(eZdZdZedZddZddZdS)zModuleCommand.DisableSubCommand)disablez%disable a module with all its streamscCs$|jj}d|_d|_d|_d|_dSr3rOr8rrrr9s z)ModuleCommand.DisableSubCommand.configurec Csz|j|jjWnntjjy}zR|jjj r`|j s>|j rB||j r`|j dt jjjkr`|tt|WYd}~n d}~00dSrR)rr`rrr rArTrrUrVrWrXrYr<rr=rZrr[r\r]rrrrEs  z-ModuleCommand.DisableSubCommand.run_on_moduleNrFrrrrDisableSubCommandsrac@s(eZdZdZedZddZddZdS)zModuleCommand.ResetSubCommand)resetzreset a modulecCs$|jj}d|_d|_d|_d|_dSr3rOr8rrrr9s z'ModuleCommand.ResetSubCommand.configurec Csdz|j|jjWnJtjjy^}z.|jjj r<|j r<|t t |WYd}~n d}~00dSr )rrbrrr rArTrrUrVrWrr[r\r]rrrrEs z+ModuleCommand.ResetSubCommand.run_on_moduleNrFrrrrResetSubCommandsrcc@s(eZdZdZedZddZddZdS)zModuleCommand.InstallSubCommand)installz/install a module profile including its packagescCs$|jj}d|_d|_d|_d|_dSr3rOr8rrrr9s z)ModuleCommand.InstallSubCommand.configurec Csrz|j|jj|jjjWnPtjj yl}z4|jjjrJ|j sF|j rJ|t t|WYd}~n d}~00dSr )rrdrrrrUrVr rArTrWrXrr[r\r]rrrrEs  z-ModuleCommand.InstallSubCommand.run_on_moduleNrFrrrrInstallSubCommandsrec@s(eZdZdZedZddZddZdS)zModuleCommand.UpdateSubCommand)r&z0update packages associated with an active streamcCs$|jj}d|_d|_d|_d|_dSr3rOr8rrrr9s z(ModuleCommand.UpdateSubCommand.configurecCs&|j|jj}|r"td|dS)Nz, )rZupgraderrrjoin)rZ module_specsrrrrEsz,ModuleCommand.UpdateSubCommand.run_on_moduleNrFrrrrUpdateSubCommandsrgc@s(eZdZdZedZddZddZdS)zModuleCommand.RemoveSubCommand)removeerasez3remove installed module profiles and their packagescCs0|jj}d|_d|_d|_d|_d|_d|_dS)NTF)rr5Z allow_erasingr6Zfresh_metadatarPrQr7r8rrrr9sz(ModuleCommand.RemoveSubCommand.configurec Cs|j|jj}|jjr|}||t\}}||jj |\}}|jj j|d}|jj j|d}|D]>}||vrtd|} t| q~|jjj||jjjdq~|sdSttjj|ddS)Nrz0Package {} belongs to multiple modules, skipping)Z clean_deps)rW)rrhrrallr*r-rrr$ZgetModulePackagessackr%r?filtermrr"rr!ZgoalrirUZclean_requirements_on_remover[r rArT) rZskipped_groupsr'Zremove_names_from_specr(Z keep_namesZ remove_queryZ keep_querypkgrDrrrrEs.   z,ModuleCommand.RemoveSubCommand.run_on_moduleNrFrrrrRemoveSubCommands roc@s(eZdZdZedZddZddZdS)z ModuleCommand.SwitchToSubCommand)z switch-toz7switch a module to a stream and distrosync rpm packagescCs.|jj}d|_d|_d|_d|_d|jj_dSr3) rr5r6r7rPrQrrUZmodule_stream_switchr8rrrr9s z*ModuleCommand.SwitchToSubCommand.configurec Cstz|jj|jj|jjjdWnPtjj yn}z4|jjjrL|j sH|j rL|t t|WYd}~n d}~00dS)N)rV)rZ switch_torrrrUrVr rArTrWrXrr[r\r]rrrrE"s  z.ModuleCommand.SwitchToSubCommand.run_on_moduleNrFrrrrSwitchToSubCommandsrpc@s(eZdZdZedZddZddZdS)z ModuleCommand.ProvidesSubCommand)Zprovideszlist modular packagescCs|jj}d|_d|_dSr3r4r8rrrr90sz*ModuleCommand.ProvidesSubCommand.configurecCs |j|jj}|rt|dSr )rZ_what_providesrrr@rLrrrrE5sz.ModuleCommand.ProvidesSubCommand.run_on_moduleNrFrrrrProvidesSubCommand+srqc@s(eZdZdZedZddZddZdS)z!ModuleCommand.RepoquerySubCommand)Z repoqueryz#list packages belonging to a modulecCs|jj}d|_d|_dSr3r4r8rrrr9?sz+ModuleCommand.RepoquerySubCommand.configurec Cst}|jjD]}|j|\}}||q||t\}}t}|jjsV|jjs|j j j |d}|D]} | t| qr|jjr|j j j |d}|D]} | t| qdt|} t| dS)N)Z nevra_strictrj )rrrrrr&r- availabler?rrlr%rmr,r\rfsortedr@) rr'rr)r(Znames_from_specZspec_artifactsZpackage_stringsr%rnrCrrrrEDs$  z/ModuleCommand.RepoquerySubCommand.run_on_moduleNrFrrrrRepoquerySubCommand:sru)rzInteract with Modules.cs>tt|fdd|jD}d|_dd|D|_dS)Nc3s|]}|VqdSr r).0subcmdrrr dz)ModuleCommand.__init__..cSsi|]}|jD] }||qqSrrGrvrwaliasrrr fsz*ModuleCommand.__init__..)r rr SUBCMDSrw_subcmd_name2obj)rrZ subcmd_objsrrxrr bs zModuleCommand.__init__cCs|}|jdddtdd|jdddtdd|jd d dtd d|jd d dtdd|jdddtdd|jdddtddg}g}t|jdddD]2}||jd|d|jd|jpdq|jdd|dd |d|jd d!d"td#d$dS)%Nz --enabledr; store_truezshow only enabled modules)destactionhelpz --disabledr>zshow only disabled modulesz --installedr?z'show only installed modules or packagesz --profilerKzshow profile contentz --availablerszshow only available packagesz--allrkzremove all modular packagescSs |jdSNrr{)xrrr~rzz-ModuleCommand.set_argparser..)keyrz{}: {}rrwrSzrr)nargschoicesmetavarrrz module-spec*zModule specification)rrr) add_mutually_exclusive_group add_argumentrrtrappendrGr"rHrf)rparserZnarrowsZsubcommand_choicesZsubcommand_helprwrrr set_argparserisH    zModuleCommand.set_argparserc CsXz|j|jjd|_Wn&ttfy>|jjtYn0|j|j_|jdSr) rrrwrKeyErrorrZ optparser print_usager9rrrrr9s   zModuleCommand.configurecCs||jdSr )check_required_argumentrwrErrrrrunszModuleCommand.runcCsRdd|jD}|jjd|vrN|jjsNttdtjj |jj |jjddS)NcSsg|]}|jD]}|qqSrr{r|rrr s z9ModuleCommand.check_required_argument..rz{} {} {}: too few arguments) SUBCMDS_NOT_REQUIRED_ARGrrwrrrr"r utilZ MAIN_PROGZcommand)rZnot_required_argumentrrrrs z%ModuleCommand.check_required_argument)r.r/r0rCommandr rIrMr_rarcrergrorprqrurrrGrrHr rr9rrr1rrrrr%s0'"%  r)Z __future__rZdnf.clirrZdnf.i18nrZdnf.module.exceptionsrZdnf.utilrr sysosr+r<Zdnf.module.module_baseZdnf.exceptionsrrrrrrs