%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/cllicense/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/cllicense/__pycache__/license.cpython-37.pyc

B

�2Lb��@s�ddlmZddlmZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlZddlmZdd	lmZmZd
dlmZde
ee
ee
edd�d
d�Zeed�dd�ZGdd�d�ZdS)�)�print_function)�absolute_importN)�JSONDecodeError)�Path)�run)�Optional)�CloudlinuxLicenseLib)�print_dictionary�replace_params�)�parse_cloudlinux_packages_opts)�error�details�context�returncCsjdt��i}|dk	r"||d<d}nd|d<d}|dk	r>||d<|dk	rN||d<t�|tj�t�|�dS)	a�
    This function makes UI-specific JSON, prints its and exits from program. It sets "timestamp".
    And if @param error is specified, then field "result" will be filled with this parameter and exit code will be 1.
    Otherwise "result" will be filled with "success" and exit code will be 0.
    @param details: if it's specified, then field "details" will be will be filled with this parameter.
    @param context: if it's specified, then field "context" will be filled with this parameter.
    �	timestampN�resultr�successrrr)�time�json�dump�sys�stdout�exit)r
rr�outputZ	exit_code�r�B/opt/alt/python37/lib/python3.7/site-packages/cllicense/license.py�_print_as_json_and_exits	r)�validation_errorsrcCs4d}x*|��D]\}}|d|�d|�d�7}qW|S)z�
    This function converts dict of validation errors in more human-readable presentation as str.
    @param validation_errors: errors
    @return:
    �z- z: �
)�items)rrZfieldr
rrr�	_beautify6sr"c@sfeZdZdZed�Zdd�Zdd�Zdd�Zd	d
�Z	dd�Z
ddd�Zed�dd�Z
dd�dd�ZdS)�CloudlinuxLicensez+
    Class to check Cloudlinux license
    z%/etc/lve-utils/cloudlinux-license.inicCsXd|_i|_t�|_|j��rNt��}|�|j�t	|dd�rFdnd|_
nd|_
dS)NFZDEFAULTZis_stagezcln-stagingZcln)�_is_json�_optsr�_license_lib�CONFIG_PATH�exists�configparserZConfigParser�read�bool�
_subdomain)�self�configrrr�__init__Is
zCloudlinuxLicense.__init__cCsRd|k|_|�|�|_|jdr2|��|��n|jdrF|��n|��dS)z$
        Run command action
        z--json�setZ	get_trialr)r$�_parse_argsr%�_set_run�_get_run�
_get_trial)r-�argvrrrrUs




zCloudlinuxLicense.runcCs2|j��rd}nd}dt��|d�}t|d�dS)z#
        Run 'get' command
        ZvalidZinvalidr)rr�licenseTN)r&Zget_license_statusrr	)r-Zlicense_statusZresult_datarrrr3es

zCloudlinuxLicense._get_runcCs2|jdr|j��|jd}|r.|j�|�dS)z#
        Run 'set' command
        z--ipz--keyN)r%r&Z!register_and_update_license_by_ipZ"register_and_update_license_by_key)r-�keyrrrr2rs



zCloudlinuxLicense._set_runcCs&t||j�\}}|s"|�t|��|S)z%
        Parse CLI arguments
        )rr$�_error_and_exitr
)r-r5Zstatus�datarrrr1~szCloudlinuxLicense._parse_argsrc
Cs�|jr$|�dt��i�t|d�nXy tt|d�|�di��Wn6tk
rz}ztdt|�|f�Wdd}~XYnXt�	|�dS)z�
        Print error and exit
        :param message dict: Dictionary with keys "result" as string and optional "context" as dict
        rTrrzError: %s [%s]N)
r$�updaterr	�print�str�get�KeyErrorrr)r-�messageZ
error_code�errrr8�s &z!CloudlinuxLicense._error_and_exit)rc
Cs,yt�|jd�}Wn&tk
r:td|jdd�YnXytjd|j�d�|d�}Wn4tjk
r�}ztdt	|�d�Wdd}~XYnXy|��}Wn0tk
r�}ztd|j
d�Wdd}~XYnXd	|kr�|d	S|�d
�dk�rtdd
t|d�id�|�d
�dk�r t|d�td�dS)Nz--configzInput config is not valid JSON.)rzhttp://z".cloudlinux.com/wapi/CL-Solo/trial)rzyWe tried to get trial, but cannot connect to server application. Please, try again later or contact our support for help.z|We tried to get trial, but something was gone wrong on server side. Please, try again later or contact our support for help.r7�typeZ
validationzVInput data validation failed: 
 %(error_text)sPlease fix form errors and submit again.Z
error_text�errors)rr?zmWe tried to get trial, but something was gone wrong. Please, try again later or contact our support for help.)
r�loadsr%rr�requestsZpostr,ZRequestExceptionr<�textr=r")r-r.Zresponser@Z
response_jsonrrr�_get_key�s2zCloudlinuxLicense._get_keyNc	Cs�|��}tddd|dd|j�d�gdd�}|jd	krLtd
d�|j��d��td
dgdd�}|jd	kr�td
d�|j��d��nt�dS)NZ	clnreg_ksz--forcez--activationkeyz--serverUrlzhttps://xmlrpc.z.cloudlinux.com/XMLRPCT)Zcapture_outputrzRWe created trial but unable to register server. Please, try to run this command: `� z3` a little bit later. Contact our support for help.z/usr/bin/cldetectz--update-license)rFrr,�
returncoder�join�args)r-r7rrrrr4�s

zCloudlinuxLicense._get_trial)r)�__name__�
__module__�__qualname__�__doc__rr'r/rr3r2r1r8r<rFr4rrrrr#Cs


+r#)NNN)Z
__future__rrr)rrrrZpathlibr�
subprocessr�typingrrDZ	cllicenserZ	cli_utilsr	r
Zcl_license_arg_parserr<�dictrr"r#rrrr�<module>
s""

Zerion Mini Shell 1.0