<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
ft`A                 @   s   d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dl	Zd dlZd dlZd dlZd dlZd dlZd dlZG dd dejZdS )	    )print_function)commandsCliError)_)NoModuleException)loggerNc                   s*  e Zd ZG dd dejZG dd deZG dd deZG dd deZG d	d
 d
eZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZeeee	e
eeeeeehZehZd%ZedZ fddZdd Zdd  Zd!d" Zd#d$ Z  ZS )&ModuleCommandc                   s,   e Zd Z fddZdd Zdd Z  ZS )zModuleCommand.SubCommandc                s(   t tj| j| tjjj| j| _d S )N)	superr   
SubCommand__init__dnfmodulemodule_baseZ
ModuleBasebase)selfcli)	__class__ /usr/lib/python3.6/module.pyr   (   s    z!ModuleCommand.SubCommand.__init__c       	      C   s   t  }x| jjD ]}| jj|\}}|d kr.q|jr:|jnd}|jrJ|jnd}|jr^|jdksd|jrxt	j
tdj| |jr|jnd}| jjj||dd|}|j| qW |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   __Znsvcapr   r   r"   modulesr   r   r   #_get_modules_from_name_stream_specs,   s    z<ModuleCommand.SubCommand._get_modules_from_name_stream_specsc       	      C   s   t  }t  }x0|D ](}||kr| jjj|r|j|j  qW xB|D ]:}tj|}x*|jtj	gdD ]}|j
rd|j|j
 qdW qDW ||fS )N)Zforms)r   r   r#   ZisModuleActiver%   ZgetArtifactshawkeyZSubjectZget_nevra_possibilitiesZ
FORM_NEVRAr   add)	r   Zuse_modulesZskip_modulesZ	artifactsZ	pkg_namesr   ZartifactZsubjZ	nevra_objr   r   r   _get_module_artifact_names>   s    


z3ModuleCommand.SubCommand._get_module_artifact_names)__name__
__module____qualname__r   r)   r,   __classcell__r   r   )r   r   r
   &   s   r
   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.ListSubCommandlistz,list all module streams, profiles and statesc             C   s   | j j}d|_d|_d S )NT)r   demandsavailable_repossack_activation)r   r2   r   r   r   	configureR   s    z&ModuleCommand.ListSubCommand.configurec             C   s   | j }| jjr&|j| jjtjjj}nV| jj	rF|j| jjtjjj
}n6| jjrf|j| jjtjjj}n|j| jjtjjj}|rt| d S | jjrtd}tjj|d S )NzNo matching Modules to list)r   r   enabledZ_get_brief_descriptionr   libdnfr   ModulePackageContainerZModuleState_ENABLEDdisabledZModuleState_DISABLED	installedZModuleState_INSTALLEDZModuleState_UNKNOWNprintr   r   
exceptionsError)r   Zmodsoutputmsgr   r   r   run_on_moduleW   s(    z*ModuleCommand.ListSubCommand.run_on_moduleN)r1   )r-   r.   r/   aliasesr   summaryr5   r@   r   r   r   r   ListSubCommandM   s   rC   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.InfoSubCommandr    z)print detailed information about a modulec             C   s   | j j}d|_d|_d S )NT)r   r2   r3   r4   )r   r2   r   r   r   r5   t   s    z&ModuleCommand.InfoSubCommand.configurec             C   sf   | j jr| jj| j j}n*| j jr4| jj| j j}n| jj| j j}|rRt| nt	j
jtdd S )NzNo matching Modules to list)r   verboser   Z_get_full_infor   profileZ_get_info_profilesZ	_get_infor;   r   r<   r=   r   )r   r>   r   r   r   r@   y   s    
z*ModuleCommand.InfoSubCommand.run_on_moduleN)r    )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   InfoSubCommando   s   rF   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.EnableSubCommandenablezenable a module streamc             C   s$   | j j}d|_d|_d|_d|_d S )NT)r   r2   r3   r4   	resolving	root_user)r   r2   r   r   r   r5      s
    z(ModuleCommand.EnableSubCommand.configurec             C   s   y| j j| jj W nl tjjk
r } zL| jjj	rb|j
s@|jrD||jrb|jd tjjjkrb|tjt| W Y d d }~X nX d S )Nr   )r   rG   r   r   r   r<   MarkingErrorsr   confstrictno_match_group_specserror_group_specsmodule_depsolv_errorsr7   r   r8   !ModuleErrorType_ERROR_IN_DEFAULTSr   errorstr)r   er   r   r   r@      s    
z,ModuleCommand.EnableSubCommand.run_on_moduleN)rG   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   EnableSubCommand   s   rT   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.DisableSubCommanddisablez%disable a module with all its streamsc             C   s$   | j j}d|_d|_d|_d|_d S )NT)r   r2   r3   r4   rH   rI   )r   r2   r   r   r   r5      s
    z)ModuleCommand.DisableSubCommand.configurec             C   s   y| j j| jj W nl tjjk
r } zL| jjj	rb|j
s@|jrD||jrb|jd tjjjkrb|tjt| W Y d d }~X nX d S )Nr   )r   rU   r   r   r   r<   rJ   r   rK   rL   rM   rN   rO   r7   r   r8   rP   r   rQ   rR   )r   rS   r   r   r   r@      s    
z-ModuleCommand.DisableSubCommand.run_on_moduleN)rU   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   DisableSubCommand   s   rV   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.ResetSubCommandresetzreset a modulec             C   s$   | j j}d|_d|_d|_d|_d S )NT)r   r2   r3   r4   rH   rI   )r   r2   r   r   r   r5      s
    z'ModuleCommand.ResetSubCommand.configurec             C   sb   y| j j| jj W nH tjjk
r\ } z(| jjj	r>|j
r>|tjt| W Y d d }~X nX d S )N)r   rW   r   r   r   r<   rJ   r   rK   rL   rM   r   rQ   rR   )r   rS   r   r   r   r@      s    
z+ModuleCommand.ResetSubCommand.run_on_moduleN)rW   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   ResetSubCommand   s   rX   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.InstallSubCommandinstallz/install a module profile including its packagesc             C   s$   | j j}d|_d|_d|_d|_d S )NT)r   r2   r3   r4   rH   rI   )r   r2   r   r   r   r5      s
    z)ModuleCommand.InstallSubCommand.configurec             C   sp   y| j j| jj| jjj W nN tjj	k
rj } z.| jjjrL|j
sH|jrL|tjt| W Y d d }~X nX d S )N)r   rY   r   r   r   rK   rL   r   r<   rJ   rM   rN   r   rQ   rR   )r   rS   r   r   r   r@      s    
z-ModuleCommand.InstallSubCommand.run_on_moduleN)rY   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   InstallSubCommand   s   rZ   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	zModuleCommand.UpdateSubCommandr%   z0update packages associated with an active streamc             C   s$   | j j}d|_d|_d|_d|_d S )NT)r   r2   r3   r4   rH   rI   )r   r2   r   r   r   r5      s
    z(ModuleCommand.UpdateSubCommand.configurec             C   s&   | j j| jj}|r"tdj|d S )Nz, )r   Zupgrader   r   r   join)r   Zmodule_specsr   r   r   r@      s    z,ModuleCommand.UpdateSubCommand.run_on_moduleN)r%   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   UpdateSubCommand   s   r\   c               @   s(   e Zd Zd	ZedZdd Zdd ZdS )
zModuleCommand.RemoveSubCommandremoveerasez3remove installed module profiles and their packagesc             C   s0   | j j}d|_d|_d|_d|_d|_d|_d S )NTF)r   r2   Zallow_erasingr3   Zfresh_metadatarH   rI   r4   )r   r2   r   r   r   r5      s    z(ModuleCommand.RemoveSubCommand.configurec       
      C   s   | j j| jj}| jjr| j }| j|t \}}| j| jj	j
 |\}}| jjj j j|d}| jjj j j|d}xF|D ]>}||krtdj|}	tj|	 q| jjj|| jjjd qW |sd S tjtjj|d d S )N)r   z0Package {} belongs to multiple modules, skipping)Z
clean_deps)rM   )r   r]   r   r   allr)   r,   r   r   r#   ZgetModulePackagessackr$   r:   filtermr   r!   r   r    Zgoalr^   rK   Zclean_requirements_on_removerQ   r   r<   rJ   )
r   Zskipped_groupsr&   Zremove_names_from_specr'   Z
keep_namesZremove_queryZ
keep_querypkgr?   r   r   r   r@      s&    
z,ModuleCommand.RemoveSubCommand.run_on_moduleN)r]   r^   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   RemoveSubCommand   s   	rc   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	z ModuleCommand.SwitchToSubCommand	switch-toz7switch a module to a stream and distrosync rpm packagesc             C   s.   | j j}d|_d|_d|_d|_d| jj_d S )NT)	r   r2   r3   r4   rH   rI   r   rK   Zmodule_stream_switch)r   r2   r   r   r   r5     s    z*ModuleCommand.SwitchToSubCommand.configurec             C   sr   y| j j| jj| jjjd W nN tjj	k
rl } z.| jjjrN|j
sJ|jrN|tjt| W Y d d }~X nX d S )N)rL   )r   Z	switch_tor   r   r   rK   rL   r   r<   rJ   rM   rN   r   rQ   rR   )r   rS   r   r   r   r@   "  s    
z.ModuleCommand.SwitchToSubCommand.run_on_moduleN)rd   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   SwitchToSubCommand  s   re   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	z ModuleCommand.ProvidesSubCommandprovideszlist modular packagesc             C   s   | j j}d|_d|_d S )NT)r   r2   r3   r4   )r   r2   r   r   r   r5   0  s    z*ModuleCommand.ProvidesSubCommand.configurec             C   s    | j j| jj}|rt| d S )N)r   Z_what_providesr   r   r;   )r   r>   r   r   r   r@   5  s    z.ModuleCommand.ProvidesSubCommand.run_on_moduleN)rf   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   ProvidesSubCommand+  s   rg   c               @   s(   e Zd ZdZedZdd Zdd ZdS )	z!ModuleCommand.RepoquerySubCommand	repoqueryz#list packages belonging to a modulec             C   s   | j j}d|_d|_d S )NT)r   r2   r3   r4   )r   r2   r   r   r   r5   ?  s    z+ModuleCommand.RepoquerySubCommand.configurec             C   s   t  }x*| jjD ]}| jj|\}}|j| qW | j|t  \}}t  }| jjs\| jj r| j	j
j j j|d}x|D ]}	|jt|	 qzW | jjr| j	j
j j j|d}x|D ]}	|jt|	 qW djt|}
t|
 d S )N)Znevra_strict)r   
)r   r   r   r   r   r%   r,   	availabler:   r   r`   r$   ra   r+   rR   r[   sortedr;   )r   r&   r   r(   r'   Znames_from_specZspec_artifactsZpackage_stringsr$   rb   r>   r   r   r   r@   D  s"    

z/ModuleCommand.RepoquerySubCommand.run_on_moduleN)rh   )r-   r.   r/   rA   r   rB   r5   r@   r   r   r   r   RepoquerySubCommand:  s   rl   r   zInteract with Modules.c                s>   t t| j   fdd| jD }d | _dd |D | _d S )Nc             3   s   | ]}| V  qd S )Nr   ).0subcmd)r   r   r   	<genexpr>d  s    z)ModuleCommand.__init__.<locals>.<genexpr>c             S   s   i | ]}|j D ]
}||qqS r   )rA   )rm   rn   aliasr   r   r   
<dictcomp>f  s   z*ModuleCommand.__init__.<locals>.<dictcomp>)r	   r   r   SUBCMDSrn   _subcmd_name2obj)r   r   Zsubcmd_objs)r   )r   r   r   b  s
    zModuleCommand.__init__c             C   s  |j  }|jdddtdd |jdddtdd |jd	d
dtdd |jdddtdd |jdddtdd |jdddtdd g }g }xHt| jdd dD ]2}|j|jd  |jdj|jd |jpd qW |jdd|ddj	|d |jd d!d"td#d$ d S )%Nz	--enabledr6   
store_truezshow only enabled modules)destactionhelpz
--disabledr9   zshow only disabled modulesz--installedr:   z'show only installed modules or packagesz	--profilerE   zshow profile contentz--availablerj   zshow only available packagesz--allr_   zremove all modular packagesc             S   s
   | j d S )Nr   )rA   )xr   r   r   <lambda>~  s    z-ModuleCommand.set_argparser.<locals>.<lambda>)keyr   z{}: {}r   rn   r   z<modular command>ri   )nargschoicesmetavarrw   r   zmodule-spec*zModule specification)r}   r{   rw   )
Zadd_mutually_exclusive_groupadd_argumentr   rk   rr   appendrA   r!   rB   r[   )r   parserZnarrowsZsubcommand_choicesZsubcommand_helprn   r   r   r   set_argparseri  s8    
"

zModuleCommand.set_argparserc             C   sZ   y| j | jjd  | _W n( ttfk
r@   | jjj  tY nX | j| j_| jj  d S )Nr   )	rs   r   rn   r   KeyErrorr   Z	optparserZprint_usager5   )r   r   r   r   r5     s    

zModuleCommand.configurec             C   s   | j   | jj  d S )N)check_required_argumentrn   r@   )r   r   r   r   run  s    zModuleCommand.runc             C   sR   dd | j D }| jjd |krN| jjsNttdjtjj	| jj
| jjd d S )Nc             S   s   g | ]}|j D ]}|qqS r   )rA   )rm   rn   rp   r   r   r   
<listcomp>  s   z9ModuleCommand.check_required_argument.<locals>.<listcomp>r   z{} {} {}: too few arguments)SUBCMDS_NOT_REQUIRED_ARGr   rn   r   r   r   r!   r   utilZ	MAIN_PROGZcommand)r   Znot_required_argumentr   r   r   r     s    
z%ModuleCommand.check_required_argument)r   )r-   r.   r/   r   Commandr
   rC   rF   rT   rV   rX   rZ   r\   rc   re   rg   rl   rr   r   rA   r   rB   r   r   r5   r   r   r0   r   r   )r   r   r   %   s.   '"%	r   )Z
__future__r   Zdnf.clir   r   Zdnf.i18nr   Zdnf.module.exceptionsr   Zdnf.utilr   r   sysosr*   r7   Zdnf.module.module_baseZdnf.exceptionsr   r   r   r   r   r   <module>   s   