ok

Mini Shell

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

�

�2�f'1��*�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
ddlmZmZddlmZmZddlmZddlmZmZmZdd	lmZdd
lmZddlmZddlm Z!Gd
�de��Z"Gd�de��Z#Gd�de$��Z%dS)�)�absolute_importN)�deepcopy)�IntEnum�auto)�Iterable�Optional)�ALL_OPTIMIZATION_FEATURES�Feature)�
setup_logging)�get_relative_docroot�create_clwpos_dir_if_not_exists�is_run_under_user)�
is_wp_path)�	constants)�	WposError)�gettextc��eZdZdZdS)�ConfigErrorz^
    Used for all exceptions during handling clwpos user config
    in UserConfig methods
    N)�__name__�
__module__�__qualname__�__doc__���I/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/user/config.pyrr"s��������	�Drrc�J�eZdZe��Ze��Ze��ZdS)�LicenseApproveStatusN)rrrr�NOT_REQUIRED�NOT_APPROVED�APPROVEDrrrrr*s/�������4�6�6�L��4�6�6�L��t�v�v�H�H�Hrrc�v�eZdZdZej�dejej	��Z
ej�d�Zied�Zd"de
ejzfd�Zd	�Zd
�Zdefd�Zd
�Zd�Zdefd�Z	d#de
de
de
deedef
d�Zdedefd�Zdefd�Zde
de
de
ddfd�Zde
de
de
ddfd�Z d�Z!de
de"e
fd�Z#de$fd �Z%d!�Z&dS)$�
UserConfigzQ
    Class to manage clwpos user config - read, write, set params in config.
    z	{homedir}�mb)�docroots�max_cache_memoryFT�usernamec��|s|���t|t��r2||_t	j|��|_|jj|_n||_|j	|_|j|_|j
�|j���|_|rtt��|_dSt!jd��|_dS)N)�homedirr")�_validate_permissions�
isinstance�strr&�pwd�getpwnam�pw�pw_dirr(�pw_name�CONFIG_PATH�format�config_pathrr�_logger�logging�	getLogger)�selfr&�
allow_root�
setup_logss    r�__init__zUserConfig.__init__@s����	)��&�&�(�(�(��h��$�$�		+�%�D�M��l�8�,�,�D�G��7�>�D�L�L��D�G�$�,�D�M�#�?�D�L��+�2�2�4�<�2�H�H����	;�(��2�2�D�L�L�L�"�,�\�:�:�D�L�L�Lrc�Z�t��sttd�����dS)Nz&Trying to use UserConfig class as root)rr�_�r7s rr)z UserConfig._validate_permissionsWs4�� �"�"�	K��a� H�I�I�J�J�J�	K�	Krc�<�	t|jd��5}tj|�����cddd��S#1swxYwYdS#t
$r:t
j��}ttd��|j|d�����wxYw)zo
        Reads config from self.config_path

        DO NOT USE THIS DIRECTLY! USE get_config INSTEAD!
        �rNz@Error while reading config %(config_path)s: %(exception_string)s)r3�exception_string��message�context)
�openr3�json�loads�read�	Exception�	traceback�
format_excrr<)r7�f�
exc_strings   r�read_configzUserConfig.read_config[s���	��d�&��,�,�
,���z�!�&�&�(�(�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,�
,�
,���	�	�	�"�-�/�/�J���\�]�]�(,�(8�j�Y�Y����
�	���s.�A�&A
�A�
A�A�A�A�AB�configc�H�t|j��	tj|dd���}t	|jd��5}|�|��ddd��dS#1swxYwYdS#t$r%}ttd��d|i����d}~wwxYw)	z=
        Writes config (as json) to self.config_path
        �T)�indent�	sort_keys�wNzDAttempt of writing to config file failed due to error:
%(exception)s�	exceptionrA)
r
r.rE�dumpsrDr3�writerHrr<)r7rN�config_jsonrK�es     r�write_configzUserConfig.write_configks���	(���0�0�0�	��*�V�A��F�F�F�K��d�&��,�,�
%������$�$�$�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%����
%�
%�
%�
%�
%�
%���	�	�	���a�b�b�$�a�(����
�����	���s;�,A2�A%�A2�%A)�)A2�,A)�-A2�2
B!�< B�B!c�L�tj�|j��S)z?
        Checks if user customized his config already.
        )�os�path�existsr3r=s r�is_default_configzUserConfig.is_default_config{s���7�>�>�$�"2�3�3�3�3rc��|���rt|j��S	|���}n$#t$rt|j��cYSwxYwt|t��r|nt|j��S)zP
        Returns default config or config content from self.config_path
        )r^r�DEFAULT_CONFIGrMrr*�dict)r7rNs  r�
get_configzUserConfig.get_config�s���
�!�!�#�#�	1��D�/�0�0�0�	1��%�%�'�'�F�F���	1�	1�	1��D�/�0�0�0�0�0�	1����#�F�D�1�1�T�v�v�x��@S�7T�7T�Ts�?�A �A �paramsc��|���}|���D]
\}}|||<�|�|��dS)a�
        Set outer (not "docroots") params in config.
        Example:
        Old config:
        {
            "docroots": ...,
            "max_cache_memory": "123mb",
        }
        Input params:
        {
            "max_cache_memory": "1024mb",
            "param": "value"
        }
        New config:
        {
            "docroots": ...,
            "max_cache_memory": "1024mb",
            "param": "value"
        }
        N)rb�itemsrY)r7rcrN�key�values     r�
set_paramszUserConfig.set_params�sS��*���"�"�� �,�,�.�.�	 �	 �J�C���F�3�K�K����&�!�!�!�!�!rN�domain�wp_path�module�returnc�L�|p|���}	t||j��}nT#t$rG}|j�|d���t
td��||jd�����d}~wwxYwttj
�|j||����s t
td��d|i����|tvr&t
td��|td	�����	|d
}|�
|i���
|g��}||vS#ttt f$rQ}|j�d|j�d|��d���t
td
��d|ji����d}~wwxYw)NT)�exc_infozDCan't find docroot for domain '%(domain)s' and homedir '%(homedir)s')rir(rA�)Wrong wordpress path '%(wp_path)s' passedrj�;Invalid feature %(feature)s, available choices: %(choices)s��feature�choicesr$zconfig z is broken: z@Config is broken.
Repair %(config_path)s or restore from backup.r3)rbrr(rHr4�warningrr<rr[r\�joinr	�get�KeyError�AttributeError�	TypeErrorr3)	r7rirjrkrN�docrootrXr$�module_infos	         r�is_module_enabledzUserConfig.is_module_enabled�s����,�4�?�?�,�,��	�*�6�4�<�@�@�G�G���	�	�	��L� � ��T� �2�2�2���`�a�a�#)�d�l�C�C����
�����	�����"�'�,�,�t�|�W�g�F�F�G�G�	���E�F�F�"�G�,����
�
�2�2�2���W�X�X�$*�7P�Q�Q����
�
		��j�)�H�"�,�,�w��3�3�7�7���D�D�K��[�(�(���.�)�4�	�	�	��L� � �!L�4�+;�!L�!L��!L�!L�W[� �\�\�\���]�^�^�&��(8�9����
�����	���s.�.�
A?�AA:�:A?�5D;�;F#�AF�F#rrc��|jstjS|j|����di��vrtjStjS)a	
        Returns NOT_REQUIRED if feature does not require any approve

        Returns NOT_APPROVED in case if user is required to approve
        license terms before he can use the feature.

        Returns APPROVED in case if license terms were applied.
        �approved_licenses)�HAS_LICENSE_TERMSrr�NAMErbrvrr )r7rrs  r�get_license_approve_statusz%UserConfig.get_license_approve_status�sR���(�	5�'�4�4��<�t���0�0�4�4�5H�"�M�M�M�M�'�4�4�#�,�,rc��|���}|�di��}ttj���������||j<||d<|�|��dS)zc
        Writes information about approved license terms for given feature to config file.
        r~)�approve_dateN)rbrvra�datetime�now�	isoformatr�rY)r7rrrNr~s    r�approve_license_agreementz$UserConfig.approve_license_agreement�s������"�"��"�J�J�':�B�?�?��*.�!�*�.�.�0�0�:�:�<�<�+
�+
�+
��'�,�'�'8��"�#����&�!�!�!�!�!rc��	t||j��}nL#t$r?}|j�|��tt
d��d|i����d}~wwxYwttj	�
|j||����s tt
d��d|i����|tvr&tt
d��|td�����|���}|�
||||��sdS|d||�|��|d||s|d||=|d|s	|d|=|�|��dS�	Nz,Docroot for domain '%(domain)s' is not foundrirArorjrprqr$)rr(rHr4rTrr<rr[r\rur	rbr|�removerY)r7rirjrkrzrXrNs       r�disable_modulezUserConfig.disable_module�s���	�*�6�4�<�@�@�G�G���	�	�	��L�"�"�1�%�%�%���H�I�I�!�6�*����
�����	�����"�'�,�,�t�|�W�g�F�F�G�G�	���E�F�F�"�G�,����
�
�2�2�2���W�X�X�$*�7P�Q�Q����
�
���"�"���%�%�f�g�v�v�F�F�	��F�	�z��7�#�G�,�3�3�F�;�;�;��j�!�'�*�7�3�	5��z�"�7�+�G�4��j�!�'�*�	,��z�"�7�+����&�!�!�!�!�!���
A!�:A�A!c�"�	t||j��}nL#t$r?}|j�|��tt
d��d|i����d}~wwxYwttj	�
|j||����s tt
d��d|i����|tvr&tt
d��|td�����|���}|�
||||��rdSd|vri|d<||dvri|d|<||d|vrg|d||<|d||�|��|�|��dSr�)rr(rHr4rTrr<rr[r\rur	rbr|�appendrY)r7rirjrrrzrXrNs       r�
enable_modulezUserConfig.enable_modules���	�*�6�4�<�@�@�G�G���	�	�	��L�"�"�1�%�%�%���H�I�I�!�6�*����
�����	�����"�'�,�,�t�|�W�g�F�F�G�G�	���E�F�F�"�G�,����
�
�3�3�3���W�X�X�$+�8Q�R�R����
�
���"�"���!�!�&�'�7�F�C�C�	��F��V�#�#�!#�F�:���&��,�,�,�*,�F�:��w�'��&��,�W�5�5�5�35�F�:��w�'��0��z��7�#�G�,�3�3�G�<�<�<����&�!�!�!�!�!r�c#�K�|���d���D]+\}}|���D]\}}|D]	}|||fV��
��,dS)Nr$)rbre)r7�doc_root�
doc_root_inforj�module_names�names      r�enabled_moduleszUserConfig.enabled_modules;s�����'+���'8�'8��'D�'J�'J�'L�'L�	2�	2�#�H�m�)6�)<�)<�)>�)>�
2�
2�%���(�2�2�D�"�G�T�1�1�1�1�1�2�
2�	2�	2r�module_namec#�K�|���D]4\}}}||kr(tj�|j||��V��5dS)zI
        Return absolute WP paths with specified module enabled.
        N)r�r[r\rur()r7r�r�rjr�s     r�wp_paths_with_enabled_modulez'UserConfig.wp_paths_with_enabled_moduleAsd����(,�';�';�'=�'=�	D�	D�#�H�g�t��{�"�"��g�l�l�4�<��7�C�C�C�C�C��	D�	Dr�features_setc��t��}|D]1}|�|��}|D]}|�|����2|S)z�
        Unique set of sites with active features from feature set
        SET is used here, because one site may have several features activated from one set
        e.g: site1 with activated object_cache, shortcodes = 1 path
        )�setr��add)r7r��sitesrr�sites_with_enabled_feature�sites      r�#wp_paths_with_active_suite_featuresz.UserConfig.wp_paths_with_active_suite_featuresIsZ������#�	 �	 �G�)-�)J�)J�7�)S�)S�&�2�
 �
 ���	�	�$�����
 ��rc���d}|����di�����D]=\}}|���D]#\}�|t�fd�|D����z
}�$�>|S)z<
        Returns count of sites with enabled module
        rr$c3� �K�|]}|�vV��	dS�Nr)�.0�checked_module_namer�s  �r�	<genexpr>z@UserConfig.get_enabled_sites_count_by_modules.<locals>.<genexpr>]s*�����"w�"w�K^�#6�,�#F�"w�"w�"w�"w�"w�"wr)rbrvre�any)r7�checked_module_names�sites_countr<r�r�s     @r�"get_enabled_sites_count_by_modulesz-UserConfig.get_enabled_sites_count_by_modulesVs������ $��� 1� 1� 5� 5�j�"� E� E� K� K� M� M�	x�	x��A�}�#0�#6�#6�#8�#8�
x�
x���<��s�"w�"w�"w�"w�bv�"w�"w�"w�w�w�w���
x��r)FTr�)'rrrrr[r\rur�
USER_WPOS_DIR�USER_CLWPOS_CONFIGr1�DEFAULT_MAX_CACHE_MEMORYr`r+r,�
struct_passwdr:r)rMrarYr^rbrhr�boolr|r
rr�r�r�r�r�rr�r�r�r�rrrr"r"8sO���������'�,�,�{�I�,C�Y�Ea�b�b�K�"+�"D�H�H�H��"$�:R�S�S�N�;�;��s�'8�!8�;�;�;�;�.K�K�K���� �4����� 4�4�4�U�U�U� "��"�"�"�"�6TX�!�!��!�(+�!�58�!�BJ�4�.�!�\`�!�!�!�!�F-�'�-�>R�-�-�-�-�""��"�"�"�"�&"�S�&"�3�&"��&"��&"�&"�&"�&"�P%"�C�%"�#�%"��%"��%"�%"�%"�%"�N2�2�2�D��D���
�D�D�D�D�����������rr")&�
__future__rr�rEr5r[r,rI�warnings�copyr�enumrr�typingrr�clwpos.optimization_featuresr	r
�clwpos.logsetupr�clwpos.utilsrr
r�clcommon.clwpos_libr�clwposr�clwpos.cl_wpos_exceptionsrrr<rr�objectr"rrr�<module>r�s���'�&�&�&�&�&�������������	�	�	�	�
�
�
�
�����������������������%�%�%�%�%�%�%�%�K�K�K�K�K�K�K�K�)�)�)�)�)�)�����������
+�*�*�*�*�*�������/�/�/�/�/�/�������	�	�	�	�	�)�	�	�	������7����f�f�f�f�f��f�f�f�f�fr

Zerion Mini Shell 1.0