a
    ˆ�ÁjÄ  ã                   @   sx   d dl mZ d dl mZ d dl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e d¡ZG d	d
„ d
ejƒZdS )é    )Úabsolute_import)Úunicode_literals)Úcommands)ÚCleanCommandLock)ÚOptionParser)Ú_NÚdnfc                   @   s8   e Zd ZdZdZedƒZedd„ ƒZdd„ Z	dd	„ Z
d
S )ÚReinstallCommandzSA class containing methods needed by the cli to execute the reinstall command.
    )Ú	reinstallZreizreinstall a packagec                 C   s"   | j ddtdƒtjtdƒd� d S )NÚpackagesú+zPackage to reinstallZPACKAGE)ÚnargsÚhelpÚactionÚmetavar)Úadd_argumentr   r   ZParseSpecGroupFileCallback)Úparser© r   ú>/usr/lib/python3.9/site-packages/dnf/cli/commands/reinstall.pyÚset_argparser)   s    þzReinstallCommand.set_argparserc                 C   sP   | j j}d|_d|_d|_d|_tj|_t	 
| j| j ¡ | jjsLt	 | j¡ dS )a  Verify that conditions are met so that this command can
        run.  These include that the program is being run by the root
        user, that there are enabled repositories with gpg keys, and
        that this command is called with appropriate arguments.
        TN)ZcliÚdemandsZsack_activationZavailable_reposZ	resolvingZ	root_userr   ZREADZclean_command_lockr   Z_checkGPGKeyÚbaseÚoptsÚ	filenamesZ_checkEnabledRepo)Úselfr   r   r   r   Ú	configure/   s    zReinstallCommand.configurec                 C   sÖ  d}| j j| jjd| j jjd�D ]N}z| j  |¡ W n4 tjj	yh   t
 tdƒ| j jj |j¡¡ Y q 0 d}q | jjdd„ | jjD ƒ D �].}z| j  |¡ W �n tjj�y } zT|jD ]$}t
 tdƒ| jj |j¡¡  qäq¾t
 tdƒ| j jj |¡¡ W Y d }~qŠd }~0  tjj�y� } z`|jD ]L}d}| j j |¡}|�rVtd	ƒ| }td
ƒ}t
 || j jj |¡|¡ �q.W Y d }~qŠd }~0  tjj	�y´   d�s°J dƒ‚Y qŠ0 d}qŠ|�sÒtj tdƒ¡‚d S )NF)ÚstrictÚprogresszNo match for argument: %sTc                 S   s   g | ]}d | ‘qS )ú@r   )Ú.0Úxr   r   r   Ú
<listcomp>N   ó    z(ReinstallCommand.run.<locals>.<listcomp>z(Package %s available, but not installed.Ú z
 (from %s)z%Installed package %s%s not available.z+Only the above marking errors are expected.z!No packages marked for reinstall.)r   Zadd_remote_rpmsr   r   Úoutputr   Zpackage_reinstallr   Ú
exceptionsZMarkingErrorÚloggerÚinfor   ZtermZboldÚlocationZ	pkg_specsZ	grp_specsr
   ZPackagesNotInstalledErrorr   ÚnameZPackagesNotAvailableErrorÚhistoryZrepoÚError)r   ZdoneZpkgZpkg_specÚerrZxmsgZpkgrepoÚmsgr   r   r   Úrun?   sL    ÿ

ÿ
 

ÿ
ÿ
ÿzReinstallCommand.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úaliasesr   ZsummaryÚstaticmethodr   r   r.   r   r   r   r   r	   "   s   
r	   )Z
__future__r   r   Zdnf.clir   Zdnf.cli.demandr   Zdnf.cli.option_parserr   Zdnf.i18nr   Zdnf.exceptionsr   ZloggingZ	getLoggerr&   ZCommandr	   r   r   r   r   Ú<module>   s   
