o
    [h                     @   s   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZmZ d dlmZ d dlmZ d d	lmZ eeZG d
d deZdS )    N)Values)AnyList)Command)ERRORSUCCESS)CommandErrorPipError)
filesystem)	getLogger)format_sizec                   @   s0  e Zd ZdZdZdZd#ddZded	ee	 de
fd
dZded	ee ddfddZded	ee ddfddZded	ee ddfddZdee	 ddfddZdee	 ddfddZded	ee ddfddZded	ee ddfddZdede	de	fddZdedee	 fddZded e	dee	 fd!d"ZdS )$CacheCommandaw  
    Inspect and manage pip's wheel cache.

    Subcommands:

    - dir: Show the cache directory.
    - info: Show information about the cache.
    - list: List filenames of packages stored in the cache.
    - remove: Remove one or more package from the cache.
    - purge: Remove all items from the cache.

    ``<pattern>`` can be a glob expression or a package name.
    Tz
        %prog dir
        %prog info
        %prog list [<pattern>] [--format=[human, abspath]]
        %prog remove <pattern>
        %prog purge
    returnNc                 C   s,   | j jddddddd | jd| j  d S )	Nz--formatstorelist_formathuman)r   abspathz:Select the output format among: human (default) or abspath)actiondestdefaultchoiceshelpr   )cmd_opts
add_optionparserinsert_option_group)self r   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/pip/_internal/commands/cache.pyadd_options(   s   	zCacheCommand.add_optionsoptionsargsc              
   C   s   | j | j| j| j| jd}|jstd tS |r|d |vr,tdd	t
| tS |d }z|| ||dd   W tS  tyZ } zt|jd  tW  Y d }~S d }~ww )N)dirinfolistremovepurgez<pip cache commands can not function since cache is disabled.r   zNeed an action (%s) to perform.z,    )get_cache_dirget_cache_infolist_cache_itemsremove_cache_itemspurge_cache	cache_dirloggererrorr   joinsortedr	   r!   r   )r   r    r!   handlersr   er   r   r   run4   s0   
zCacheCommand.runc                 C   s   |rt dt|j d S )NToo many arguments)r   r.   r#   r-   r   r    r!   r   r   r   r(   T   s   zCacheCommand.get_cache_dirc              	   C   s   |rt dt| |}t| |d}| |d}| |d}| |d}tt|t| }t|}	t	
dj|||||||	d }
t|
 d S )Nr5   *http-v2httpwheelsa  
                    Package index page cache location (pip v23.3+): {http_cache_location}
                    Package index page cache location (older pips): {old_http_cache_location}
                    Package index page cache size: {http_cache_size}
                    Number of HTTP files: {num_http_files}
                    Locally built wheels location: {wheels_cache_location}
                    Locally built wheels size: {wheels_cache_size}
                    Number of locally built wheels: {package_count}
                )http_cache_locationold_http_cache_locationhttp_cache_sizenum_http_fileswheels_cache_locationZpackage_countwheels_cache_size)r   len_find_http_files_find_wheels
_cache_dirr
   r   directory_sizeformat_directory_sizetextwrapdedentformatstripr.   r#   )r   r    r!   r>   Znum_packagesr;   r<   r?   r=   r@   messager   r   r   r)   Z   s8   
zCacheCommand.get_cache_infoc                 C   sX   t |dkr
td|r|d }nd}| ||}|jdkr%| | d S | | d S )Nr'   r5   r   r7   r   )rA   r   rC   r   format_for_humanformat_for_abspath)r   r    r!   patternfilesr   r   r   r*      s   

zCacheCommand.list_cache_itemsrO   c                 C   sp   |s	t d d S g }|D ]}tj|}t|}|d| d| d qt d t dt	| d S )NzNo locally built wheels cached.z - z ()zCache contents:

)
r.   r#   ospathbasenamer
   format_file_sizeappendr0   r1   )r   rO   resultsfilenamewheelsizer   r   r   rL      s   


zCacheCommand.format_for_humanc                 C   s    |rt dt| d S d S )NrQ   )r.   r#   r0   r1   )r   rO   r   r   r   rM      s   zCacheCommand.format_for_abspathc                 C   s   t |dkr
td|std| ||d }d}|d dkr(|| |7 }n
|d|d  d7 }|s9t| d}|D ]}|t|j7 }t	| t
d	| q=td
t |t| d S )Nr'   r5   zPlease provide a patternr   zNo matching packagesr7   z for pattern ""z
Removed %szFiles removed: %s (%s))rA   r   rC   rB   r.   warningrR   statst_sizeunlinkverboser#   r   )r   r    r!   rO   Zno_matching_msgZbytes_removedrX   r   r   r   r+      s"   

zCacheCommand.remove_cache_itemsc                 C   s   |rt d| |dgS )Nr5   r7   )r   r+   r6   r   r   r   r,      s   zCacheCommand.purge_cachesubdirc                 C   s   t j|j|S )N)rR   rS   r0   r-   )r   r    ra   r   r   r   rD      s   zCacheCommand._cache_dirc                 C   s0   |  |d}|  |d}t|dt|d S )Nr9   r8   r7   rD   r
   
find_files)r   r    Zold_http_dirZnew_http_dirr   r   r   rB      s
   zCacheCommand._find_http_filesrN   c                 C   s,   |  |d}|d|v rdnd }t||S )Nr:   -z*.whlz-*.whlrb   )r   r    rN   	wheel_dirr   r   r   rC      s   zCacheCommand._find_wheels)r   N)__name__
__module____qualname____doc__ignore_require_venvusager   r   r   strintr4   r   r(   r)   r*   rL   rM   r+   r,   rD   rB   rC   r   r   r   r   r      s     
 *r   )rR   rG   optparser   typingr   r   pip._internal.cli.base_commandr   pip._internal.cli.status_codesr   r   pip._internal.exceptionsr   r	   Zpip._internal.utilsr
   pip._internal.utils.loggingr   pip._internal.utils.miscr   rf   r.   r   r   r   r   r   <module>   s    