σ
©9Vc           @@  sι   d  d l  m Z d  d l 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 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   dist_is_localt   renamest   normalize_path(   t
   indent_logt   UninstallPathSetc           B@  sk   e  Z d  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   (    (    s2   /tmp/pip-build-5Z5nTX/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(    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt
   _permitted   s    c         C@  sB   t  |  j  s> t j d |  j j t |  j j  t j  t	 St
 S(   Ns1   Not uninstalling %s at %s, outside environment %s(   R   R   t   loggert   infot   project_nameR
   t   locationt   syst   prefixt   Falset   True(   R   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt   _can_uninstall%   s    	
c         C@  s   t  | d t } t j j |  s( d  S|  j |  rJ |  j j |  n |  j j |  t j j	 |  d d k r t
 r |  j t |   n  d  S(   Nt   resolve_symlinksi   s   .py(   R
   R   t   osR   t   existsR   R   t   addR   t   splitextR   R   (   R   R   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyR%   0   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(    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt   add_pth>   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(    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt   compactG   s    	Mc         C@  s5   t  j j |  j t  j j |  d j t  j j   S(   Ni   (   R#   R   t   joinR   t
   splitdrivet   lstripR1   (   R   R   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt   _stashU   s    	c      	   C@  s·  |  j    s d S|  j s3 t j d |  j j  d St j d |  j j |  j j  t   Vt |  j	 |  j   } | r d } n- x | D] } t j |  q 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   qwWt j d |  j j |  j j  n  Wd QXd S(   s[   Remove paths in ``self.paths`` with confirmation (unless
        ``auto_confirm`` is True).Ns7   Can't uninstall '%s'. No files were found to uninstall.s   Uninstalling %s-%s:t   ys   Proceed (y/n)? t   ns.   Not removing or modifying (outside of prefix):t   suffixs
   -uninstallR   s   pip-s   Removing file or directory %ss   Successfully uninstalled %s-%s(   R9   R:   (   R!   R   R   R   R   R   t   versionR   R,   R4   R   R   t   tempfilet   mkdtempR   R8   t   debugR   t   appendR	   R   t   valuest   remove(   R   t   auto_confirmR   t   responseR   t   new_pathR   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyRB   Y   sD    	
		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   R   t   errorR   R   R   R   R   R8   R?   R	   R   RA   t   rollback(   R   R   t   tmp_pathR   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyRG      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   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt   commit   s    	(   t   __name__t
   __module__t   __doc__R   R   R!   R%   R*   R4   R8   R   RB   RG   RI   (    (    (    s2   /tmp/pip-build-5Z5nTX/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(   (    (    s2   /tmp/pip-build-5Z5nTX/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   t   normcaseR   R6   t   replaceRO   R%   (   R   R)   (    (    s2   /tmp/pip-build-5Z5nTX/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(    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pys	   <genexpr>·   s    s   
s   
s   Removing entry: %ss   utf-8t   wb(   R   R?   RN   t   opent	   readlinesRP   R.   RO   RB   t   encodet
   ValueErrort
   writelines(   R   t   fht   linest   endlineR)   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyRB   ±   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 stateRW   (
   RP   R   R   RF   RN   R   R?   RX   R\   R    (   R   R]   (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyRG   Δ   s    (   RJ   RK   R   R%   RB   RG   (    (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyR'      s   			
	(   t
   __future__R    t   loggingR#   R   R=   t
   pip.compatR   R   R   t   pip.exceptionsR   t	   pip.utilsR   R   R   R   R	   R
   t   pip.utils.loggingR   t	   getLoggerRJ   R   t   objectR   R'   (    (    (    s2   /tmp/pip-build-5Z5nTX/pip/pip/req/req_uninstall.pyt   <module>   s   .