o
    ]ô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	y+   e
ZY nw 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 ]$}t  t j | |¡¡}t|dƒr#||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   ú\/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/joblib/disk.pyÚ	disk_used   s   
r   c              
   C   st   d}t ||d |d d�}zt|| d  t| dd… ƒ ƒ}W |S  ttfy9 } ztd| t| ƒf ƒ|‚d}~ww )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kiloÚunitsr   Úer   r   r   Úmemstr_to_bytes'   s   "û
ÿÿý€ÿr!   c              
   C   sF   zt  | ¡ W dS  ty" } z|jtjkr‚ W Y d}~dS d}~ww )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 n t jy"   |dur|t j| t ¡ ƒ n‚ Y nw |D ]}t j | |¡}t||d� q%d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   þþþr1   Tc              	   C   sº   t j | ¡r[|durt | d|¡ dS d}	 t  | ¡}z%t|ƒdks$|r7tj| ddd� t d 	| ¡¡ W dS t
d 	| t|ƒ¡ƒ‚ t
tfyT   |d7 }|tkrR‚ Y nw t t¡ qdS )	zBUtility function to cleanup a temporary folder if it still exists.NFr   T)Ú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)   Úallow_non_emptyZ	err_countÚfilesr   r   r   r-   f   s2   
ÿÿüþ
ìùr-   )N)NT)Ú__doc__r$   r   r4   r+   r;   Úmultiprocessingr   r9   Ú	NameErrorr#   r   r!   r'   r=   r:   r1   r-   r   r   r   r   Ú<module>   s&    	ÿ
