ó
Ð²Ebc           @@  sí   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l j j j 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 rÄ d  d l m Z d  d l m Z m Z n  e j e ƒ Z d	 e
 f d
 „  ƒ  YZ d S(   i    (   t   absolute_importN(   t   Command(   t   ERRORt   SUCCESS(   t   CommandErrort   PipError(   t   MYPY_CHECK_RUNNING(   t   Values(   t   Anyt   Listt   CacheCommandc           B@  s†   e  Z d  Z e Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   sw  
    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.
    s˜   
        %prog dir
        %prog info
        %prog list [<pattern>] [--format=[human, abspath]]
        %prog remove <pattern>
        %prog purge
    c         C@  sH   |  j  j d d d d d d d d d d
 d ƒ|  j j d |  j  ƒ d  S(   Ns   --formatt   actiont   storet   destt   list_formatt   defaultt   humant   choicest   abspatht   helps:   Select the output format among: human (default) or abspathi    (   R   R   (   t   cmd_optst
   add_optiont   parsert   insert_option_group(   t   self(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyt   add_options-   s    	c         C@  sÞ   i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6} | j sR t j d ƒ t S| si | d | k rŒ t j d d	 j	 t
 | ƒ ƒ ƒ t S| d } y | | | | d
 ƒ Wn( t k
 rÙ } t j | j d ƒ t SXt S(   Nt   dirt   infot   listt   removet   purges<   pip cache commands can not function since cache is disabled.i    s   Need an action (%s) to perform.s   , i   (   t   get_cache_dirt   get_cache_infot   list_cache_itemst   remove_cache_itemst   purge_cachet	   cache_dirt   loggert   errorR   t   joint   sortedR   t   argsR   (   R   t   optionsR)   t   handlersR   t   e(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyt   run;   s*    



	
c         C@  s)   | r t  d ƒ ‚ n  t j | j ƒ d  S(   Ns   Too many arguments(   R   R%   R   R$   (   R   R*   R)   (    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR   ]   s    c   
      C@  sÔ   | r t  d ƒ ‚ n  t |  j | ƒ ƒ } t |  j | d ƒ ƒ } |  j | d ƒ } |  j | d ƒ } t j | ƒ } t j | ƒ } t j d ƒ j	 d | d | d | d	 | d
 | d | ƒ j
 ƒ  }	 t j |	 ƒ d  S(   Ns   Too many argumentst   *t   httpt   wheelssN  
            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}
        t   http_cache_locationt   http_cache_sizet   num_http_filest   wheels_cache_locationt   package_countt   wheels_cache_size(   R   t   lent   _find_http_filest   _find_wheelst
   _cache_dirt
   filesystemt   format_directory_sizet   textwrapt   dedentt   formatt   stripR%   R   (
   R   R*   R)   R3   t   num_packagesR1   R4   R2   R6   t   message(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR    d   s$    	c         C@  s|   t  | ƒ d k r! t d ƒ ‚ n  | r4 | d } n d } |  j | | ƒ } | j d k rk |  j | ƒ n |  j | ƒ d  S(   Ni   s   Too many argumentsi    R.   R   (   R7   R   R9   R   t   format_for_humant   format_for_abspath(   R   R*   R)   t   patternt   files(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR!   …   s    c         C@  s•   | s t  j d ƒ d  Sg  } xH | D]@ } t j j | ƒ } t j | ƒ } | j d j | | ƒ ƒ q$ Wt  j d ƒ t  j d j	 t
 | ƒ ƒ ƒ d  S(   Ns   Nothing cached.s
    - {} ({})s   Cache contents:
s   
(   R%   R   t   ost   patht   basenameR;   t   format_file_sizet   appendR?   R'   R(   (   R   RF   t   resultst   filenamet   wheelt   size(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyRC   •   s    c         C@  sN   | s
 d  Sg  } x | D] } | j  | ƒ q Wt j d j t | ƒ ƒ ƒ d  S(   Ns   
(   RK   R%   R   R'   R(   (   R   RF   RL   RM   (    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyRD   £   s    c         C@  sÏ   t  | ƒ d k r! t d ƒ ‚ n  | s6 t d ƒ ‚ n  |  j | | d ƒ } | d d k rr | |  j | ƒ 7} n  | s‡ t d ƒ ‚ n  x+ | D]# } t j | ƒ t j d | ƒ qŽ Wt j d t  | ƒ ƒ d  S(	   Ni   s   Too many argumentss   Please provide a patterni    R.   s   No matching packagess
   Removed %ss   Files removed: %s(	   R7   R   R9   R8   RG   t   unlinkR%   t   debugR   (   R   R*   R)   RF   RM   (    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR"   ®   s    c         C@  s(   | r t  d ƒ ‚ n  |  j | d g ƒ S(   Ns   Too many argumentsR.   (   R   R"   (   R   R*   R)   (    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR#   Ä   s    c         C@  s   t  j j | j | ƒ S(   N(   RG   RH   R'   R$   (   R   R*   t   subdir(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR:   Ë   s    c         C@  s"   |  j  | d ƒ } t j | d ƒ S(   NR/   R.   (   R:   R;   t
   find_files(   R   R*   t   http_dir(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR8   Ï   s    c         C@  s>   |  j  | d ƒ } | d | k r' d n d } t j | | ƒ S(   NR0   t   -s   *.whls   -*.whl(   R:   R;   RS   (   R   R*   RE   t	   wheel_dir(    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR9   Ô   s    (   t   __name__t
   __module__t   __doc__t   Truet   ignore_require_venvt   usageR   R-   R   R    R!   RC   RD   R"   R#   R:   R8   R9   (    (    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyR
      s   		"		!							(   t
   __future__R    t   loggingRG   R=   t   pip._internal.utils.filesystemt	   _internalt   utilsR;   t   pip._internal.cli.base_commandR   t   pip._internal.cli.status_codesR   R   t   pip._internal.exceptionsR   R   t   pip._internal.utils.typingR   t   optparseR   t   typingR   R	   t	   getLoggerRW   R%   R
   (    (    (    s9   /tmp/pip-build-UPPWic/pip/pip/_internal/commands/cache.pyt   <module>   s   