a
    Tsg"                     @   st   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mZ d dl	m
Z
 d dlmZ edZG dd	 d	ejZdS )
    )absolute_import)unicode_literalsN)commands)OptionParser)_dnfc                   @   sX   e Zd ZdZdZedZedd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd ZdS )UpgradeCommandzTA class containing methods needed by the cli to execute the
    update command.
    )upgradeupdatez
upgrade-toz	update-toZlocalupdateZupz,upgrade a package or packages on your systemc                 C   s"   | j ddtdtjtdd d S )NZpackages*zPackage to upgradeZPACKAGE)nargshelpactionmetavar)add_argumentr   r   ZParseSpecGroupFileCallback)parser r   </usr/lib/python3.9/site-packages/dnf/cli/commands/upgrade.pyset_argparser*   s    zUpgradeCommand.set_argparserc                 C   sZ   | j j}d|_d|_d|_d|_t| j| j  | j	j
sDt| j d| _d| _d| _dS )zVerify that conditions are met so that this command can run.

        These include that there are enabled repositories with gpg
        keys, and that this command is being run by the root user.
        TN)clidemandsZsack_activationZavailable_reposZ	resolvingZ	root_userr   Z_checkGPGKeybaseopts	filenamesZ_checkEnabledRepoupgrade_minimalall_securityskipped_grp_specs)selfr   r   r   r   	configure0   s    zUpgradeCommand.configurec                 C   s   | j r
dnd}| jj| j|| jd | jjs<| jjs<| jjrzd}||  O }|| 	 O }|| 
 O }||  O }|rd S n"| jjstjj  | j  d S tjtdd S )NeqZgte)cmp_typeallFzNo packages marked for upgrade.)r   r   Z _populate_update_security_filterr   r   r   	pkg_specs	grp_specs_update_modules_update_files_update_packages_update_groupsZ
releaseverr   r   Zrun_update_query_hookr   Zupgrade_all
exceptionsErrorr   )r   r    resultr   r   r   runB   s"    
zUpgradeCommand.runc                 C   sN   t | jj}tjjr6tjj| j}|	| jj| _
n
| jj| _
t | j
|kS )N)lenr   r#   r   r   ZWITH_MODULESmodulemodule_baseZ
ModuleBaser	   r   )r   Zgroup_specs_numr.   r   r   r   r$   Y   s    
zUpgradeCommand._update_modulesc                 C   s   d}| j jr| jj| j jd| jjjdD ]`}z| j| d}W q( tjj	y } z*t
td| jjj|j W Y d }~q(d }~0 0 q(|S )NF)strictprogressTNo match for argument: %s)r   r   r   Zadd_remote_rpmsoutputr0   Zpackage_upgrader   r(   MarkingErrorloggerinfor   termboldlocation)r   successZpkger   r   r   r%   c   s    

zUpgradeCommand._update_filesc                 C   sp   d}| j jD ]^}z| j| d}W q tjjyh } z(tt	d| jj
j| W Y d }~qd }~0 0 q|S )NFTr1   )r   r"   r   r	   r   r(   r3   r4   r5   r   r2   r6   r7   )r   r9   Zpkg_specr:   r   r   r   r&   p   s    
zUpgradeCommand._update_packagesc                 C   s   | j r| j| j  dS dS )NTF)r   r   Zenv_group_upgrade)r   r   r   r   r'   {   s    zUpgradeCommand._update_groupsN)__name__
__module____qualname____doc__aliasesr   Zsummarystaticmethodr   r   r+   r$   r%   r&   r'   r   r   r   r   r   #   s   

r   )Z
__future__r   r   ZloggingZdnf.exceptionsr   Zdnf.baseZdnf.clir   Zdnf.cli.option_parserr   Zdnf.i18nr   Z	getLoggerr4   ZCommandr   r   r   r   r   <module>   s   
