a
    Žù»jì  ã                   @   s�   d Z ddlZddlZddlZddlZddlZddlmZ ze W n e	yV   e
ZY n0 dd„ Zdd„ Zdd	„ Zd
ZdZddd„Zddd„ZdS )z
Disk management utilities.
é    N)Úutilc                 C   sj   d}t  | ¡dg D ]H}t  t j | |¡¡}t|dƒrF||jd 7 }q||jd d d 7 }qt|d ƒS )z%Return the disk usage in a directory.r   Ú.Ú	st_blocksi   é   g      �@)	ÚosÚlistdirÚstatÚpathÚjoinÚhasattrr   Úst_sizeÚint)r	   ÚsizeÚfiler   © r   ú1E:\soccer\ml_env\Lib\site-packages\joblib/disk.pyÚ	disk_used   s    
r   c              
   C   s‚   d}t ||d |d d�}z$t|| d  t| dd… ƒ ƒ}W n> ttfy| } z"td| t| ƒf ƒ|‚W Y d}~n
d}~0 0 |S )z,Convert a memory text to its value in bytes.i   é   é   )ÚKÚMÚGéÿÿÿÿNzQInvalid literal for size give: %s (type %s) should be alike '10G', '500M', '50K'.)Údictr   ÚfloatÚKeyErrorÚ
ValueErrorÚtype)ÚtextZkiloZunitsr   Úer   r   r   Úmemstr_to_bytes'   s    $
ÿÿýr    c              
   C   sF   zt  | ¡ W n2 ty@ } z|jtjkr,‚ W Y d}~n
d}~0 0 dS )zgEnsure directory d exists (like mkdir -p on Unix)
    No guarantee that the directory is writable.
    N)r   ÚmakedirsÚOSErrorÚerrnoÚEEXIST)Údr   r   r   r   Úmkdirp5   s
    r&   gš™™™™™¹?é
   c                 C   sn   g }zt  | ¡}W n2 t jyD   |dur>|t j| t ¡ ƒ n‚ Y n0 |D ]}t j | |¡}t||d� qJdS )aË  Remove all subdirectories in this path.

    The directory indicated by `path` is left in place, and its subdirectories
    are erased.

    If onerror is set, it is called to handle the error with arguments (func,
    path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
    path is the argument to that function that caused it to fail; and
    exc_info is a tuple returned by sys.exc_info(). If onerror is None,
    an exception is raised.
    N)Úonerror)r   r   ÚerrorÚsysÚexc_infor	   r
   Údelete_folder)r	   r(   ÚnamesÚnameÚfullnamer   r   r   Ú
rm_subdirsH   s    r0   Tc              	   C   sº   t j | ¡r¶|dur$t | d|¡ n’d}t  | ¡}zNt|ƒdksD|rjtj| ddd� t d 	| ¡¡ W q¶nt
d 	| t|ƒ¡ƒ‚W n( t
tfy¨   |d7 }|tkr¤‚ Y n0 t t¡ q(dS )zBUtility function to cleanup a temporary folder if it still exists.NFr   )Úignore_errorsr(   zSuccessfully deleted {}z*Expected empty folder {} but got {} files.r   )r   r	   ÚisdirÚshutilÚrmtreer   Úlenr   ÚdebugÚformatr"   ÚWindowsErrorÚRM_SUBDIRS_N_RETRYÚtimeÚsleepÚRM_SUBDIRS_RETRY_TIME)Zfolder_pathr(   Zallow_non_emptyZ	err_countÚfilesr   r   r   r,   f   s(    
ÿÿr,   )N)NT)Ú__doc__r#   r   r3   r*   r:   Úmultiprocessingr   r8   Ú	NameErrorr"   r   r    r&   r<   r9   r0   r,   r   r   r   r   Ú<module>   s"   	

