
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<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ƒ}|rŒt|ƒ d S | jjr¨t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r¦tdƒj|ƒ}	tj|	ƒ q€| jjj|| jjjd� q€W |sÊd 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|	ƒƒ q¶W 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pÔdƒƒ q¨W |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   