%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/xdg/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/xdg/__pycache__/MenuEditor.cpython-312.pyc

�

�u�c�I���dZddlZ	ddlmcmZddlm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZGd�de�Zy#e$rddlmcmZY�>wxYw)	z CLass to edit XDG Menus �N)�Menu�	MenuEntry�Layout�	Separator�XMLMenuBuilder)�xdg_config_dirs�
xdg_data_dirs)�ParsingError)�setRootModec��eZdZd(d�Zd(d�Zd�Zd)d�Zd*d�Zd+d�Zd+d�Z	d+d	�Z
d+d
�Zd+d�Zd,d�Z
d-d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Zd�Zd�Zd�Zd.d�Zd�Zd�Zd/d�Zd�Z d �Z!d!�Z"d+d"�Z#d+d#�Z$d$�Z%d%�Z&d&�Z'd'�Z(y)0�
MenuEditorNc��d|_d|_d|_t�|_|j|||�g|_y�N)�menu�filename�treer�parser�parse�	filenames��selfrr�roots    �0/usr/lib/python3/dist-packages/xdg/MenuEditor.py�__init__zMenuEditor.__init__s:����	���
���	�$�&����
�
�4��4�(����c�J�|rtd�t|t�r||_nB|r!|jj|�|_n|jj�|_|r|jj|_nk|r||_natjjtddtjj|jj�d�|_	tj
|j�|_|j'|j�y#t$rItj d|jjz�}tj"|�|_Y�mt$$rt%d|j��wxYw)NTr�menus�z�
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" "http://standards.freedesktop.org/menu-spec/menu-1.0.dtd">
    <Menu>
        <Name>Applications</Name>
        <MergeFile type="parent">%s</MergeFile>
    </Menu>
zNot a valid .menu file)r�
isinstancerrrr�Filenamer�os�path�joinr�split�etreer�IOError�
fromstring�ElementTreer
�$_MenuEditor__remove_whitespace_nodesrs    rrzMenuEditor.parse$s>�������d�D�!��D�I�
����)�)�$�/�D�I����)�)�+�D�I�� �I�I�.�.�D�M�
�$�D�M��G�G�L�L���);�W�b�g�g�m�m�TX�T]�T]�Tf�Tf�Fg�hi�Fj�k�D�M�	H����D�M�M�2�D�I�	
�&�&�t�y�y�1���	0��#�#�%��i�i���
%��D��)�)�$�/�D�I��	H��7����G�G�	H�s�2$D2�2AF"�F"c�Z�|j|j�|j�yr)�_MenuEditor__saveEntriesr�_MenuEditor__saveMenu�rs r�savezMenuEditor.saveGs�����4�9�9�%����rc
	���t|j|d��}
|j|
||||||�}
|j||
||	�|jj�|
S)N�.desktop)r�_MenuEditor__getFileName�
editMenuEntry�_MenuEditor__addEntryr�sort)r�parent�name�command�genericname�comment�icon�terminal�after�before�	menuentrys           r�createMenuEntryzMenuEditor.createMenuEntryKs]���d�0�0��z�B�C�	��&�&�y�$��W�g�W[�]e�f�	�����	�5�&�9��	�	�����rc��t�}||_|jdz|_|j|_|j|_|j|||||�}|j
||||�|jj�|S)Nr)	r�Parent�Depth�
DefaultLayoutr�editMenur3rr4)	rr5r6r8r9r:r<r=rs	         r�
createMenuzMenuEditor.createMenuUsv���v������\�\�A�%��
��*�*���#�1�1����}�}�T�4��g�t�D�������e�V�4��	�	�����rc�x�t|�}|j||||�|jj�|Sr)rr3rr4)rr5r<r=�	separators     r�createSeparatorzMenuEditor.createSeparatores2���f�%�	�����	�5�&�9��	�	�����rc��|j||||�|j||||�|jj�|Sr��_MenuEditor__deleteEntryr3rr4�rr>�	oldparent�	newparentr<r=s      r�
moveMenuEntryzMenuEditor.moveMenuEntryns<�����9�i���?����	�9�e�V�<��	�	�����rc	��|j||||�|j||||�|j|jj�}|jd�|jd�k7r�|j
|tjj|jd�|j�tjj|jd�|j��|jj�|S)NT)rKr3�_MenuEditor__getXmlMenur�Name�getPath�_MenuEditor__addXmlMover!r"r#r4)rrrMrNr<r=�	root_menus       r�moveMenuzMenuEditor.moveMenuvs������9�d�E�6�:����	�4���7��%�%�d�i�i�n�n�5�	����T�"�i�&7�&7��&=�=����i������i�6G�6G��6M�t�y�y�)Y�[]�[b�[b�[g�[g�hq�hy�hy�z~�h�BF�BK�BK�\L�
M��	�	�����rc��|j||||�|j||||�|jj�|SrrJ)rrGr5r<r=s     r�
moveSeparatorzMenuEditor.moveSeparator�s<�����6�9�e�V�<�����	�5�&�9��	�	�����rc�b�|j||||�|jj�|Sr)r3rr4rLs      r�
copyMenuEntryzMenuEditor.copyMenuEntry�s(�����	�9�e�V�<��	�	�����rc
�N�|j}
|r7|
jd�s|
jd|�|
jd|d��|r7|
jd�s|
jd|�|
jd|d��|r7|
jd�s|
jd|�|
jd|d��|r|
jd|�|r|
jd|�|r|
jdd	�n|s|
jdd
�|dur|
jdd	�n|dur|
jdd
�|	dur|
jd
d	�n|	dur|
jd
d
�|j�t	|j
�dkDr|jj�|S)NrRT��locale�Comment�GenericName�Exec�Icon�Terminal�true�false�	NoDisplayF�Hiddenr)�DesktopEntry�hasKey�set�updateAttributes�len�Parentsrr4)rr>r6r8r9r7r:r;�	nodisplay�hidden�	deskentrys           rr2zMenuEditor.editMenuEntry�sm���*�*�	���#�#�F�+��
�
�f�d�+��M�M�&�$�t�M�4���#�#�I�.��
�
�i��1��M�M�)�W�T�M�:���#�#�M�2��
�
�m�[�9��M�M�-��T�M�B���M�M�&�'�*���M�M�&�$�'���M�M�*�f�-���M�M�*�g�.�����M�M�+�v�.�
�%�
��M�M�+�w�/��T�>��M�M�(�F�+�
�u�_��M�M�(�G�,��"�"�$��y� � �!�A�%��I�I�N�N���rc��t|jt�r�|jjdk(rj|j	|jdd��}|j
|d|jdz�|jj|jdz�n�t|jt�s�|s|j}|j|d�jdd�}	|js|	jdd�|_|j	|jdd��}|j
|d|	�t|	�|_|jj}
|r7|
jd�s|
jd|�|
jd|d��|r7|
jd�s|
jd|�|
jd|d��|r7|
jd	�s|
jd	|�|
jd	|d��|r|
jd
|�|dur|
jdd�n|d
ur|
jdd�|dur|
jdd�n|d
ur|
jdd�|jj�t|jt �r|j"j%�|S)N�
.directoryT�	Directory�/�rRr\r_r^rarercFrdrf)rrrrr rQrS�_MenuEditor__addXmlTextElementrR�
setAttributesr1�replacergrhrirjrArrr4)rrr6r8r9r:rmrn�xml_menurros           rrDzMenuEditor.editMenu�s:���d�n�n�i�0�T�^�^�5L�5L�P\�5\��(�(����d�D�)A�B�H��$�$�X�{�D�I�I��<T�U��N�N�(�(����\�)A�B��D�N�N�I�6���y�y���)�)�$��=�E�E�c�2�N�H��9�9�$�,�,�\�2�>��	��(�(����d�D�)A�B�H��$�$�X�{�H�E�&�x�0�D�N��N�N�/�/�	���#�#�F�+��
�
�f�d�+��M�M�&�$�t�M�4���#�#�M�2��
�
�m�[�9��M�M�-��T�M�B���#�#�I�.��
�
�i��1��M�M�)�W�T�M�:���M�M�&�$�'�����M�M�+�v�.�
�%�
��M�M�+�w�/��T�>��M�M�(�F�+�
�u�_��M�M�(�G�,����'�'�)��d�k�k�4�(��I�I�N�N���rc�*�|j|d��y�NT)rm�r2�rr>s  r�
hideMenuEntryzMenuEditor.hideMenuEntry�s�����9���5rc�,�|j|dd��y)NF�rmrnr{r|s  r�unhideMenuEntryzMenuEditor.unhideMenuEntry�s�����9��e��Drc�*�|j|d��yrz)rD�rrs  r�hideMenuzMenuEditor.hideMenu�s���
�
�d�d�
�+rc���|j|dd��|j|jdd�d�}|jd�}|jd�}||zD]}|j	|��y)NFrT�Deleted�
NotDeleted)rDrQrS�findall�remove)rrrx�deleted�not_deleted�nodes      r�
unhideMenuzMenuEditor.unhideMenu�sq���
�
�d�e�E�
�:��$�$�T�\�\�$��%=�u�E���"�"�9�-���&�&�|�4���k�)�	"�D��O�O�D�!�	"rc���|j|�dk(rb|j|jj�|jD]}|j||��|jj�|S)N�delete)�	getAction�_MenuEditor__deleteFilergrrlrKrr4)rr>r5s   r�deleteMenuEntryzMenuEditor.deleteMenuEntry�sf���>�>�)�$��0����i�4�4�=�=�>�#�+�+�
6���"�"�6�9�5�
6��I�I�N�N���rc�
�|j|�dk(r�|j|jj�g|j_|j
D]�}|jj|�}|j|j|<|jj|�}|j|j|<|jj
j|���|jj�|S�N�revert)r�r�rgr�Originalrl�Entries�index�MenuEntries�appendrr4)rr>r5r�s    r�revertMenuEntryzMenuEditor.revertMenuEntrys����>�>�)�$��0����i�4�4�=�=�>�)+�I���&�#�+�+�
:�����,�,�Y�7��(1�(:�(:����u�%��*�*�0�0��;��,5�,>�,>��"�"�5�)��"�"�*�*�1�1�&�9�
:�
�I�I�N�N���rc�~�|j|�dk(r�|j|jjj�|j|j|�|j|jdd��}|j|�}|j|�|jj�|S)Nr�T)
r�r�rrrgrrKrArQrS�_MenuEditor__get_parent_noder�rr4)rrrxr5s    r�
deleteMenuzMenuEditor.deleteMenus����>�>�$��8�+����d�n�n�9�9�B�B�C����t�{�{�D�1��(�(����d�D�)A�B�H��+�+�H�5�F��M�M�(�#��I�I�N�N���rc��|j|�dk(rd|j|jjj�|jj
|_|jj�|Sr�)r�r�rrrgrr�rr4r�s  r�
revertMenuzMenuEditor.revertMenusU���>�>�$��8�+����d�n�n�9�9�B�B�C�!�^�^�4�4�D�N��I�I�N�N���rc�v�|j|j|d��|jj�|S)NT)r<)rKrArr4)rrGs  r�deleteSeparatorzMenuEditor.deleteSeparator%s1�����9�+�+�Y�d��C��	�	�����rc��t|t�r�t|jt�sy|jj	�dk(ry|jj	�dk(r/t|j�t|j�zdk(ryyt|t�r)|j	�dk(ry|j	�dk(ryyy)N�none�Bothr��Userrr�)rrrrr�getTyperk�Submenusr�)r�entrys  rr�zMenuEditor.getAction-s����e�T�"��e�o�o�y�9�����(�(�*�f�4�����(�(�*�f�4��E�N�N�#�c�%�*;�*;�&<�<��:� ����y�
)��}�}��&�(������F�*���rc�<�|s|j}t|jt�r|jj	�|jd��D]E}t|t�r|j	��$t|t�s�5|j|��Gy)NT)rn)rrrrrr.�
getEntriesrr+)rrr�s   r�
__saveEntrieszMenuEditor.__saveEntriesBsq����9�9�D��d�n�n�i�0��N�N���!��_�_�D�_�1�	*�E��%��+��
�
���E�4�(��"�"�5�)�		*rc�V�tjjtjj|j��s<tj
tjj|j��|jj|jd��y)Nzutf-8)�encoding)r!r"�isdir�dirnamer�makedirsr�writer-s r�
__saveMenuzMenuEditor.__saveMenuMsX���w�w�}�}�R�W�W�_�_�T�]�]�;�<��K�K�������
�
�6�7��	�	����
�
���8rc�R�d}	|dk(r||z}n|dzt|�z|z}|dk(rd}n|dk(rd}||jvrctjj	tjjtd|��s|jj|�	|S|dz
}��)Nrr�-r0�applicationsrqzdesktop-directories)�strrr!r"�isfiler#r	r�)rr6�	extension�postfixr�dirs      r�
__getFileNamezMenuEditor.__getFileNameRs�������!�|��)�+���#�:��G��4�y�@���J�&�$���l�*�+���t�~�~�-�b�g�g�n�n������]�1�-�s�H�=�7����%�%�h�/�����1���rc�d�|s|j}d|vr|jdd�\}}n|}d}d}|jd�D]>}|jd�}|j|k(r|r|j|||�}n|}|s�>n|s-|r+|j
||�}|r|j|||�}|S|}|S)NrsrrtrrR)rr$r��find�textrQ�_MenuEditor__addXmlMenuElement)rr"�create�elementr6�foundr��	name_nodes        r�__getXmlMenuzMenuEditor.__getXmlMenugs�����i�i�G��$�;��:�:�c�1�-�L�T�4��D��D����O�O�F�+�	�D��	�	�&�)�I��~�~��%�� �-�-�d�F�D�A�E� �E���	����+�+�G�T�:�D���)�)�$���=�������rc�l�tjd|�}tjd|�}||_|S)NrrR�r%�
SubElementr�)rr�r6�	menu_noder�s     r�__addXmlMenuElementzMenuEditor.__addXmlMenuElement�s3���$�$�V�W�5�	��$�$�V�Y�7�	��	���rc�@�tj||�}||_|Srr�)rr�r6r�r�s     r�__addXmlTextElementzMenuEditor.__addXmlTextElement�s ������g�.����	��rc�"�|jd�}|jd�}||z}|D]9}|djdk(s�|dj|k(s�)|j|��;t	j
||�}|j
|d|�|S)N�Include�Excluderr )r��tagr�r�r%r�ru)	rr�r�type_�includes�excludes�rules�ruler�s	         r�__addXmlFilenamezMenuEditor.__addXmlFilename�s����?�?�9�-���?�?�9�-���8�#���	%�D��A�w�{�{�j�(�T�!�W�\�\�X�-E����t�$�	%�����w�/��� � ��z�8�<��rc�~�tjd|�}|j|d|�|j|d|�|S)N�Move�Old�New)r%r�ru)rr��old�newr�s     r�__addXmlMovezMenuEditor.__addXmlMove�s=�������0��� � ��u�c�2�� � ��u�c�2��rc��|jd�D]}|j|��tjd|�}|jD]�}|ddk(rtjd|�}�"|ddk(r|j|d|d�}�A|ddk(r|j|d|d�}�`|ddk(s�itjd|�}|d|jd<��|S)	Nrrrr r�Menuname�Merge�type)r�r�r%r��orderru�attrib)rr��layoutr�r��childs      r�__addXmlLayoutzMenuEditor.__addXmlLayout�s����O�O�H�-�	!�D��N�N�4� �	!�����'�2���\�\�		0�E��Q�x�;�&��(�(��d�;���q��Z�'��0�0��z�5��8�L���q��Z�'��0�0��z�5��8�L���q��W�$��(�(��$�7��',�Q�x����V�$�		0��rc���t�}g|_|jj|_|jj|_|jj|_|jj
|_|jj|_|jjddg�|jD]{}t|t�r|j|j��/t|t�r|j|j��[t|t �s�l|j#��}|jjddg�||_|S)Nr�r�files)rr��
show_empty�inline�
inline_header�inline_alias�inline_limitr�r�rr�
parseMenunamerRr�
parseFilename�
DesktopFileIDr�parseSeparator)rr5r�r�s    r�__addLayoutzMenuEditor.__addLayout�s��������"�M�M�4�4����
�
�,�,��
�%�}�}�:�:���$�m�m�8�8���$�m�m�8�8��������W�g�.�/��^�^�	(�E��%��&��$�$�U�Z�Z�0��E�9�-��$�$�U�%8�%8�9��E�9�-��%�%�'�
	(�	�����W�g�.�/���
��
rc��|s|r[|r|jj|�dz}n|r|jj|�}|jj|�n|jj|�|j	|jdd��}t
|t�rT|jj|�|jj|�|j||jd�n!t
|t�r|j|�|s|r.|j|�|j||j �yy)NrTr�)r�r��insertr�rQrSrrr�rl�_MenuEditor__addXmlFilenamer�r�
addSubmenu�_MenuEditor__addLayout�_MenuEditor__addXmlLayoutr)rr5r�r<r=r��
xml_parents       r�
__addEntryzMenuEditor.__addEntry�s���F�����,�,�U�3�a�7������,�,�V�4���N�N�!�!�%��/��N�N�!�!�%�(��&�&�v�~�~�d�D�'A�B�
��e�Y�'����%�%�e�,��M�M� � ��(��!�!�*�e�.A�.A�9�M�
��t�
$����e�$��F����V�$����
�F�M�M�:�rc��|jj|�|j|jdd��}t	|t
�rT|jj|�|jj|�|j||jd�n+t	|t�r|jj|�|s|r.|j|�|j||j�yy)NTr�)r�r�rQrSrrrlr�r�r�rr�r�r�r)rr5r�r<r=r�s      r�
__deleteEntryzMenuEditor.__deleteEntry�s��������e�$��&�&�v�~�~�d�D�'A�B�
��e�Y�'��M�M� � ��(����%�%�e�,��!�!�*�e�.A�.A�9�M�
��t�
$��O�O�"�"�5�)��F����V�$����
�F�M�M�:�rc��	tj|�	|jj|�y#t$rY�(wxYw#t$rYywxYwr)r!r��OSErrorr�
ValueError)rrs  r�__deleteFilezMenuEditor.__deleteFile�sQ��	��I�I�h��	��N�N�!�!�(�+���	��	���	��	�s�4�A�	A�A�	A�Ac���|D]e}|jj�}|sd|_|jj�}|sd|_t|�s�U|j	|��gy)Nrt)r��strip�tailrk�$_MenuEditor__remove_whilespace_nodes)rr�r�r�rs     r�__remove_whitespace_nodesz$MenuEditor.__remove_whitespace_nodes	s^���	6�E��:�:�#�#�%�D����
��:�:�#�#�%�D����
��5�z��.�.�u�5�	6rc�D�|j�D]
\}}||us�|cSyr)�_MenuEditor__iter_parent)rr�r5r�s    r�__get_parent_nodezMenuEditor.__get_parent_nodes*��!�/�/�1�	�M�F�E���}���	rc#�dK�|jj�D]}|D]}||f���
�y�wr)r�getiterator)rr5r�s   r�
__iter_parentzMenuEditor.__iter_parents;�����i�i�+�+�-�	$�F��
$���e�m�#�
$�	$�s�.0)NNF)NNNNNNN)NNNNN)NN)NNNNNNNN)NNNNNN)TN)r�))�__name__�
__module__�__qualname__rrr.r?rErHrOrVrXrZr2rDr}r�r�r�r�r�r�r�r�r�r+r,r1rQr�rur�rTr�r�r3rKr�r)r�r�rrr
r
s����!2�F��� ��
���(�T1�f6�E�,�"��������*	*�9�
�*�@��
�,��&�.;�.;� �	6��$rr
)�__doc__r!�xml.etree.cElementTreer%�cElementTree�ImportError�xml.etree.ElementTreer(�xdg.Menurrrrr�xdg.BaseDirectoryrr	�xdg.Exceptionsr
�
xdg.Configr�objectr
rrr�<module>rsM���	�*�*�*�H�G�<�'�"�E$��E$��'�*�)�)�*�s�	?�A�A

Zerion Mini Shell 1.0