o
    XRh%                     @   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   M/home/air/sanwanet/backup_V2/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 )z2 Convert a memory text to its value in bytes.
    i         )KMGNzQInvalid literal for size give: %s (type %s) should be alike '10G', '500M', '50K'.)dictr   floatKeyError
ValueErrortype)text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   mkdirp8   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_subdirsK   s   r2   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)folder_pathr*   allow_non_empty	err_countfilesr   r   r   r.   i   s8   

r.   )N)NT)__doc__r   r,   r<   r%   r5   multiprocessingr   r:   	NameErrorr$   r   r"   r(   r>   r;   r2   r.   r   r   r   r   <module>   s&    

