o
    QfX                     @   sV   d Z ddlZddlZddlZddlZddlZdd Zdd Zdd Zd	Z	dd
dZ
dS )z
Disk management utilities.
    Nc                 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   `/oak/stanford/groups/akundaje/marinovg/programs/SPAdes-3.15.4-Linux/share/spades/joblib3/disk.py	disk_used   s   
r   c              	   C   sd   d}t d||d d}zt|| d  t| dd  }W |S  ttfy1   td| t| f w )z7 Convert a memory text to it's value in kilobytes.
    i   r      )KMGNzQInvalid literal for size give: %s (type %s) should be alike '10G', '500M', '50K'.)dictr   floatKeyError
ValueErrortype)textZkiloZunitsr   r   r   r   memstr_to_kbytes"   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)der   r   r   mkdirp1   s   r$   g?c              
   C   s   g }zt | }W n" t jy+ } z|dur |t j| t  n W Y d}~nd}~ww |D ]A}t j| |}t j|ro|durIt	|d| q.d}	 z	t	|dd W n t jym   |dkrb |d7 }t
t Y nw qLq.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.
    NFr   Tr   )r   r   errorsysexc_infor   r	   isdirshutilrmtreetimesleepRM_SUBDIRS_RETRY_TIME)r   onerrornameserrnamefullnameZ	err_countr   r   r   
rm_subdirsA   s:   r3   )N)__doc__r    r   r)   r&   r+   r   r   r$   r-   r3   r   r   r   r   <module>   s    
