σ
^κWc           @@  sΧ   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z m Z d  d l	 m
 Z
 d  d l m Z m Z m Z m Z m Z d  d l m Z e j e  Z d e f d     YZ d	 e f d
     YZ d S(   i    (   t   absolute_importN(   t   uses_pycachet   WINDOWSt   cache_from_source(   t   UninstallationError(   t   rmtreet   askt   is_localt   renamest   normalize_path(   t
   indent_logt   UninstallPathSetc           B@  sb   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e	 d  Z
 d   Z d	   Z RS(
   sM   A set of file paths to be removed in the uninstallation of a
    requirement.c         C@  s@   t    |  _ t    |  _ i  |  _ | |  _ d  |  _ g  |  _ d  S(   N(   t   sett   pathst   _refuset   ptht   distt   Nonet   save_dirt   _moved_paths(   t   selfR   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt   __init__   s    			c         C@  s
   t  |  S(   ss   
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        (   R   (   R   t   path(    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt
   _permitted   s    c         C@  sΓ   t  j j |  \ } } t  j j t |  t  j j |   } t  j j |  sU d  S|  j |  rw |  j j	 |  n |  j
 j	 |  t  j j |  d d k rΏ t rΏ |  j	 t |   n  d  S(   Ni   s   .py(   t   osR   t   splitt   joinR	   t   normcaset   existsR   R   t   addR   t   splitextR   R   (   R   R   t   headt   tail(    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR   #   s    '"c         C@  sk   t  |  } |  j |  rW | |  j k r@ t |  |  j | <n  |  j | j |  n |  j j |  d  S(   N(   R	   R   R   t   UninstallPthEntriesR   R   (   R   t   pth_filet   entry(    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt   add_pth6   s    c         C@  s   t    } x} t | d t D]i } t g  | D]@ } | j |  oi | t | j t j j   t j j k ^ q,  s | j	 |  q q W| S(   sΤ   Compact a path set to contain the minimal number of paths
        necessary to contain all paths in the set. If /a/path/ and
        /a/path/to/a/file.txt are both in the set, leave only the
        shorter path.t   key(
   R   t   sortedt   lent   anyt
   startswitht   rstripR   R   t   sepR   (   R   R   t   short_pathsR   t	   shortpath(    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt   compact?   s    	Mc         C@  s5   t  j j |  j t  j j |  d j t  j j   S(   Ni   (   R   R   R   R   t
   splitdrivet   lstripR+   (   R   R   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt   _stashM   s    	c      	   C@  s§  |  j  s# t j d |  j j  d St j d |  j j |  j j  t   Vt |  j |  j    } | rs d } n- x | D] } t j |  qz Wt	 d d  } |  j
 rγ t j d  x* |  j |  j
  D] } t j |  qΙ Wn  | d k rt j d d	 d
 d  |  _ xJ | D]B } |  j |  } t j d |  |  j j |  t | |  qWx! |  j j   D] } | j   qgWt j d |  j j |  j j  n  Wd QXd S(   s[   Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True).s7   Can't uninstall '%s'. No files were found to uninstall.Ns   Uninstalling %s-%s:t   ys   Proceed (y/n)? t   ns.   Not removing or modifying (outside of prefix):t   suffixs
   -uninstallt   prefixs   pip-s   Removing file or directory %ss   Successfully uninstalled %s-%s(   R2   R3   (   R   t   loggert   infoR   t   project_namet   versionR
   R&   R.   R   R   t   tempfilet   mkdtempR   R1   t   debugR   t   appendR   R   t   valuest   remove(   R   t   auto_confirmR   t   responseR   t   new_pathR   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR?   Q   s@    	
		c         C@  s§   |  j  d k r) t j d |  j j  t St j d |  j j  x= |  j D]2 } |  j	 |  } t j
 d |  t | |  qI Wx! |  j j   D] } | j   q Wd S(   s1   Rollback the changes previously made by remove().s'   Can't roll back %s; was not uninstalleds   Rolling back uninstall of %ss   Replacing %sN(   R   R   R6   t   errorR   R8   t   FalseR7   R   R1   R<   R   R   R>   t   rollback(   R   R   t   tmp_pathR   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyRE   {   s    c         C@  s5   |  j  d k	 r1 t |  j   d |  _  g  |  _ n  d S(   s?   Remove temporary save dir: rollback will no longer be possible.N(   R   R   R   R   (   R   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt   commit   s    	(   t   __name__t
   __module__t   __doc__R   R   R   R$   R.   R1   RD   R?   RE   RG   (    (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR      s   							*	R!   c           B@  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C@  sG   t  j j |  s% t d |   n  | |  _ t   |  _ d  |  _ d  S(   Ns.   Cannot remove entries from nonexistent file %s(	   R   R   t   isfileR   t   fileR   t   entriesR   t   _saved_lines(   R   R"   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR      s    	c         C@  sX   t  j j |  } t rD t  j j |  d rD | j d d  } n  |  j j |  d  S(   Ni    s   \t   /(   R   R   R   R   R/   t   replaceRM   R   (   R   R#   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR      s    c         C@  sκ   t  j d |  j  t |  j d   } | j   } | |  _ Wd  QXt d   | D  rb d } n d } xS |  j D]H } y. t  j d |  | j | | j	 d   Wqr t
 k
 rΉ qr Xqr Wt |  j d   } | j |  Wd  QXd  S(	   Ns   Removing pth entries from %s:t   rbc         s@  s   |  ] } d  | k Vq d S(   s   
N(    (   t   .0t   line(    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pys	   <genexpr>­   s    s   
s   
s   Removing entry: %ss   utf-8t   wb(   R6   R<   RL   t   opent	   readlinesRN   R(   RM   R?   t   encodet
   ValueErrort
   writelines(   R   t   fht   linest   endlineR#   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR?   §   s    	c         C@  sh   |  j  d  k r& t j d |  j  t St j d |  j  t |  j d   } | j |  j   Wd  QXt	 S(   Ns.   Cannot roll back changes to %s, none were mades!   Rolling %s back to previous stateRT   (
   RN   R   R6   RC   RL   RD   R<   RU   RY   t   True(   R   RZ   (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyRE   Ί   s    (   RH   RI   R   R   R?   RE   (    (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyR!      s   			
	(   t
   __future__R    t   loggingR   R:   t
   pip.compatR   R   R   t   pip.exceptionsR   t	   pip.utilsR   R   R   R   R	   t   pip.utils.loggingR
   t	   getLoggerRH   R6   t   objectR   R!   (    (    (    sf   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/req/req_uninstall.pyt   <module>   s   (