o
    èhd  ã                   @   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  m	  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 eeƒZG dd	„ d	eƒZdS )
é    N)ÚValues)ÚAnyÚList)ÚCommand)ÚERRORÚSUCCESS)ÚCommandErrorÚPipError)Ú	getLoggerc                   @   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   úX/var/www/html/olx_land/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¡}t |¡}t |¡}t d¡j	||||||d 
¡ }	t |	¡ d S )Nr3   Ú*ÚhttpÚwheelsa†  
                    Package index page cache location: {http_cache_location}
                    Package index page cache size: {http_cache_size}
                    Number of HTTP files: {num_http_files}
                    Wheels location: {wheels_cache_location}
                    Wheels size: {wheels_cache_size}
                    Number of wheels: {package_count}
                )Ú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_dirÚ
filesystemÚformat_directory_sizeÚtextwrapÚdedentÚformatÚstripr,   r!   )
r   r   r   r:   Únum_packagesr8   r;   r9   r=   Úmessager   r   r   r'   Z   s,   

ÿ
ðí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%   r3   r   r5   r   )r>   r   r@   r   Úformat_for_humanÚformat_for_abspath)r   r   r   ÚpatternÚfilesr   r   r   r(   ~   s   

zCacheCommand.list_cache_itemsrM   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Nothing cached.z - z (ú)zCache contents:
Ú
)
r,   r!   ÚosÚpathÚbasenamerB   Úformat_file_sizeÚappendr.   r/   )r   rM   ÚresultsÚfilenameÚwheelÚsizer   r   r   rJ      s   


zCacheCommand.format_for_humanc                 C   s8   |sd S g }|D ]}|  |¡ qt d t|ƒ¡¡ d S )NrO   )rT   r,   r!   r.   r/   )r   rM   rU   rV   r   r   r   rK   š   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 ¡7 }|s8t |¡ |D ]}t |¡ t 	d|¡ q:t 
d	t |ƒ¡ d S )
Nr%   r3   zPlease provide a patternr   zNo matching packagesr5   z for pattern "{}"z
Removed %szFiles removed: %s)r>   r   r@   r?   rF   r,   ÚwarningrP   ÚunlinkÚverboser!   )r   r   r   rM   Úno_matching_msgrV   r   r   r   r)   ¤   s   

zCacheCommand.remove_cache_itemsc                 C   s   |rt dƒ‚|  |dg¡S )Nr3   r5   )r   r)   r4   r   r   r   r*   ½   s   zCacheCommand.purge_cacheÚsubdirc                 C   s   t j |j|¡S )N)rP   rQ   r.   r+   )r   r   r]   r   r   r   rA   Ã   s   zCacheCommand._cache_dirc                 C   s   |   |d¡}t |d¡S )Nr6   r5   ©rA   rB   Ú
find_files)r   r   Úhttp_dirr   r   r   r?   Æ   s   zCacheCommand._find_http_filesrL   c                 C   s,   |   |d¡}|d|v rdnd }t ||¡S )Nr7   ú-z*.whlz-*.whlr^   )r   r   rL   Ú	wheel_dirr   r   r   r@   Ê   s   zCacheCommand._find_wheels)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úignore_require_venvÚusager   r   r   ÚstrÚintr2   r   r&   r'   r(   rJ   rK   r)   r*   rA   r?   r@   r   r   r   r   r      s     
 $
r   )rP   rD   Úoptparser   Útypingr   r   Úpip._internal.utils.filesystemÚ	_internalÚutilsrB   Úpip._internal.cli.base_commandr   Úpip._internal.cli.status_codesr   r   Úpip._internal.exceptionsr   r	   Úpip._internal.utils.loggingr
   rc   r,   r   r   r   r   r   Ú<module>   s    