Hacked By AnonymousFox

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

�

���f����ddlZddlZddlZddlmZmZmZddlmZm	Z	m
Z
ddlmZm
Z
ddlmZmZGd�d��ZdS)	�N)�Dict�Any�Optional)�ModuleStatus�MODULES_STATUS_FILE�
MAIN_LOG_PATH)�atomic_write�setup_logger�)�NoSuchModule�MalformedConfigErrorc��eZdZdZd�Zd�Zed���Zd�Zd�Z	d�Z
d�Zed	���Zej
d
���Zd�Zd�Zd
�Zd�Zed���ZdS)�Configz;
    Low-level logic of interaction with 'states' file
    c��Gd�d��}||_tdt��|_|���dS)Nc��eZdZdZiZdS)�Config.__init__.<locals>.CfgN)�__name__�
__module__�__qualname__�
worker_pid�modules���M/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwizard/config/config.py�Cfgrs�������J��G�G�Grrz
wizard.config)rr
r�log�reload)�selfrs  r�__init__zConfig.__init__sU��	�	�	�	�	�	�	�	�������?�?������
�
�
�
�
rc��i|j_|���D]5\}}tj|�di��d�|jj|<�6dS)a�
        Forget about the previous config and create a new one with specified
        modules and instructions.

        {'cagefs': {'options': {'enable_for_new_users': True, 'enable_for_existing_users': True}},
         'mod_lsapi': {'options': {'use_beta_for_da': True}},
         'mysql_governor': {'options': {'mode': 'single'}},
         'php': {'options': {'install_versions': ['5.2', '5.3'],
                                                 'install_modules': False, 'default_version': '5.3'}},
         'nodejs': {'options': {'versions': ['7.4', '8.9'], 'default_version': '8.9'}},
         'python': {'options': {'versions': ['2.7', '3.6']}},
         'ruby': {'options': {'versions': ['2.7']}}}
        �options)�statusr!N)rr�itemsr�PENDING�get)rr�module_name�instructionss    r�set_moduleszConfig.set_modules&sf������)0�����	�	�%�K��&�.�'�+�+�I�r�:�:�-�-�D�H��[�)�)�	�	rc�R�d�|jj���D��S)z$Get dictionary with modules statusesc�&�i|]\}}||d��S)r"r)�.0�moduler!s   r�
<dictcomp>z#Config.statuses.<locals>.<dictcomp>@s#��Z�Z�Z�o�f�g����)�Z�Z�Zr)rrr#�rs r�statuseszConfig.statuses<s*��[�Z���AQ�AW�AW�AY�AY�Z�Z�Z�Zrc��	|jj|�di��S#t$r}t	|��|�d}~wwxYw)z Get modules options (dictionary)r!N�rrr%�KeyErrorr�rr&�es   r�get_module_optionszConfig.get_module_optionsBsV��	3��8�#�K�0�4�4�Y��C�C�C���	3�	3�	3��{�+�+��2�����	3���s�%(�
A�A�Ac�x�	|jj|dS#t$r}t|��|�d}~wwxYw)�/Get modules states in format (see ModuleStatus)r"N)rrr2rr3s   r�get_module_statuszConfig.get_module_statusJsK��	3��8�#�K�0��:�:���	3�	3�	3��{�+�+��2�����	3���s��
9�4�9c��	|jj|�d��S#t$r}t	|��|�d}~wwxYw)r7�status_timeNr1r3s   r�get_module_status_timezConfig.get_module_status_timeRsT��	3��8�#�K�0�4�4�]�C�C�C���	3�	3�	3��{�+�+��2�����	3���s�$'�
A�A�Ac��||jjvrt|���||jj|d<tj��|jj|d<dS)zSet new module stater"r:N)rrr�time)rr&�	new_states   r�set_module_statuszConfig.set_module_statusZsV���d�h�.�.�.��{�+�+�+�2;�����%�h�/�7;�y�{�{�����%�m�4�4�4rc��|jjS)z Get background worker process id�rrr.s rrzConfig.worker_pidbs���x�"�"rc��||j_dS)z$Set new background worker process idNrA)r�new_pids  rrzConfig.worker_pidhs��&�����rc��|jj���D]0\}}|�d��st	|j|d���1i|j_dS)z
        Reset self.Cfg object to default values before it will be loaded
        from file as a part of self.reload()
        �__N)r�__dict__r#�
startswith�setattrr)r�k�vs   r�
_reset_cfgzConfig._reset_cfgnsa���H�%�+�+�-�-�	+�	+�D�A�q��<�<��%�%�
+����!�T�*�*�*�������rc�B�|���|���}|�dS|d|j_|d���D]E\}}|d|�d��|�di��d�|jj|<�FdS)z�
        Reset config object and load data from json config.

        :raises MalformedConfigError: cannot parse json config
        N�pidrr"r:r!)r"r:r!)rK�_read_json_configrrr#r%r)r�	json_datar&�infos    rrz
Config.reloadys���	
�������*�*�,�,�	����F�'��.����!*�9�!5�!;�!;�!=�!=�	�	��K���x�.�#�x�x�
�6�6��8�8�I�r�2�2�-�-�D�H��[�)�)�	�	rc�b�|jj|jjd�}|�|��dS)z Dump python object state to file)rMrN)rrr�_write_json_config)r�states  r�savezConfig.save�s<���8�&��x�'�
�
��	
����&�&�&�&�&rc�
�tj�t��sdS	t	td���5}tj|��cddd��S#1swxYwYdS#ttf$r3}|j	�
dt|����Yd}~dSd}~wttf$rC}|j	�
dt|����tt���|�d}~wwxYw)z{
        Load state config and parse it using json

        :raises MalformedConfigError: cannot parse json config
        Nzutf-8)�encodingz*Unable to load config file due to error %sz#Unable to load json config file, %s)�config_path)�os�path�existsr�open�json�load�IOError�OSErrorr�error�str�	TypeError�
ValueErrorr
)r�fr4s   rrNzConfig._read_json_config�sD���w�~�~�1�2�2�	��4�	O��)�G�<�<�<�
$���y��|�|�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$����
$�
$�
$�
$�
$�
$����!�	�	�	��H�N�N�G��Q���P�P�P��4�4�4�4�4������:�&�	O�	O�	O��H�N�N�@�#�a�&�&�I�I�I�&�3F�G�G�G�Q�N�����	O���sF�A,�A�A,�A#�#A,�&A#�'A,�,D�=(B+�+D�?>C=�=Dc��tt��5}tj||d���ddd��dS#1swxYwYdS)z%Write data to file using atomic write�)�indentN)r	rr\�dump)�schemards  rrRzConfig._write_json_config�s����-�
.�
.�	+�!��I�f�a��*�*�*�*�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+�	+�	+s
�:�>�>N)rrr�__doc__rr(�propertyr/r5r8r;r?r�setterrKrrTrN�staticmethodrRrrrrrs-��������������,�[�[��X�[�
3�3�3�3�3�3�3�3�3�C�C�C��#�#��X�#�
��&�&���&�
	�	�	����('�'�'�O�O�O�(�+�+��\�+�+�+rr)r\rXr=�typingrrr�clwizard.constantsrrr�clwizard.utilsr	r
�
exceptionsrr
rrrr�<module>rrs�������	�	�	�	�����&�&�&�&�&�&�&�&�&�&�O�O�O�O�O�O�O�O�O�O�5�5�5�5�5�5�5�5���������W+�W+�W+�W+�W+�W+�W+�W+�W+�W+r

Hacked By AnonymousFox1.0, Coded By AnonymousFox