a
    Df                     @   sF   d Z ddlZddlZddlZddl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 ]H}t t j| |}t|drF||jd 7 }q||jd d d 7 }qt|d S )zget the disk usage for the given directory

    Args:
        path (str): path string.

    Returns:
        int corresponding to disk usage in blocks.
    r   .	st_blocksi      g      @)	oslistdirstatpathjoinhasattrr   st_sizeint)r   sizefiler    r   V/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pox/_disk.py	disk_used   s    	
r   c              	   C   sb   d}t d||d d}z$t|| d  t| dd  }W n" ttfy\   td|  Y n0 |S )a.  convert memory text to the corresponding value in kilobytes

    Args:
        text (str): string corresponding to an abbreviation of size.

    Returns:
        int representation of text.

    Examples:
        >>> kbytes('10K')
        10
        >>> 
        >>> kbytes('10G')
        10485760
    i   r      )KMGNzKInvalid literal for size: '%s' should be a string like '10G', '500M', '50K')dictr   floatKeyError
ValueError)textZkiloZunitsr   r   r   r   kbytes/   s    $
r   g?TFc              	   C   s   g }zt | }W n< t jyN   |dur>|t j| t  n|rHY dS  Y n0 |rZdg}|D ]}t j| |}t j|r^|durt	||| q^d}zt	||d W q^W q t jy   |dkrȂ |d7 }t
t Y q0 qq^dS )a  remove directories in the given path

    Args:
        path (str): path string of root of directories to delete.
        self (bool, default=True): if False, delete subdirectories, not path.
        ignore_errors (bool, default=False): if True, silently ignore errors.
        onerror (function, default=None): custom error handler.

    Returns:
        None

    Notes:
        If self=False, the directory indicated by path is left in place,
        and its subdirectories are erased. If self=True, path is also removed.

        If ignore_errors=True, errors are ignored. Otherwise, onerror 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 the function that caused it to fail; and *exc_info* is a
        tuple returned by ``sys.exc_info()``. If ignore_errors=False and
        onerror=None, an exception is raised.
    N r   r   )r   r   errorsysexc_infor   r	   isdirshutilrmtreetimesleepRM_SUBDIRS_RETRY_TIME)r   selfignore_errorsonerrornamesnamefullnameZ	err_countr   r   r   r#   O   s2    r#   )TFN)	__doc__r   r"   r   r$   r   r   r&   r#   r   r   r   r   <module>   s   