a
    !c]                     @   sl   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)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   sH   | j j}d|_d|_d|_d|_t| j| j  | j	j
sDt| 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_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  qqt
td| j jj| W Y d }~qd }~0  tjjy } z`|jD ]L}d}| j j|}|rVtd	| }td
}t
|| j jj|| q.W Y d }~qd }~0  tjj	y   Y q0 d}q|st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>L       z(ReinstallCommand.run.<locals>.<listcomp>z(Package %s available, but not installed. z
 (from %s)z%Installed package %s%s not available.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.option_parserr   Zdnf.i18nr   Zdnf.exceptionsr   ZloggingZ	getLoggerr%   ZCommandr   r   r   r   r   <module>   s   
