%PDF- %PDF-
Mini Shell

Mini Shell

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

B

�2Lb�2�@s$ddlmZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZddl
Z
ddlmZddlmZmZmZddlmZdd	lmZdd
lmZddlmZmZmZddlmZmZm Z m!Z!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+ddlm,Z,Gdd�de-�Z.dS)�)�print_function)�absolute_importN)�Union�Any�Optional�Dict)�FormattedException)�run_command�ExternalProgramFailed�get_cl_version)�NoSuchModule�)�acquire_config_access)�Config)�run_installation�ALL_MODULES�get_supported_modules)�WizardStatus�ModuleStatus�CRASH_LOG_PATH�FILE_MARKER_PATH�
MAIN_LOG_PATH)�CancelModuleException�InstallationFailedException)�parse_cloudlinux_wizard_opts)�is_background_process_running�run_background�setup_logger)�get_rpm_db_errorsc@s�eZdZdZejejejgZej	ejej
gZdd�Zdd�Z
edd��Zdd	�Zd#dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zed$d!d"��Zd
S)%�CloudlinuxWizardzAMain class for working with Wizard that exposes high level logic.cCsd|_t�|_tdt�|_dS)Nzwizard.main)�_optsr�_supported_modulesrr�log)�self�r$�@/opt/alt/python37/lib/python3.7/site-packages/clwizard/wizard.py�__init__@szCloudlinuxWizard.__init__c
Cs�t|�|_y�|jjdkr`|��|��r>|jjs>|jddd�|jjrNt�q�|j	|jj
d�nf|jjdkr�|��|jjr�|��q�|�
�n6|jjdkr�|�|jj�n|jjdkr�|��nt�|jjd	kr�|��s�|jjdkr�|��s�|��|��|��Wn�tk
�rV}z.|j�d
t|��|j|j|j|jdd�Wdd}~XYnjtk
�rx|jd
dd�YnHtk
�r�}z(|j�dt|��|jdt� �d�Wdd}~XYnXdS)zv
        CL Wizard main function
        :param argv: command line arguments for wizard
        :return: None
        �installzInstallation already finishedr
)�result�	exit_code)�options�status�cancelZfinish)r'r,z>We got an error while running cloudlinux-wizard, message: '%s')r(�context�detailsr)Nz8Module installation failed, see log for more informationz&Unknown error in cloudlinux-wizard, %sz\Unknown error happened, please, try again or contact CloudLinux support if it happens again.)r(r.)!rr Z	subparser�_validate_system�is_installation_finished�force�_print_result_and_exitZno_asyncr�run_background_installationZ	json_data�initial�_get_initial_status�_get_modules_statuses�_cancel_module_installation�module�create_completion_marker�NotImplementedError�is_all_modules_installed�run_collecting_statistics�run_cagefs_force_updaterr"�error�str�messager-r.r�	ExceptionZ	exception�	traceback�
format_exc)r#�argv�er$r$r%�runEsH



	$zCloudlinuxWizard.runcCstj�t�S)N)�os�path�isfilerr$r$r$r%r0~sz)CloudlinuxWizard.is_installation_finishedc
Csfyt�t�|j�d�WnFttfk
r`}z$|j�dt|��|j	ddd�Wdd}~XYnXdS)Nz Wizard was successfully finishedz1Finish command called more than once, error: '%s'z$Finish command called more than oncer
)r(r))
rG�mknodrr"�info�OSError�IOError�warningr?r2)r#�errr$r$r%r9�s
z)CloudlinuxWizard.create_completion_markerNc	Csrtjdd�}|�d�t��<}t�r4|jddd�|dk	rF|�|�t|�j}||_	WdQRX|jd|d�dS)Nz
--no-asynczGUnable to run new installation because background task is still workingr
)r(r)�success)r(�pid)
�sysrD�appendrrr2Zset_modulesrrQ�
worker_pid)r#r*�cmd�configrTr$r$r%r3�s


z,CloudlinuxWizard.run_background_installationcCst�dkr|jdd�dS)z;
        Check that wizard supports current system
        Nz|Could not identify CloudLinux version. Restart your system. If you have the same problem again - contact CloudLinux support.)r()rr2)r#r$r$r%r/�s
z!CloudlinuxWizard._validate_systemcCs|j|jS)zGet path to module log file)r!ZLOG_FILE)r#�module_namer$r$r%�_get_module_log_path�sz%CloudlinuxWizard._get_module_log_pathc
Cs�g}t���}|�|�}xr|jD]h}y|�|�}|�|�}Wntk
rPwYnX|||d�}|tjtjgkr||�	|�|d<|�
|�qWWdQRX|tjkr�|j
||td�|j
||d�dS)z?
        Get information about background worker state
        )r+�name�status_timeZlog_fileN)�
wizard_status�modulesZ	crash_log)r[r\)r�_get_wizard_stater!�get_module_statusZget_module_status_timerr�FAILED�AUTO_SKIPPEDrXrSr�CRASHEDr2r)r#r\rV�staterYr+rZZ
module_statusr$r$r%r6�s 


z&CloudlinuxWizard._get_modules_statusescCsJt�}|r|j|d�|jdd�|j��D�ttt�t|j��d�dS)zg
        Get initial modules status that is used
        by lvemanager to display wizard pages
        )r(cSsi|]\}}|���|�qSr$)Zinitial_status)�.0rW�clsr$r$r%�
<dictcomp>�sz8CloudlinuxWizard._get_initial_status.<locals>.<dictcomp>)r\Zunsuppored_by_cpN)rr2r!�items�list�setr)r#Z
error_messager$r$r%r5�s
z$CloudlinuxWizard._get_initial_statusc	Csr|j�d|�t��T}|�|�}||jkrJ|j|tjd�|j�d|�n|j�d||�t	||��WdQRXdS)z=Remove module from queue or print error if it is not possiblezTrying to cancel module '%s')rWZ	new_statez!Module '%s' successfully canceledz<Not able to cancel module '%s', because it is in status '%s'N)
r"rKrr^�CANCELABLE_MODULE_STATUSESZset_module_statusr�	CANCELLEDrNr)r#r8rVr+r$r$r%r7�s


z,CloudlinuxWizard._cancel_module_installationc
Cszddg}tj�d�s|�d�|j�d�yt|�}|j�d|�Wn0tk
rt}z|j�d|�Wdd}~XYnXdS)	z,
        Collects user`s statistics
        z/usr/sbin/cloudlinux-summaryz--sendZSYNCHRONOUS_SUMMARYz--asynczTry to collect statistics..z-Output of statistics collection command: '%s'z>Error during collecting and sending statistics. Reason is '%s'N)	rG�environ�getrSr"rKr	r
r>)r#rU�outrEr$r$r%r<�s
z*CloudlinuxWizard.run_collecting_statisticsc	s6t��}t|j���}WdQRXt�fdd�|D��S)z�
        Check that all modules were successfully installed:
        -- installed
        -- canceled
        -- auto-skipped
        Nc3s|]}|�jkVqdS)N)�DONE_MODULES_STATUSES)rcr+)r#r$r%�	<genexpr>�sz<CloudlinuxWizard.is_all_modules_installed.<locals>.<genexpr>)rrg�statuses�values�all)r#rVrpr$)r#r%r;�sz)CloudlinuxWizard.is_all_modules_installedcCsTd}tj�|�sdS|ddg}|j�d|�t|�}ttj�d��}|rP|�	�dS)z=
        Runs cagefsctl --force-update in background
        z/usr/sbin/cagefsctlNz--force-updatez--wait-lockz0Starting cagefs force-update in background..: %sZCL_TEST_SYSTEM)
rGrHrIr"rKr�boolrkrlZcommunicate)r#Z
cagefsctl_binrUZcagefsctl_procZis_test_environmentr$r$r%r=s
z(CloudlinuxWizard.run_cagefs_force_updatecs�|jdkrtjSyt�|j�Wnltjk
r�t|j���}t	�fdd�|D��r\tj
Stdd�|D��r�tdd�|D��s�tjStj
SXtjSdS)Nc3s|]}|�jkVqdS)N)rn)rcr+)r#r$r%ro sz5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>css|]}|tjtjfkVqdS)N)rr_rj)rcr+r$r$r%ro$scss|]}|tjfkVqdS)N)rZ
INSTALLING)rcr+r$r$r%ro%s)rTrZIDLE�psutilZProcessZ
NoSuchProcessrgrprqrrZDONE�anyr_raZIN_PROGRESS)r#rVrpr$)r#r%r]s
z"CloudlinuxWizard._get_wizard_staterPrcKs:|t��d�}|�|�ttj|ddd��t�|�dS)z�
        Print data in default format for web and exit
        :param dict extra: extra fields in response,
                           usually we expect 'context' here
        )r(Z	timestamp�T)�indentZ	sort_keysN)�time�update�print�json�dumpsrR�exit)r(r)Zextrar@r$r$r%r2+s
	
z'CloudlinuxWizard._print_result_and_exit)N)rPr)�__name__�
__module__�__qualname__�__doc__rZPENDINGr_rjriZ	INSTALLEDr`rnr&rF�staticmethodr0r9r3r/rXr6r5r7r<r;r=r]r2r$r$r$r%r0s.9	
r)/Z
__future__rrr{rGrRrxrB�typingrrrrrtZclcommonrZclcommon.utilsr	r
rZclwizard.configrrVrrr\rrrZ	constantsrrrrr�
exceptionsrr�parserrZutilsrrrr�objectrr$r$r$r%�<module>	s(

Zerion Mini Shell 1.0