
    e                     b    d Z ddlZddlZddlmZ  ej        d          Z G d de          ZdS )aa  
System commands, use to display system information

Usage:
    --cleanup-blobs
    will clean up all blobs

    --cleanup-blobs sha1,sha1
    Diagnose blobs with given sha1

    --diagnose-blobs --channel-names channel1,channel2 --file-name filename.json
    download a json file with information about blobs of the given channels on Anaconda Server


    N   )SubCommandBaserepo_clic                   2    e Zd ZdZd Zd Zd ZddZd ZdS )	
SubCommandsystemc                    | j                                         }d|d         vrt                              d           d S | j        j        1t          | j        j                  dk    r|                                  | j        j        |                     | j        j                   | j        j        rT| j        j	        s| j
                            d           d S |                     | j        j	        | j        j                   d S d S )Nadminrolesz?You are not an admin. This command is only available to admins.r   zplease specify channel names)apiget_current_userloggererrorargscleanup_blobslendelete_blobsdiagnose_blobschannel_nameslog	file_name)self	user_infos     8lib/python3.11/site-packages/repo_cli/commands/system.pymainzSubCommand.main   s   H--//	)G,,,LLQ   F9".3ty7N3O3OST3T3T9".ty67779# 	R9* R=>>>>>##DI$;TY=PQQQQQ		R 	R    c                 &   t          |          dk    rt                              d           d S |d                             d          }| j                            |          }t                              d|d          d|d                     d S )Nr   zNo blobs to cleanup,bloc count: 
blob_count space reclaimed: space_reclaimed)r   r   infosplitr   post_blob_cleanup)r   raw_argsblobsret_vals       r   r   zSubCommand.cleanup_blobs-   s    x==AKK-...F!!#&&(,,U33`7<0``GL]D^``	
 	
 	
 	
 	
r   c                     | j                                         }t                              d|d          d|d                     d S )Nr   r    r!   r"   )r   r   r   r#   )r   r(   s     r   r   zSubCommand.delete_blobs9   sS    (''))`7<0``GL]D^``	
 	
 	
 	
 	
r   Nc                    |                     d          }| j                            |          }|j        st                              d           d S |                                }|4|j                            d                               d          d         }n|}t          |d          5 }t          j
        ||           d d d            n# 1 swxY w Y   t                              d|            d S )Nr   zError while diagnosing blobszContent-Dispositionz	filename=r   wzDiagnosis file saved to )r$   r   r   okr   r   jsonheadersgetopendumpr#   )r   r   args_file_namerespdatafilenamefs          r   r   zSubCommand.diagnose_blobs?   s'   %++C00x&&}55w 	LL7888Fyy{{!|''(=>>DD[QQRSTHH%H(C   	AIdA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	9x99:::::s   /CCCc                    |                     ddt                    | _        | j                            ddt          dd           | j                            d	d
d           | j                            ddt                     | j                            ddd t                     | j                            | j                   d S )Nr   zReturn information about system)helpdescriptionz--cleanup-blobszCleanup blobsstore*)r8   typeactionnargsz--diagnose-blobszDiagnose blobs
store_true)r8   r=   z--channel-nameszList of channel names)r8   r<   z--file-namez	File name)r8   defaultr<   )r   )
add_parser__doc__	subparseradd_argumentstrset_defaultsr   )r   
subparserss     r   rA   zSubCommand.add_parserR   s    #..<' / 
 
 	##  	$ 	
 	
 	
 	##! 	$ 	
 	
 	
 	##( 	$ 	
 	
 	
 	##	 	$ 	
 	
 	
 	###33333r   )N)	__name__
__module____qualname__namer   r   r   r   rA    r   r   r   r      sl        DR R R$

 

 


 
 
; ; ; ;& 4  4  4  4  4r   r   )rB   r-   loggingbaser   	getLoggerr   r   rL   r   r   <module>rP      s                  		:	&	&Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z4r   