AlkantarClanX12

Your IP : 3.133.134.175


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/cllimits/lib/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/cllimits/lib/__pycache__/utils.cpython-311.pyc

�

�ug���p�ddlZddlZddlZddlZddlmZmZdZd�Zd�Z	d�Z
dd�Zdd
�Zdd�Z
d�Zd
�ZdS)�N)�run_command�ExternalProgramFailedzAvailable values for optionc��|�d��r#|�dd��\}}d|zd|id�S|�t��r5|�dd��\}}|dzd	|���id�Sd
|iS)zu
    Replacing params in data for show error message
    :param data: error's data for show message
    :return:
    z--� �z
%(param)s �param)�result�context�:z: %(available_options)s�available_optionsr	)�
startswith�split�
VALUES_STR�strip)�datar�texts   �I/opt/cloudlinux/venv/lib64/python3.11/site-packages/cllimits/lib/utils.py�replace_paramsrs������t���L��j�j��a�(�(���t�&��-�7�E�:J�K�K�K����z�"�"�A��j�j��a�(�(���e��!:�:�/������?�A�A�	A�
�d���c�H�	t|��dS#t$rYdSwxYw)z�
    Checks is string contains a number (integer or float)
    :param s_val: String to check
    :return: True - string is number, False - not number
    TF)�float�
ValueError)�s_vals r�_is_string_numberr$s9���
�e�����t�������u�u����s��
!�!c�t�t|�����}|�d��rd}nV|�d��rd}n>|�d��rd}n&t|��rd}|�d�}nt	d���td|zt
|d	d
���z��S)zs
    Convert value in Gbytes,Mbytes to bytes

    :param value: value of mem limit
    :return: value in bytes
    �kr�m��g�zWrong memory value�N���)�str�lower�endswithrr�intr)�value�powers  r�convert_mem_value_to_bytesr)1s���
��J�J�����E��~�~�c���
/����	����	�	�/����	����	�	�/����	�5�	!�	!�/����������-�.�.�.��t�u�}�u�U�3�B�3�Z�0�0�0�1�1�1rTc���|s|St|�����}gd�}|�d��r|d=t|������dd���dd��}|�d��rd}|�dd��}nd}t|��}|D]'}|dzdkr|dz}�|dkr|�d�}n
|�|d	�|��}|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�*r!�0Kz.2f)r#r$r%�replacer
r)r'�convert�unitsr	�units     r�(_convert_memory_value_to_adaptive_formatr7Gs'��������J�J�����E�%�%�%�E��~�~�c�����!�H���J�J�����&�&�s�B�/�/�7�7��R�@�@�E�����������
�
�c�2�&�&������%�L�L�E������D�=�1����T�M�E�E�
�a�Z�Z��]�]�]�F��E��1��1�1�4�1�1�F���MrFc�r�|r%ttj|d�����dSt|��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)�	sort_keysN)�print�json�dumps)�	data_dict�is_jsons  r�print_dictionaryr?nsE����
�d�j��d�3�3�3�4�4�4�4�4�	�i�����rc��tj��t|��d�}t||��tjd��dS)za
    Prints to stdout
    :param: is_json - True if print error in json format, False - text
    )�	timestampr	rN)�timer#r?�sys�exit)�messager>rs   r�print_error_and_exitrFs>��
�����G���=�=�D��T�7�#�#�#��H�Q�K�K�K�K�Krc��tj�|��rtj�|��sdSdS)z\
    Detect quota is supported
    :return: True/False - quotas supported/not supported
    FT)�os�path�isfile)�
cl_quota_path�
repquota_paths  r�is_quota_supportedrM�s9���7�>�>�-�(�(������}�0M�0M���u��4rc�~�t||��sdS|dg}	t|��}n#t$rYdSwxYw|sdSdS)z\
    Detect quota is activated
    :return: True/False - quotas activated/not activated
    Fz-nvaT)rMrr)rKrL�cmd�stdouts    r�is_quota_activerQ�so���m�]�;�;���u��&�
!�C���S�!�!���� �����u�u��������u��4s�(�
6�6)T)F)r;rHrCrB�clcommon.utilsrrrrrr)r7r?rFrMrQ�rr�<module>rTs�������	�	�	�	�
�
�
�
�����=�=�=�=�=�=�=�=�
*�
����$
�
�
�2�2�2�,$�$�$�$�N����"�����������r