3 ft`A@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 ZehZd%ZedZfddZddZdd Zd!d"Zd#d$ZZS)& ModuleCommandcs,eZdZfddZddZddZZS)zModuleCommand.SubCommandcs(ttj|j|tjjj|j|_dS)N) superr SubCommand__init__dnfmodule module_baseZ ModuleBasebase)selfcli) __class__/usr/lib/python3.6/module.pyr (sz!ModuleCommand.SubCommand.__init__c Cst}x|jjD]}|jj|\}}|dkr.q|jr:|jnd}|jrJ|jnd}|jr^|jdksd|jrxt j t dj ||j r|j nd}|jjj||dd|}|j|qW|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 zs   z3ModuleCommand.SubCommand._get_module_artifact_names)__name__ __module__ __qualname__r r)r, __classcell__rr)rrr &s r c@s(eZdZdZedZddZddZdS) zModuleCommand.ListSubCommandlistz,list all module streams, profiles and statescCs|jj}d|_d|_dS)NT)rdemandsavailable_repossack_activation)rr2rrr configureRsz&ModuleCommand.ListSubCommand.configurecCs|j}|jjr&|j|jjtjjj}nV|jj rF|j|jjtjjj }n6|jj rf|j|jjtjjj }n|j|jjtjjj }|rt|dS|jjrtd}tjj|dS)NzNo matching Modules to list)rrenabledZ_get_brief_descriptionrlibdnfr ModulePackageContainerZModuleState_ENABLEDdisabledZModuleState_DISABLED installedZModuleState_INSTALLEDZModuleState_UNKNOWNprintrr exceptionsError)rZmodsoutputmsgrrr run_on_moduleWs(z*ModuleCommand.ListSubCommand.run_on_moduleN)r1)r-r.r/aliasesrsummaryr5r@rrrrListSubCommandMsrCc@s(eZdZdZedZddZddZdS) 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 ddS)NzNo matching Modules to list) rverboserZ_get_full_inforprofileZ_get_info_profilesZ _get_infor;r r<r=r)rr>rrrr@ys z*ModuleCommand.InfoSubCommand.run_on_moduleN)r )r-r.r/rArrBr5r@rrrrInfoSubCommandosrFc@s(eZdZdZedZddZddZdS) zModuleCommand.EnableSubCommandenablezenable a module streamcCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4 resolving root_user)rr2rrrr5s z(ModuleCommand.EnableSubCommand.configurecCsy|jj|jjWnltjjk r}zL|jjj rb|j s@|j rD||j rb|j dt jjjkrb|tjt|WYdd}~XnXdS)Nr)rrGrrr r< MarkingErrorsrconfstrictno_match_group_specserror_group_specsmodule_depsolv_errorsr7r r8!ModuleErrorType_ERROR_IN_DEFAULTSrerrorstr)rerrrr@s   z,ModuleCommand.EnableSubCommand.run_on_moduleN)rG)r-r.r/rArrBr5r@rrrrEnableSubCommandsrTc@s(eZdZdZedZddZddZdS) zModuleCommand.DisableSubCommanddisablez%disable a module with all its streamscCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5s z)ModuleCommand.DisableSubCommand.configurecCsy|jj|jjWnltjjk 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@rrrrDisableSubCommandsrVc@s(eZdZdZedZddZddZdS) zModuleCommand.ResetSubCommandresetzreset a modulecCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5s z'ModuleCommand.ResetSubCommand.configurecCsby|jj|jjWnHtjjk 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@rrrrResetSubCommandsrXc@s(eZdZdZedZddZddZdS) zModuleCommand.InstallSubCommandinstallz/install a module profile including its packagescCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5s z)ModuleCommand.InstallSubCommand.configurecCspy|jj|jj|jjjWnNtjj 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@rrrrInstallSubCommandsrZc@s(eZdZdZedZddZddZdS) zModuleCommand.UpdateSubCommandr%z0update packages associated with an active streamcCs$|jj}d|_d|_d|_d|_dS)NT)rr2r3r4rHrI)rr2rrrr5s z(ModuleCommand.UpdateSubCommand.configurecCs&|jj|jj}|r"tdj|dS)Nz, )rZupgraderrrjoin)rZ module_specsrrrr@sz,ModuleCommand.UpdateSubCommand.run_on_moduleN)r%)r-r.r/rArrBr5r@rrrrUpdateSubCommandsr\c@s(eZdZd ZedZddZddZdS) zModuleCommand.RemoveSubCommandremoveerasez3remove installed module profiles and their packagescCs0|jj}d|_d|_d|_d|_d|_d|_dS)NTF)rr2Z allow_erasingr3Zfresh_metadatarHrIr4)rr2rrrr5sz(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]>}||krtdj|} tj| q|jjj||jjjdqW|sdStjtjj|ddS)N)rz0Package {} belongs to multiple modules, skipping)Z clean_deps)rM)rr]rrallr)r,rrr#ZgetModulePackagessackr$r:filtermrr!rr Zgoalr^rKZclean_requirements_on_removerQr r<rJ) rZskipped_groupsr&Zremove_names_from_specr'Z keep_namesZ remove_queryZ keep_querypkgr?rrrr@s&  z,ModuleCommand.RemoveSubCommand.run_on_moduleN)r]r^)r-r.r/rArrBr5r@rrrrRemoveSubCommands rcc@s(eZdZdZedZddZddZdS) 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|jjjdWnNtjj 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@rrrrSwitchToSubCommandsrec@s(eZdZdZedZddZddZdS) z ModuleCommand.ProvidesSubCommandprovideszlist 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@rrrrProvidesSubCommand+srgc@s(eZdZdZedZddZddZdS) z!ModuleCommand.RepoquerySubCommand repoqueryz#list packages belonging to a modulecCs|jj}d|_d|_dS)NT)rr2r3r4)rr2rrrr5?sz+ModuleCommand.RepoquerySubCommand.configurec Cst}x*|jjD]}|jj|\}}|j|qW|j|t\}}t}|jjs\|jj r|j j j jj |d}x|D]} |j t| qzW|jjr|j j j jj |d}x|D]} |j t| qWdjt|} 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@rrrrRepoquerySubCommand:srlr zInteract with Modules.cs>tt|jfdd|jD}d|_dd|D|_dS)Nc3s|]}|VqdS)Nr).0subcmd)rrr dsz)ModuleCommand.__init__..cSsi|]}|jD] }||qqSr)rA)rmrnaliasrrr fsz*ModuleCommand.__init__..)r rr SUBCMDSrn_subcmd_name2obj)rrZ subcmd_objs)r)rrr bs zModuleCommand.__init__cCs|j}|jdddtdd|jdddtdd|jd d dtd d|jd d dtdd|jdddtdd|jdddtddg}g}xHt|jdddD]2}|j|jd|jdj|jd|jpdqW|jdd|ddj |d|jd d!d"td#d$dS)%Nz --enabledr6 store_truezshow only enabled modules)destactionhelpz --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)nargschoicesmetavarrwrz module-spec*zModule specification)r}r{rw) Zadd_mutually_exclusive_group add_argumentrrkrrappendrAr!rBr[)rparserZnarrowsZsubcommand_choicesZsubcommand_helprnrrr set_argparseris8       "  zModuleCommand.set_argparserc CsZy|j|jjd|_Wn(ttfk r@|jjjtYnX|j|j_|jjdS)Nr) rsrrnrKeyErrorrZ optparserZ print_usager5)rrrrr5s   zModuleCommand.configurecCs|j|jjdS)N)check_required_argumentrnr@)rrrrrunszModuleCommand.runcCsRdd|jD}|jjd|krN|jjsNttdjtjj |jj |jjddS)NcSsg|]}|jD]}|qqSr)rA)rmrnrprrr sz9ModuleCommand.check_required_argument..rz{} {} {}: too few arguments) SUBCMDS_NOT_REQUIRED_ARGrrnrrrr!r utilZ MAIN_PROGZcommand)rZnot_required_argumentrrrrs z%ModuleCommand.check_required_argument)r )r-r.r/rCommandr rCrFrTrVrXrZr\rcrergrlrrrrArrBr rr5rrr0rr)rrr%s.'"%   r)Z __future__rZdnf.clirrZdnf.i18nrZdnf.module.exceptionsrZdnf.utilrr sysosr*r7Zdnf.module.module_baseZdnf.exceptionsrrrrrrs