ok

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/cllimits/lib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/cllimits/lib/__pycache__/utils.cpython-37.pyc

B

F�sdE�@s�ddlmZddlmZddlmZddlZddlZddlZddlZddlm	Z	m
Z
dZdd�Zd	d
�Z
dd�Zddd�Zddd�Zddd�Zdd�Zdd�ZdS)�)�print_function)�absolute_import)�divisionN)�run_command�ExternalProgramFailedzAvailable values for optioncCsh|�d�r,|�dd�\}}d|d|id�S|�t�r\|�dd�\}}d|d	|��id�Sd
|iSdS)zu
    Replacing params in data for show error message
    :param data: error's data for show message
    :return:
    z--� �z
%%(param)s %s�param)�result�context�:z%s: %%(available_options)sZavailable_optionsr
N)�
startswith�split�
VALUES_STR�strip)�datar	�text�r�C/opt/alt/python37/lib/python3.7/site-packages/cllimits/lib/utils.py�replace_paramss

rcCs&yt|�dStk
r dSXdS)z�
    Checks is string contains a number (integer or float)
    :param s_val: String to check
    :return: True - string is number, False - not number
    TFN)�float�
ValueError)Zs_valrrr�_is_string_number&s
rcCsxt|���}|�d�rd}n@|�d�r,d}n0|�d�r<d}n t|�rTd}d�|�}ntd��td	|t|d
d���S)zs
    Convert value in Gbytes,Mbytes to bytes

    :param value: value of mem limit
    :return: value in bytes
    �kr�m��g�z{}kzWrong memory valueiN���)�str�lower�endswithr�formatr�intr)�valueZpowerrrr�convert_mem_value_to_bytes3s


r%TcCs�|s|St|���}dddddg}|�d�r2|d=t|����dd��d	d�}|�d
�rjd
}|�d
d�}nd}t|�}xH|D]@}|ddkr�|d}q||dkr�d�|�}Pq|d
�|||�}Pq|W|S)z�
    Convert memory value to adaptive value in GB, TB, etc

    :param value: memory value in MB or KB
    :param convert: if True - convert value, False - not convert
    :return: adaptive value in GB, TB, etc

    �K�M�G�T�Prr�r�*iz{}0Kz
{}{:.2f}{})rr r!�replacer
rr")r$ZconvertZunitsr
Zunitrrr�(_convert_memory_value_to_adaptive_formatIs*





r.FcCs$|rttj|dd��nt|�dS)z�
    Print specified dictionary
    :param data_dict: data dictionary to print
    :param is_json: True - print in JSON, False - in text
    :return: None
    T)Z	sort_keysN)�print�json�dumps)Z	data_dict�is_jsonrrr�print_dictionaryps	r3cCs*t��t|�d�}t||�t�d�dS)za
    Prints to stdout
    :param: is_json - True if print error in json format, False - text
    )Z	timestampr
rN)�timerr3�sys�exit)�messager2rrrr�print_error_and_exit�s
r8cCs tj�|�rtj�|�sdSdS)z\
    Detect quota is supported
    :return: True/False - quotas supported/not supported
    FT)�os�path�isfile)�
cl_quota_path�
repquota_pathrrr�is_quota_supported�sr>cCsDt||�sdS|dg}yt|�}Wntk
r6dSX|s@dSdS)z\
    Detect quota is activated
    :return: True/False - quotas activated/not activated
    Fz-nvaT)r>rr)r<r=�cmd�stdoutrrr�is_quota_active�s
rA)T)F)F)Z
__future__rrrr0r9r5r4Zclcommon.utilsrrrrrr%r.r3r8r>rArrrr�<module>s 

'




Zerion Mini Shell 1.0