o
    0›i¶#  ã                   @   s”   d dl Z d dlZd dlmZ d dl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)ÚCallable)ÚCommand)ÚERRORÚSUCCESS)ÚCommandErrorÚPipError)Ú
filesystem)Ú	getLogger)Úformat_sizec                   @   sV  e Zd ZdZdZdZd%dd„Zdeee	e
ee gdf f f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   ú^/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/pip/_internal/commands/cache.pyÚadd_options(   s   ú	zCacheCommand.add_optionsc                 C   s   | j | j| j| j| jdœS )N)ÚdirÚinfoÚlistÚremoveÚpurge)Úget_cache_dirÚget_cache_infoÚlist_cache_itemsÚremove_cache_itemsÚpurge_cacher   r   r   r   Úhandler_map4   s   ûzCacheCommand.handler_mapÚoptionsÚargsc              
   C   s¤   |   ¡ }|jst d¡ tS |r|d |vr#t dd t|ƒ¡¡ tS |d }z|| ||dd … ƒ W t	S  tyQ } zt |jd ¡ tW  Y d }~S d }~ww )Nz<pip cache commands can not function since cache is disabled.r   zNeed an action (%s) to perform.z, é   )
r*   Ú	cache_dirÚloggerÚerrorr   ÚjoinÚsortedr   r,   r   )r   r+   r,   r*   r   Úer   r   r   Úrun=   s&   
þü€þ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%   W   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_locationÚ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>   Únum_packagesr;   r<   r?   r=   rA   Úmessager   r   r   r&   ]   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   )rB   r   rD   r   Úformat_for_humanÚformat_for_abspath)r   r+   r,   ÚpatternÚfilesr   r   r   r'   ‡   s   

zCacheCommand.list_cache_itemsrQ   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Úappendr1   r2   )r   rQ   ÚresultsÚfilenameÚwheelÚsizer   r   r   rN   –   s   


zCacheCommand.format_for_humanc                 C   s    |rt  d t|ƒ¡¡ d S d S )NrS   )r/   r!   r1   r2   )r   rQ   r   r   r   rO   £   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 |  |d¡¡}g |¢|¢}	|	D ]%}
z|
 ¡ D ]}|j	dd qt|
 ¡  W n	 ty‹   Y nw t 
d	|
¡ qm|  |d¡}tj |¡r©t |¡ t 
d¡ t dt |ƒt|ƒ¡ t dt |	ƒ¡ d S )Nr-   r5   zPlease provide a patternr   zNo matching packagesr7   z for pattern "ú"z
Removed %sr9   r:   T)Ú
missing_okzselfcheck.jsonz"Removed legacy selfcheck.json filezFiles removed: %s (%s)zDirectories removed: %s)rB   r   rD   rC   r/   ÚwarningrT   ÚstatÚst_sizeÚunlinkÚverboser	   Úsubdirs_without_filesrE   Úsubdirs_without_wheelsÚiterdirÚrmdirÚFileNotFoundErrorrU   Úisfiler#   r!   r   )r   r+   r,   rQ   Úno_matching_msgÚbytes_removedrZ   Ú	http_dirsÚ
wheel_dirsÚdirsÚsubdirÚfileÚselfcheck_jsonr   r   r   r(   §   sH   


ÿþ

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_cachero   c                 C   s   t j |j|¡S )N)rT   rU   r1   r.   )r   r+   ro   r   r   r   rE   à   s   zCacheCommand._cache_dirc                 C   s0   |   |d¡}|   |d¡}t |d¡t |d¡ S )Nr9   r8   r7   ©rE   r	   Ú
find_files)r   r+   Úold_http_dirÚnew_http_dirr   r   r   rC   ã   s
   ÿzCacheCommand._find_http_filesrP   c                 C   s,   |   |d¡}|d|v rdnd }t ||¡S )Nr:   ú-z*.whlz-*.whlrr   )r   r+   rP   Ú	wheel_dirr   r   r   rD   ê   s   zCacheCommand._find_wheels)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úignore_require_venvÚusager   ÚdictÚstrr   r   r"   r*   Úintr4   r%   r&   r'   rN   rO   r(   r)   rE   rC   rD   r   r   r   r   r      s"    
&	*3r   )rT   rH   Úoptparser   Útypingr   Úpip._internal.cli.base_commandr   Úpip._internal.cli.status_codesr   r   Úpip._internal.exceptionsr   r   Úpip._internal.utilsr	   Úpip._internal.utils.loggingr
   Úpip._internal.utils.miscr   rx   r/   r   r   r   r   r   Ú<module>   s    