B
    Uvg7
                 @   sN   d dl mZ d dlZd dlZd dlZd dlmZ ee	Z
G dd deZdS )    )absolute_importN)rmtreec                   sJ   e Zd ZdZd fdd	Zdd Zdd	 Zd
d Zdd Zdd Z	  Z
S )TempDirectorya'  Helper class that owns and cleans up a temporary directory.

    This class can be used as a context manager or as an OO representation of a
    temporary directory.

    Attributes:
        path
            Location to the created temporary directory or None
        delete
            Whether the directory should be deleted when exiting
            (when used as a contextmanager)

    Methods:
        create()
            Creates a temporary directory and stores its path in the path
            attribute.
        cleanup()
            Deletes the temporary directory and sets path attribute to None

    When used as a context manager, a temporary directory is created on
    entering the context and, if the delete attribute is True, on exiting the
    context the created directory is deleted.
    Ntempc                s8   t t|   |d kr"|d kr"d}|| _|| _|| _d S )NT)superr   __init__pathdeletekind)selfr   r	   r
   )	__class__ =/tmp/pip-install-r_9ig3yj/pip/pip/_internal/utils/temp_dir.pyr   %   s    zTempDirectory.__init__c             C   s   d | jj| jS )Nz	<{} {!r}>)formatr   __name__r   )r   r   r   r   __repr__1   s    zTempDirectory.__repr__c             C   s   |    | S )N)create)r   r   r   r   	__enter__4   s    zTempDirectory.__enter__c             C   s   | j r|   d S )N)r	   cleanup)r   excvaluetbr   r   r   __exit__8   s    zTempDirectory.__exit__c             C   sT   | j dk	r td| j  dS tj tjd| jd| _ td| j  dS )zFCreate a temporary directory and store it's path in self.path
        Nz+Skipped creation of temporary directory: {}zpip-{}-)prefixzCreated temporary directory: {})	r   loggerdebugr   osrealpathtempfilemkdtempr
   )r   r   r   r   r   <   s    
zTempDirectory.createc             C   s,   | j dk	r"tj | j r"t| j  d| _ dS )z?Remove the temporary directory created and reset state
        N)r   r   existsr   )r   r   r   r   r   M   s    
zTempDirectory.cleanup)NNr   )r   
__module____qualname____doc__r   r   r   r   r   r   __classcell__r   r   )r   r   r      s   r   )
__future__r   loggingos.pathr   r   pip._internal.utils.miscr   	getLoggerr   r   objectr   r   r   r   r   <module>   s   
