
     h                         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e          ZdS )    N)Values)AnyList)Command)ERRORSUCCESS)CommandErrorPipError)
filesystem)	getLogger)format_sizec                   j   e Zd ZdZdZdZddZdedee	         de
fd	Zdedee         ddfd
Zdedee         ddfdZdedee         ddfdZdee	         ddfdZdee	         ddfdZdedee         ddfdZdedee         ddfdZdede	de	fdZdedee	         fdZdede	dee	         f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                     | j                             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)selfs    [/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/pip/_internal/commands/cache.pyadd_optionszCacheCommand.add_options(   sU      (M 	! 	
 	
 	
 	''4=99999    optionsargsc                    | j         | j        | j        | j        | j        d}|j        s!t                              d           t          S |r
|d         |vrBt                              dd	                    t          |                               t          S |d         }	  ||         ||dd                     nC# t          $ r6}t                              |j        d                    t          cY d }~S d }~ww xY wt          S )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   es         r    runzCacheCommand.run4   s   %')-%
 
   	LLWXXXL  	tAwh..LL1		&**++   La	HVWd122h//// 	 	 	LL###LLLLLL	 s   !B< <
C<+C71C<7C<c                 f    |rt          d          t                              |j                   d S )NToo many arguments)r	   r2   r'   r1   r   r#   r$   s      r    r,   zCacheCommand.get_cache_dirT   s4     	53444G%&&&&&r"   c           	         |rt          d          t          |                     |                    }t          |                     |d                    }|                     |d          }|                     |d          }|                     |d          }t          j        t          j        |          t          j        |          z             }t          j        |          }	t          j
        d                              |||||||	                                          }
t                              |
           d S )Nr:   *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stripr2   r'   )r   r#   r$   rD   num_packagesrA   rB   rE   rC   rG   messages              r    r-   zCacheCommand.get_cache_infoZ   sB    	53444T227;;<<4,,Wc::;;"oogyAA"&//'6"B"B $ B B$0%&9::'(?@@A
 
 '<=RSS O
 
 V$7(? /-&;*"3    UWW+ 	0 	Gr"   c                     t          |          dk    rt          d          |r	|d         }nd}|                     ||          }|j        dk    r|                     |           d S |                     |           d S )Nr+   r:   r   r=   r   )rH   r	   rJ   r   format_for_humanformat_for_abspath)r   r#   r$   patternfiless        r    r.   zCacheCommand.list_cache_items   s    t99q==3444 	1gGGG!!'733'))!!%(((((##E*****r"   rX   c                    |st                               d           d S g }|D ]Q}t          j                            |          }t          j        |          }|                    d| d| d           Rt                               d           t                               d                    t          |                               d S )NzNo locally built wheels cached.z - z ()zCache contents:

)
r2   r'   ospathbasenamer   format_file_sizeappendr4   r5   )r   rX   resultsfilenamewheelsizes         r    rU   zCacheCommand.format_for_human   s     	KK9:::F 	3 	3HG$$X..E.x88DNN111$1112222'(((DIIfWoo../////r"   c                     |r<t                               d                    t          |                               d S d S )Nr[   )r2   r'   r4   r5   )r   rX   s     r    rV   zCacheCommand.format_for_abspath   s>     	2KK		&--0011111	2 	2r"   c                 X   t          |          dk    rt          d          |st          d          |                     ||d                   }d}|d         dk    r||                     |          z  }n|d|d          dz  }|st                              |           d}|D ]M}|t          j        |          j        z  }t          j	        |           t          
                    d	|           Nt                              d
t          |          t          |                     d S )Nr+   r:   zPlease provide a patternr   zNo matching packagesr=   z for pattern ""z
Removed %szFiles removed: %s (%s))rH   r	   rJ   rI   r2   warningr\   statst_sizeunlinkverboser'   r   )r   r#   r$   rX   no_matching_msgbytes_removedrb   s          r    r/   zCacheCommand.remove_cache_items   s/   t99q==3444 	;9:::!!'473307c>>T**7333EE :Q::::O 	,NN?+++ 	3 	3HRWX..66MIhNN<2222,c%jj+m:T:TUUUUUr"   c                 R    |rt          d          |                     |dg          S )Nr:   r=   )r	   r/   r;   s      r    r0   zCacheCommand.purge_cache   s1     	53444&&w666r"   subdirc                 L    t           j                            |j        |          S )N)r\   r]   r4   r1   )r   r#   rp   s      r    rK   zCacheCommand._cache_dir   s    w||G-v666r"   c                     |                      |d          }|                      |d          }t          j        |d          t          j        |d          z   S )Nr?   r>   r=   rK   r   
find_files)r   r#   old_http_dirnew_http_dirs       r    rI   zCacheCommand._find_http_files   sV    w77w	::$\377*:O#;
 ;
 
 	
r"   rW   c                 n    |                      |d          }|d|v rdndz   }t          j        ||          S )Nr@   -z*.whlz-*.whlrs   )r   r#   rW   	wheel_dirs       r    rJ   zCacheCommand._find_wheels   s@    OOGX66	$ wWWHE$Y888r"   )r   N)__name__
__module____qualname____doc__ignore_require_venvusager!   r   r   strintr8   r   r,   r-   r.   rU   rV   r/   r0   rK   rI   rJ    r"   r    r   r      s          E
: 
: 
: 
:6 c s    @'V '49 ' ' ' ' '(f (DI ($ ( ( ( (T+ +d3i +D + + + +0d3i 0D 0 0 0 02S	 2d 2 2 2 2V& VS	 Vd V V V V676 7c 7t 7 7 7 77& 7# 7# 7 7 7 7
 
49 
 
 
 
9F 9S 9T#Y 9 9 9 9 9 9r"   r   )r\   rN   optparser   typingr   r   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   rz   r2   r   r   r"   r    <module>r      s   				                2 2 2 2 2 2 9 9 9 9 9 9 9 9 ; ; ; ; ; ; ; ; * * * * * * 1 1 1 1 1 1 0 0 0 0 0 0	8		T9 T9 T9 T9 T97 T9 T9 T9 T9 T9r"   