ok

Mini Shell

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

�

E��f�N���ddlmZddlmZddlmZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZe��aGd�de��ZdS)
�)�absolute_import)�print_function)�divisionN)�	in_cagefs�)�ClSelect)�ClSelectExcept)�clprint)�utilsc�Z�eZdZe��rdndZdZdd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zdd
�Z
dd�Zdd�Zd�Zee��Zd�Zd d�Zee��Zd�Zee��Zd�Zee��Zd�Zd�Zd�Zd�Zed���Zed���Zed���Zed���ZdS)!�ClExtSelectz0/etc/cl.selector.conf.d/php.extensions.conflictsz)/etc/cl.selector/php.extensions.conflictsz/opt/alt�phpc�L�tj||��g|_d|_dS)NF)r�__init__�
_conflicts�!_use_default_exts_from_native_php)�self�items  �K/opt/cloudlinux/venv/lib64/python3.11/site-packages/clselect/clextselect.pyrzClExtSelect.__init__#s,����$��%�%�%����27��.�.�.�c��||jvS�N)�_hidden_extensions)r�ext_names  r�_is_disabled_extentionz"ClExtSelect._is_disabled_extention+s���4�2�2�2rc��|���}|�||��|�|j|j|f|j|d���}|�d�|��tj��dS)zM
        Adds extensions to default list of extensions for a version
        �enable_extentions��action�
N)	�get_all_alternatives_data�_check_alternative�_process_ini_file�
DEFAULTS_PATH�_item�_add_extensions�_write_to_file�joinr
�r�version�ext_list�alternatives�defaults_contentss     r�enable_extensionszClExtSelect.enable_extensions.s����5�5�7�7�������6�6�6� �2�2���
�Z��!�� ��2�	3�4�4��
	
����I�I�'�(�(�+�*C�	E�	E�	E�	E�	Erc��|���}|�||��|�|j|j|f|j|��}|�d�|��|j��dS)a
        Replaces extensions to default list of extensions for a version.
        Writes/updates /etc/cl.selector/defaults.cfg file
        :param version: alt-php version to process
        :param ext_list: list extensions to set as defaults for the version
        r N)r!r"r#r$r%�_replace_extensionsr'r(r)s     r�replace_extensionszClExtSelect.replace_extensions<s����5�5�7�7�������6�6�6� �2�2���
�Z��!��$��	���
	
����I�I�'�(�(�$�*<�	>�	>�	>�	>�	>rc��|���}|�||��|�|j|j|f|j|d���}|�d�|��|j��dS)z�
        Removes extensions from default list of extensions for a version
        :param version: alt-php version to process
        :param ext_list: comma separated extensions list to delete
        �disable_extentionsrr N)r!r"r#r$r%�_del_extensionsr'r(r)s     r�disable_extensionszClExtSelect.disable_extensionsMs����5�5�7�7�������6�6�6� �2�2���
�Z��!�� ��3�	3�5�5��
	
���D�I�I�&7�8�8�$�:L�M�M�M�M�Mrc��d}d}t��}d}|���}|�||��|�|��}|�|��}	|�|��}	n#tj$rg}	YnwxYwttd�|����}
|	D]�}d}||vr||vrd}t|df|df|dfg��}
t|
���
|
��s�||krQ|jrJ||	vrF|
�|df��|
�|df��d}|�|����|
�||f��|r|�|����|r|�
||��tt|
t!jd�������S)	a�
        Returns list of extensions marking built-ins and enabled ones
        Also replaces mysqli->nd_mysqli in defaults.cfg for new installations according to LVEMAN-1399
        :param version: php version
        :return Tuple: (extension_name, extension_state)
            extension_state:
                None        -- built-in extension
                False/True  -- disabled/enabled extension
        �mysqli�	nd_mysqliFc�
�|dfSr���is r�<lambda>z-ClExtSelect.list_extensions.<locals>.<lambda>ys
��a��Y�rTNr)�key)�listr!r"�_get_enabled_extensions�
_get_builtins�_load_extensions_listr	�UnableToGetExtensions�map�set�intersectionr�appendr1�tuple�sorted�operator�
itemgetter)rr*�ext_mysqli_name�ext_nd_mysqli_name�ext_list_to_write�is_need_to_write_defaultsr,�enabled_extensions�as_built_in�
as_extensions�all_extensions�ext�status�ext_sets              r�list_extensionszClExtSelect.list_extensions\s*��#��(�� �F�F��$)�!��5�5�7�7�������6�6�6�"�9�9�'�B�B���(�(��1�1��	�!�6�6�w�?�?�M�M���3�	�	�	��M�M�M�	�����c�#6�#6��E�E�F�F�� �	6�	6�C��F��)�)�)��;�0F�0F����C��;��e��s�D�k�B�C�C�G��~�&�&�3�3�G�<�<�
6�
�/�)�)�d�.T�)�.�-�?�?�"�)�)�?�E�*B�C�C�C�"�)�)�+=�t�*D�E�E�E�04�-�%�,�,�-?�@�@�@�@�"�)�)�3��-�8�8�8��6�)�0�0��5�5�5��%�	@��#�#�G�->�?�?�?��V�N��0C�A�0F�0F�G�G�G�H�H�Hs�*B�B�Bc�6�	|j�|j�|��d��}d|_t	td�|�d������S#tjtj	f$rd|_|�
d��cYSwxYw)zB
        Returns list of enabled extensions for a version
        �modulesFc�*�|���Sr��stripr;s rr=z5ClExtSelect._get_enabled_extensions.<locals>.<lambda>�s��q�w�w�y�y�r�,T�native)�_dh�getr%rr?rD�split�configparser�NoSectionError�
NoOptionErrorrA)rr*�datas   rr@z#ClExtSelect._get_enabled_extensions�s���	0��8�<�<��*�*�g�g�.�	�;�;�D�5:�D�2���0�0�4�:�:�c�?�?�C�C�D�D�D���+�\�-G�H�	0�	0�	0�59�D�2��%�%�h�/�/�/�/�/�	0���s�AA�7B�BTc
�^�|�|��}t|��dks||dkr|Sd}g}|�|d��}tt|����D]!}	||	�d��r|	}n�"|r�||||�d��dzd����}
|�ttd�|
�
d��������|�|��|�|��}|�||��}dd�
t|����z}
|r|
||<n|�|
��|�|��S)	z�
        Adds 'modules' option to section or extends it
        @param section_info: tuple (item and version)
        @param section: list
        @param data: list
        @return: list
        rNrrY�=c�*�|���Srr[r;s rr=z-ClExtSelect._add_extensions.<locals>.<lambda>�s��A�G�G�I�I�rr]�modules = %s)�_make_section_header�len�_compose_alt_path�range�
startswith�findr\�extendr?rDra�_check_for_conflicts�_include_dependenciesr(rIrG�_smooth_data)r�section_info�sectionre�trace�section_header�midxrY�alt_path�idx�modules_string�resolved_moduless            rr&zClExtSelect._add_extensions�s����2�2�<�@�@���w�<�<�1����'�!�*� <� <��N������)�)�,�q�/�:�:����W���&�&�	�	�C��s�|�&�&�y�1�1�
�����
��	M�$�T�]�7�4�=�+=�+=�c�+B�+B�1�+D�+E�+E�F�L�L�N�N�N��N�N��S�-�-��0D�0D�S�0I�0I�J�J�K�K�
M�
M�
M����t�����+�+�G�4�4���5�5�g�x�H�H��'�3�8�8�F�;K�4L�4L�+M�+M�N���	+�*�G�D�M�M��N�N�>�*�*�*�� � ��)�)�)rc����|�|��}t|��dks||dkr|Sd}|�|d��}tt|����D]!}||�d��r|}n�"|dd�}	|r�t��}
|�|	��}	|	D]g�|��g|��}t|��dkr&t�	�fd�|D����|
�	|���hdd�
t|
����z}n%dd�
t|����z}|r|||<n|�|��t�
��}	|	���D]}
|
|vrt|
=�|�|��S)aK
        Adds 'modules' option to section or extends it
        @param section_info: tuple (item and version).
            Example: ('php', '5.2')
        @param section: list. Modules from /etc/cl.selecto/defaults.cfg for supplied php version
            Example: ['[php5.2]',
                      'modules = bcmath,dom,gd,imap,json,mcrypt,mysql,mysqli,phar,posix,sockets,uuid,wddx,xmlreader,zip',
                      '', '']
        @param data: list: Modules list to set from command line
        @:param trace: ????, Currently not using, always True
        @return: list
        rNrrYc�"��i|]}|�k�|���Sr:r:)�.0�
dep_module�mods  �r�
<dictcomp>z3ClExtSelect._replace_extensions.<locals>.<dictcomp>�s'���/s�/s�/s�J�ak�or�ar�ar�
�C�ar�ar�arrrir])rjrkrlrmrnrErqrr�depend_modules_dict�updater(rIrG�copy�keysrs)rrtrurervrwrxryrzrYr|�include_depr{r�r�s              @rr0zClExtSelect._replace_extensions�s����2�2�<�@�@���w�<�<�1����'�!�*� <� <��N����)�)�,�q�/�:�:����W���&�&�	�	�C��s�|�&�&�y�1�1�
�����
��q�q�q�'���	G�"�u�u���/�/��8�8�G��
5�
5��"�8�8�#���I�I���{�#�#�q�(�(�(�.�.�/s�/s�/s�/s�R]�/s�/s�/s�t�t�t� �'�'��4�4�4�4�+�s�x�x��?O�8P�8P�/Q�/Q�R�N�N�+�s�x�x��t���/E�/E�F�N��	+�*�G�D�M�M��N�N�>�*�*�*�%�*�*�,�,��!�,�,�.�.�	4�	4�J��T�!�!�'�
�3��� � ��)�)�)rc��|�|��}t|��dks||dkr|Sd}|�|d��}tt|����D]!}||�d��r|}n�"|s|S||||�d��dzd����}	ttd�|	�	d������}
|
�
��}t|��D]J}||
vr�|
�|g��}
|�||
|��r�5|�
|���K|�||��}dd�t!|����z}	|	||<|�|��S)	z�
        Deletes items in data list from section list
        @param section_info: tuple (item and version)
        @param section: list
        @param data: list of extension names to delete
        @return: list
        rNrrYrgc�*�|���Srr[r;s rr=z-ClExtSelect._del_extensions.<locals>.<lambda>	s��Q�W�W�Y�Y�rr]ri)rjrkrlrmrnror\rErDrar��
difference�_is_dependency�discardrrr(rIrs)rrtrurervrwrxryrzr{rYr|r�rest_of_moduless              rr4zClExtSelect._del_extensions�s����2�2�<�@�@���w�<�<�1����'�!�*� <� <��N����)�)�,�q�/�:�:����W���&�&�	�	�C��s�|�&�&�y�1�1�
�����
��	��N� ���w�t�}�'9�'9�#�'>�'>�q�'@�'A�'A�B�H�H�J�J���c�.�.��1E�1E�c�1J�1J�K�K�L�L��"�<�<�>�>����I�I�	+�	+�D��7�"�"��%�0�0�$��8�8�O��"�"�4��(�C�C�
���$�$�T�*�*�*�*��5�5�6F��Q�Q��'�3�8�8�F�;K�4L�4L�+M�+M�N��&���
�� � ��)�)�)rc�^�|D])}|�||��}||vr
|t|<dS�*dS)a^
        Checks if module in modules dependent on ext and returns true or false
        @param ext: Module to check
        @param modules: set of names of installed modules
        @param alt_path: Path to alt-php ini dir: /opt/alt/phpXX/etc/php.d.all
        @return: bool. True if ext present in dependencies of any module in modules list
        TF)�_get_dependenciesr�)�clsrTrYryr��dependenciess      rr�zClExtSelect._is_dependencysQ���	�	�C��0�0��h�?�?�L��l�"�"�+.�#�C�(��t�t�#��urc��tj�|j|j�|�dd����d|j�d���S)z<
        Composes and returns path for alternatives
        �.��etcz.d.all)�os�pathr(�SYSTEM_ALT_PATHr%�replace)rr*s  rrlzClExtSelect._compose_alt_path(sN���w�|�|�� ��j�j�'�/�/�#�r�":�":�":�;���*�*�*�&�	(�(�	(rNc���d}g}t��}tj|��}|�r�|���}||vr�|�|��t
j�||�d���}		t|	��}
g}g}|
D�]}
|
�	d��s|
�	d��rh|�
||
��}||kr||vr|�|���c|�d|�d���d}|�
|��g}|
�	d��sf|
�	d	��sQ|r(|�|
�������|�|
�������|
���|�	||vr|||<|�d|��n#t"t$f$rY���wxYw|���|S)z�
        Includes dependencies into extensions list and update data dict
        if present
        @param ext_list: list
        @param alt_path: string
        @param data: dict
        @return: list
        F�.ini�	extension�zend_extensionz;---z---T�;r Nr)rE�collections�deque�popleft�addr�r�r(�openrn�_single_out_extension�
appendleftrGrp�rstrip�close�insert�OSError�IOError)r�r+ryre�
in_section�result_ext_list�handled�qrT�ext_path�f�
file_contents�pending_contents�liners               rrrz!ClExtSelect._include_dependencies2s(���
����%�%����h�'�'���&	��)�)�+�+�C��g�~�~���K�K������w�|�|�H��l�l�l�;�;�H�
���N�N�� "�
�#%� ��C�C�D����{�3�3�	.�t���GW�7X�7X�	.�#&�#<�#<�S�$�#G�#G��#�s�?�?�x�w�/F�/F��L�L��2�2�2�$�%�,�,�_�C�_�_�_�=�=�=�%)�
�%�,�,�-=�>�>�>�+-�(� �O�O�C�0�0�C�D�O�O�D�4I�4I�C�%�C�)�0�0������?�?�?�?�,�3�3�D�K�K�M�M�B�B�B�����	�	�	��#��4��� -�D��I� �&�&�q�#�.�.�.�.���W�%�
�
�
���
����K�&	�P�s�<EG�G.�-G.c�P�t��}tj�||�d���}	t	|��}|D]H}|�d��r1|�||��}||kr|�|���I|S#ttf$r|cYSwxYw)z�
        Checks if an extension has dependencies and if so returns them
        Otherwise returns None
        @param ext: string
        @return: set
        r�r�)
rEr�r�r(r�rnr�r�r�r�)r�rTryr�r�r�r�rs        rr�zClExtSelect._get_dependenciesks����u�u���7�<�<��c�c�c�*;�<�<��		 ��X���A��
3�
3���?�?�;�/�/�3�"�8�8��d�C�C�H��3���$�(�(��2�2�2�������!�	 �	 �	 �����	 ���s�AB�B%�$B%c��ddi}d|vr3||�d��dzd����}n3||�d��dzd��d��}d|vr|d|�d���}d	|vr|d|�d	���}||vr	||}nH||vr|}nAd
|vr=d�t	d�|�d
������|kr|}|S)
z=
        Singles out and returns extension from line
        �ixed�sourceguardian�/rNrgz "r��-�_r�c�*�|���Sr)�
capitalizer;s rr=z3ClExtSelect._single_out_extension.<locals>.<lambda>�s��A�L�L�N�N�r)�rfindr\ror(rDra)rTr��quirksrs    rr�z!ClExtSelect._single_out_extension�s2���*�+���$�;�;��D�J�J�s�O�O�A�-�.�.�/�5�5�7�7�H�H��D�I�I�c�N�N�1�,�-�-�.�4�4�T�:�:�H��(�?�?�� 3����s�!3�!3� 3�4�H��(�?�?�� 4�����!4�!4� 4�5�H��v����h�'�H�H�
�H�_�_��H�H��S�j�j�R�W�W�S�*B�*B��	�	�#���& �& �!�!�$,�-�-��H��rc���|js|���t��}|D]B}|�||��r*|�|��s|�|���C|S)z?
        Removes from extensions list conflicting ones
        )r�_load_conflicting_extensionsrE�_is_not_conflictingrr�)rr+�	clean_setrTs    rrqz ClExtSelect._check_for_conflicts�s�����	0��-�-�/�/�/��E�E�	��	#�	#�C��'�'��Y�7�7�
#��3�3�C�8�8�
#��
�
�c�"�"�"���rc��|jD]A}||vr;t|����|����dkrdS�BdS)z;
        Checks extension against conflicting sets
        rFT)rrkr�rF)rrTr��conflicts    rr�zClExtSelect._is_not_conflicting�sV����	!�	!�H��h����y�~�~�'�'�4�4�X�>�>�?�?�1�D�D� �5�5���trc	�.�tj|j��}|���D]f}d|vr�t	td�|�d������}t|��dkr�L|j�	|���gdS)zU
        Loads conflicting extensions from file and saves'em as list of sets
        r]c�*�|���Srr[r;s rr=z:ClExtSelect._load_conflicting_extensions.<locals>.<lambda>�s��a�g�g�i�i�r�N)
r�read_file_as_string�CONFLICTS_PATH�
splitlinesrErDrarkrrG)r�	conflictsr��conflict_sets    rr�z(ClExtSelect._load_conflicting_extensions�s����-�d�.A�B�B�	��(�(�*�*�	1�	1�D��$�����s�$7�$7�$�*�*�S�/�/�J�J�K�K�L��<� � �1�$�$���O�"�"�<�0�0�0�0�
	1�	1rc�f�|�|��}	g}tj|��D]T}|�d��s�|d|�d���}||jvr�?|�|���Ut|��S#t$rtj
|���wxYw)z`
        Loads alternative extensions list for a version
        @param version: string
        r�N)rlr��listdir�endswithrorrGrIr�r	rC)rr*ry�alt_extensions�filenamer�s      rrBz!ClExtSelect._load_extensions_list�s���
�)�)�'�2�2��	@��N��J�x�0�0�
1�
1���(�(��0�0���$�%;�h�m�m�F�&;�&;�%;�<�	��� 7�7�7���%�%�i�0�0�0�0��.�)�)�)���	@�	@�	@� �6�w�?�?�?�	@���s�A9B�B0c	�R�|D]#\}}tjdd|�d|�d�d����$dS)zR
        Prints info
        @param ext: string
        @param data: list
        �text�WARNz enabled as dependency (�)�rU�messageN�r
�
print_diag)�dependens_infor<rTs   r�_print_dependencies_infoz$ClExtSelect._print_dependencies_info�s]��'�	�	�H�Q�����!��A�A�s�s�s����
�
�
�
�	�	rc�r���|sgSt|����g��}��fd�|D��S)zv
        Get array of dependenses [(ext, depending ext)]
        @param ext: string
        @param data: list
        c� ��g|]
}|�v�|�f��Sr:r:)rr<rTr+s  ��r�
<listcomp>z5ClExtSelect.get_dependencies_list.<locals>.<listcomp>�s'���<�<�<�Q�!�8�*;�*;��C��*;�*;�*;r)rEr�)rTrer+�diffs` ` r�get_dependencies_listz!ClExtSelect.get_dependencies_list�sK�����	��I��4�y�y�#�#�S�E�*�*��<�<�<�<�<�$�<�<�<�<rc�`�tt|���|����Sr)r?rEr�)�	init_list�
processed_sets  r�get_conflicts_infozClExtSelect.get_conflicts_info�s$���C�	�N�N�-�-�m�<�<�=�=�=rc�N�|r |D]}tjdd|�d�d����dSdS)z~
        Prepares data for printing conflicts if any
        @param init_list: list
        @param processed_set: set
        r�r�z skipped as conflictingr�Nr�)r�r<s  r�_print_conflicts_infoz!ClExtSelect._print_conflicts_info�sp���	E��
E�
E���"��%�?@�q�q� B�D�D�E�E�E�E�	E�	E�
E�
Er)r)Tr)�__name__�
__module__�__qualname__rr�r�rrr.r1r5rWr@r&r0r4r��classmethodrlrrr�r��staticmethodrqr�r�rBr�r�r�r�r:rrr
r
s;�������9�;�;�	9�:�:�
8��
!�O�7�7�7�7�3�3�3�E�E�E�>�>�>�"
N�
N�
N�9I�9I�9I�v0�0�0�*�*�*�*�@.*�.*�.*�.*�` *� *� *� *�D���!�[��0�0�N�(�(�(�6�6�6�6�n(�K�(=�>�>�� � � �&$��$5�6�6�����*)�L�)>�?�?�����$���1�1�1�@�@�@�&����\���	=�	=��\�	=��>�>��\�>��E�E��\�E�E�Err
)�
__future__rrrr�rbr�rJ�clcommon.clcagefsr�clselectr�clselectexceptr	�
clselectprintr
r�r�dictr�r
r:rr�<module>r�s��'�&�&�&�&�&�%�%�%�%�%�%���������������	�	�	�	�����'�'�'�'�'�'�������*�*�*�*�*�*�"�"�"�"�"�"��������d�f�f��bE�bE�bE�bE�bE�(�bE�bE�bE�bE�bEr

Zerion Mini Shell 1.0