3
d                 @   sD   d dl Z d dlZd dlmZmZ G dd deZG dd deZdS )    N)templatemkdtempc               @   s8   e Zd ZdZdedfddZdd Zdd	 Zd
d ZdS )TemporaryDirectorya*  Create and return a temporary directory.  This has the same
    behavior as mkdtemp but can be used as a context manager.  For
    example:

        with TemporaryDirectory() as tmpdir:
            ...

    Upon exiting the context, the directory and everthing contained
    in it are removed.
     Nc             C   s   t |||| _d| _d S )NF)r   name_closed)selfsuffixprefixdir r   6/tmp/pip-build-7vycvbft/nipype/nipype/utils/tmpdirs.py__init__   s    zTemporaryDirectory.__init__c             C   s   | j S )N)r   )r   r   r   r   	__enter__   s    zTemporaryDirectory.__enter__c             C   s   | j stj| j d| _ d S )NT)r   shutilrmtreer   )r   r   r   r   cleanup   s    zTemporaryDirectory.cleanupc             C   s   | j   dS )NF)r   )r   excvaluetbr   r   r   __exit__#   s    zTemporaryDirectory.__exit__)	__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r      s
   
r   c                   s(   e Zd Z fddZ fddZ  ZS )InTemporaryDirectoryc                s$   t j | _t j| j tt| j S )N)osgetcwd_pwdchdirr   superr   r   )r   )	__class__r   r   r   )   s    
zInTemporaryDirectory.__enter__c                s    t j| j tt| j|||S )N)r   r   r   r    r   r   )r   r   r   r   )r!   r   r   r   .   s    zInTemporaryDirectory.__exit__)r   r   r   r   r   __classcell__r   r   )r!   r   r   (   s   r   )r   r   tempfiler   r   objectr   r   r   r   r   r   <module>   s   