ok

Mini Shell

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

B

E!wdr�@s�ddlmZddlmZddlmZddlZddlZddlZddlZddlZdZ	dd�Z
dd	d
dd�Zd
d�Zdej
fdd�Zdej
fdd�Zdd�Zdd�Zd*dd�Zd+dd�Zd,dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zeed'�d(d)�ZdS)-�)�absolute_import)�division)�print_functionNz/proc/lve/listc	Cs�y:tt��}|�d�}WdQRXt|�dd�d�dg}Wnbtk
r\dd�t�g}YnBtk
r|dd�t�g}Yn"tk
r�dd	�t�g}YnX|S)
z/
    Obtain lve process filesystem version
    �N�:�rZOKz-clcommon: get_lve_version: Can`t open file {}z1clcommon: get_lve_version: Can`t get data from {}z*clcommon: get_lve_version: Can`t parse  {})	�open�LVE_FILE�read�int�rsplit�IOError�format�
IndexError�
ValueError)�f�lineZlve_procfs_version�r�@/opt/alt/python37/lib/python3.7/site-packages/clcommon/clfunc.py�get_lve_versions
rriii@)�K�M�G�TcCsht|�}t�d�}t�d�}t�dtj�}|�|�}|�|�}|�|�}|dks`|dks`|dkrd|SdS)zh
    check that val is a valid CPU limit (0-100 int or speed (% or MHZ\GHZ))
    return val if ok a
    z^([1-9]|[1-9][0-9]|100)$z^([1-9]|[1-9][0-9]*)%$z^([1-9]|[1-9][0-9]*)(mhz|ghz)+$N)�str�re�compile�
IGNORECASE�match)�val�dataZ
regexp_intZ
regexp_speedpZ
regexp_speedfZp1Zp2Zp3rrr�validate_cpu0s




r!cCsByt|�}Wntk
r dSX||kr6|kr>nn|SdS)zH
    Check that val - is a string number
    return val as a string
    N)rr)r�min_val�max_valZdig_valrrr�validate_intAsr$c
Cs�y`|d}|��rd}||}tt|dd��t|��d�}||krV|kr^nn|SWntttfk
rzYnXdS)N���r�)�isdigitr�float�BYTES_CONVERSION_TABLE�upperrr�KeyError)rr"r#�suffix�resultrrr�memory_to_pageNs$r.cCs\|dkrt|d�dS|dkr>ttt|�ddd��dSttt|�ddd��d	S)
N�r&rii�rir)r�roundr()Zpagesrrr�page_to_memory\s
r2cCs�tjdd|d|gtjd�}|��d�d�}xb|D]Z}|����}y,|d�|���t�	t
|d�tj�Wq2t
ttfk
r�w2Yq2Xq2WdS)Nz/bin/psz-Uz-u)�stdoutr�
r%)�
subprocess�Popen�PIPEZcommunicate�split�rstrip�index�encode�os�killr�signal�SIGHUPrr�OSError)�itemZusernameZps�lines�row�partsrrr�reload_processesds
rE�/etc/login.defsc	Csjt|��X}xP|D]H}|�d�r q|�dd�d}|��}t|�dkr|d|kr|dSqWWdQRX|S)N�#rrr0)r�
startswithr8�len)�key�default�_path�
login_defsZraw_linerZline_splitedrrrrMps


rM�`�c
Cs4yttd��}Wntttfk
r.|}YnX|S)NZUID_MAX)rrMr
r�	TypeError)rKZuid_max_rrr�uid_max|s

rPcCs"tj�dt|��t�|�dS)Nz%s
)�sys�stderr�writer�exit)�messageZstatusrrr�exit_with_error�srVcCs6d|kr2y|�d��d�}Wntk
r0YnX|S)Nz\uZunicode_escapezutf-8)�decoder;�UnicodeDecodeError)�srrr�safe_escaped_unicode_to_utf�srZcCsjt|t�rdd�|��D�St|t�r4dd�|D�St|t�rPtdd�|D��St|t�rb|��S|SdS)NcSsi|]\}}t|�t|��qSr)�byteify)�.0rJ�valuerrr�
<dictcomp>�szbyteify.<locals>.<dictcomp>cSsg|]}t|��qSr)r[)r\�elementrrr�
<listcomp>�szbyteify.<locals>.<listcomp>css|]}t|�VqdS)N)r[)r\r_rrr�	<genexpr>�szbyteify.<locals>.<genexpr>)�
isinstance�dict�items�list�tuplerr;)r rrrr[�s



r[cCsjt|t�rdd�|��D�St|t�r4dd�|D�St|t�rPtdd�|D��St|t�rb|��S|SdS)NcSsi|]\}}t|�t|��qSr)�
unicodeify)r\rJr]rrrr^�szunicodeify.<locals>.<dictcomp>cSsg|]}t|��qSr)rg)r\r_rrrr`�szunicodeify.<locals>.<listcomp>css|]}t|�VqdS)N)rg)r\r_rrrra�szunicodeify.<locals>.<genexpr>)rbrcrdrerf�bytesrW)r rrrrg�s



rgcCs4y|jdd��d�Wntk
r*dSXdSdS)z�
    Check is string contains only ASCII characters
    :param s: string to check
    :return: True - string contains only ASCII characters
    zutf-8)�encoding�asciiFTN)r;rWrX)rYrrr�is_ascii_string�s
rk)�text�returncCs(dd�}t�d||�}t�dd|�}|S)zG
    Escape '%' characters inside text, except '%' followed by '('
    cSs |��dd�d|��dS)zo
        Generate string to replace from matched string
        '% ' -> '%% '
        '%%c' -> '%%%%c'
        Nr%r0)�group)Z	match_objrrr�replace�sz(escape_formatting_chars.<locals>.replacez%+([^(])z%$z%%)r�sub)rlrorrr�escape_formatting_chars�srq)NrF)rN)r)Z
__future__rrrr<rr>r5rQr	rr)r!�maxsizer$r.r2rErMrPrVrZr[rgrkrrqrrrr�<module>	s4





Zerion Mini Shell 1.0