Mini Shell

Direktori : /usr/lib/python3.6/site-packages/xdg/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/xdg/__pycache__/Menu.cpython-36.opt-1.pyc

3

�N�P���@s�dZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZm
Z
mZddlmZddlZddlZejjjZdd�ZGd	d
�d
�ZGdd�d�ZGd
d�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZiZdd�Z dIdd�Z!dJdd�Z"dd�Z#dd �Z$d!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(d)d*�Z)d+d,�Z*d-d.�Z+d/d0�Z,d1d2�Z-d3d4�Z.d5d6�Z/d7d8�Z0d9d:�Z1d;d<�Z2d=d>�Z3d?d@�Z4dAdB�Z5dCdD�Z6dEdF�Z7GdGdH�dH�Z8dS)Ka�
Implementation of the XDG Menu Specification Version 1.0.draft-1
http://standards.freedesktop.org/menu-spec/

Example code:

from xdg.Menu import parse, Menu, MenuEntry

def print_menu(menu, tab=0):
  for submenu in menu.Entries:
    if isinstance(submenu, Menu):
      print ("	" * tab) + unicode(submenu)
      print_menu(submenu, tab+1)
    elif isinstance(submenu, MenuEntry):
      print ("	" * tab) + unicode(submenu.DesktopEntry)

print_menu(parse())
�N)�
xdg_data_dirs�xdg_config_dirs)�DesktopEntry)�ParsingError�ValidationError�debug)�PY3cCs$trt|t�r|jd�}tj|�S)zkWrapper around locale.strxfrm that accepts unicode strings on Python 2.
    
    See Python bug #2481.
    zutf-8)r�
isinstance�unicode�encode�locale�strxfrm)�s�r�/usr/lib/python3.6/Menu.py�_strxfrm!s
rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
d$dd�Zd%dd�Zdd�Z
d&dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)'�Menuz[Menu containing sub menus under menu.Entries

	Contains both Menu and MenuEntry items.
    cCs�d|_d|_g|_d|_d|_d|_d|_d|_d|_d|_	g|_
d|_d|_g|_
g|_d|_g|_g|_d|_g|_g|_dS)N�rFT�notset)�Name�	Directory�Entries�Doc�Filename�Depth�Parent�NotInXml�Show�Visible�AppDirs�
DefaultLayout�Deleted�Directories�
DirectoryDirs�Layout�MenuEntries�Moves�OnlyUnallocated�Rules�Submenus)�selfrrr�__init__/s*z
Menu.__init__cCs|jS)N)r)r*rrr�__str__KszMenu.__str__cCs�x|jD]}|jj|�qWx|jD]}|jj|�q$Wx|jD]}|jj|�q@W|jdkrf|j|_|jdkrx|j|_|jr�|j|_|jr�|j|_x|jD]}|jj|�q�Wx|j	D]}|j	j|�q�Wx|j
D]}|j|�q�W|S)Nr)r�appendr#r"r!r'r$r r(r&r)�
addSubmenu)r*�other�dir�	directory�rule�move�submenurrr�__add__Ns*

zMenu.__add__cCstj|j�|j��S)N)r�strcoll�getName)r*r/rrr�__cmp__pszMenu.__cmp__cCst|j��S)z&Key function for locale-aware sorting.)rr7)r*rrr�_keyssz	Menu._keycCs.y|j�}Wntk
r YnX|j�|kS)N)r9�AttributeError)r*r/rrr�__lt__ws
zMenu.__lt__cCs2y|jt|�kStk
r,|jt|�kSXdS)N)rr
�	NameError�str)r*r/rrr�__eq__~szMenu.__eq__Fccs4x.|jD]$}|dkr|Vq|jdkr|VqWdS)z4Interator for a list of Entries visible to the user.TN)rr)r*Zhidden�entryrrr�
getEntries�s

zMenu.getEntriescCsFx|jD]}|j|kr|SqW|dkrBx|jD]}|j||�q.WdS)z4Searches for a MenuEntry with a given DesktopFileID.TN)r%�
DesktopFileIDr)�getMenuEntry)r*Z
desktopfileidZdeep�	menuentryr4rrrrB�s
zMenu.getMenuEntrycCsL|jdd�}x:|jD]0}|j|dkrt|�dkr@|j|d�S|SqWdS)z&Searches for a Menu with a given path.�/�rN)�splitr)r�len�getMenu)r*�pathZarrayr4rrrrH�szMenu.getMenucCs�|}g}x8|r|j|j�n|j|j��|jdkr<|j}q
Pq
W|j�d}|dkr`|jd�x|D]}tjj	||�}qfW|S)z/Returns this menu's path in the menu structure.rrF)
r-rr7rr�reverse�pop�osrI�join)r*ZorgZtoplevel�parent�namesrI�namerrr�getPath�s 


zMenu.getPathcCs(y|jjj�Stk
r"|jSXdS)z"Returns the menu's localised name.N)rrr7r:r)r*rrrr7�szMenu.getNamecCs&y|jjj�Stk
r dSXdS)z Returns the menu's generic name.rN)rr�getGenericNamer:)r*rrrrR�szMenu.getGenericNamecCs&y|jjj�Stk
r dSXdS)z Returns the menu's comment text.rN)rr�
getCommentr:)r*rrrrS�szMenu.getCommentcCs&y|jjj�Stk
r dSXdS)z0Returns the menu's icon, filename or simple namerN)rr�getIconr:)r*rrrrT�szMenu.getIconcCsDx>|jD]}||kr||7}PqW|jj|�||_|jd|_dS)NrE)r)r-rr)r*�newmenur4rrrr.�szMenu.addSubmenuN)F)F)FF)�__name__�
__module__�__qualname__�__doc__r+r,r5r8r9r;r>r@rBrHrQr7rRrSrTr.rrrrr*s""

	

rc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MovezA move operationNcCs |r|j|�nd|_d|_dS)Nr)�	parseNode�Old�New)r*�noderrrr+�sz
Move.__init__cCst|j|j�S)N)Zcmpr\)r*r/rrrr8�szMove.__cmp__cCs�x�|jD]�}|jtkr|jdkrXy|j|jdj�Wq�tk
rTtdd��Yq�Xq|jdkry|j|jdj�Wqtk
r�tdd��YqXqWdS)Nr\rzOld cannot be emptyz??r]zNew cannot be empty)	�
childNodes�nodeType�ELEMENT_NODE�tagName�parseOld�	nodeValue�
IndexErrorr�parseNew)r*r^�childrrrr[�s


zMove.parseNodecCs
||_dS)N)r\)r*�valuerrrrc�sz
Move.parseOldcCs
||_dS)N)r])r*rhrrrrf�sz
Move.parseNew)N)	rVrWrXrYr+r8r[rcrfrrrrrZ�s
rZc@sFeZdZdZddd�Zdd�Zdd
d�Zdd
�Zdd�Zddd�Z	dS)r$zMenu Layout classNcCs�g|_|rr|jd�pd|_|jd�p&d|_|jd�p6d|_|jd�pFd|_|jd�pVd|_t|j�|_|j|�n>d|_d|_d|_d|_d|_|jj	d	d
g�|jj	d	dg�dS)N�
show_empty�false�inline�inline_limit��
inline_header�true�inline_alias�Merge�menus�files)
�order�getAttributerirkrlrnrp�intr[r-)r*r^rrrr+s zLayout.__init__cCs�x|jD�]}|jtkr
|jdkr�yR|j|jdj|jd�p@d|jd�pLd|jd�pXd|jd�pdd	|jd
�ppd�Wntk
r�tdd��YnXq
|jd
kr�|j	�q
|jdkr�y|j
|jdj�Wntk
r�tdd��YnXq
|jdkr
|j|jd��p
d�q
WdS)N�MenunamerrirjrkrlrmrnrorpzMenuname cannot be emptyr�	SeparatorrzFilename cannot be emptyrq�type�all)r_r`rarb�
parseMenunamerdrurer�parseSeparator�
parseFilename�
parseMerge)r*r^rgrrrr[s,






zLayout.parseNoderjrmrocCs:|jjd||||||g�t|jdd�|jdd<dS)NrwrErm���r)rtr-rv)r*rh�emptyrkrlrnrprrrr{-szLayout.parseMenunamecCs|jjdg�dS)Nrx)rtr-)r*rrrr|1szLayout.parseSeparatorcCs|jjd|g�dS)Nr)rtr-)r*rhrrrr}4szLayout.parseFilenamerzcCs|jjd|g�dS)Nrq)rtr-)r*ryrrrr~7szLayout.parseMerge)N)rjrjrmrorj)rz)
rVrWrXrYr+r[r{r|r}r~rrrrr$s

r$c@sleZdZdZddd�Zdd�Zdd�Zd	d
�Zddd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�RulezInlcude / Exclude Rules ClassNcCs2||_d|_d|_dg|_d|_|r.|j|�dS)Nrr�orT)�Typer�r�Exprr]r[)r*ryr^rrrr+=sz
Rule.__init__cCs|jS)N)r�)r*rrrr,LszRule.__str__cCsXxR|D]J}|dkr*|jdks|jdkr*qqt|j�r|dkrJd|_d|_qd|_qW|S)N�T�IncludeF)�MatchedInclude�	Allocated�evalr��Add)r*�menuentriesryZrunrCrrr�doOs



zRule.docCs�x�|jD]�}|jtkr|jdkrXy|j|jdj�Wq�tk
rTtdd��Yq�Xq|jdkr�y|j|jdj�Wq�tk
r�tdd��Yq�Xq|jdkr�|j	�q|jdkr�|j
|�q|jd	kr�|j|�q|jd
kr|j|�qWdS)NrrzFilename cannot be emptyz???ZCategoryzCategory cannot be emptyZAllZAndZOrZNot)
r_r`rarbr}rdrer�
parseCategory�parseAll�parseAnd�parseOr�parseNot)r*r^rgrrrr[\s(







zRule.parseNodeTcCs>|js$|jd|j|jd7_|s0d|_n
|r:d|_dS)N� TF)r]r�r�r)r*�setrrrrfrsz
Rule.parseNewcCs2|j�|jd|j�jdd�jdd�7_dS)Nzmenuentry.DesktopFileID == '%s'�\z\\�'z\')rfr��strip�replace)r*rhrrrr}zszRule.parseFilenamecCs"|j�|jd|j�7_dS)Nz'%s' in menuentry.Categories)rfr�r�)r*rhrrrr�~szRule.parseCategorycCs|j�|jd7_dS)N�True)rfr�)r*rrrr��sz
Rule.parseAllcCsf|jd�|jd7_|jd7_|jjd�|j|�|jd8_|jj�|jd7_dS)NF�(rE�and�))rfr�rr�r-r[rK)r*r^rrrr��s


z
Rule.parseAndcCsf|jd�|jd7_|jd7_|jjd�|j|�|jd8_|jj�|jd7_dS)NFr�rEr�r�)rfr�rr�r-r[rK)r*r^rrrr��s


zRule.parseOrcCsf|jd�|jd7_|jd7_|jjd�|j|�|jd8_|jj�|jd7_dS)NFznot (rEr�r�)rfr�rr�r-r[rK)r*r^rrrr��s


z
Rule.parseNot)N)T)rVrWrXrYr+r,r�r[rfr}r�r�r�r�r�rrrrr�;s




r�c@steZdZdZddd�Zdd�Zdd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�	MenuEntryz(Wrapper for 'Menu Style' Desktop EntriesrcCsVttjj||��|_|j|||�d|_d|_g|_d|_d|_	d|_
|jj�|_dS)NTF)
rrLrIrM�
setAttributesr�Original�Parentsr�r�r�Z
getCategories�
Categories)r*�filenamer0�prefixrrrr+�szMenuEntry.__init__cCs|jjdkr|jj�dS)z&Save any changes to the desktop entry.TN)rZtainted�write)r*rrr�save�szMenuEntry.savecCs|jjj|jd�S)z7Return the directory containing the desktop entry file.r)rr�r�r)r*rrr�getDir�szMenuEntry.getDircCs8tjjdkr0|jrdStd|jjkr*dSdSndSdS)z.Return the type of MenuEntry, System/User/BothFZBothr�User�SystemN)�xdg�Config�	root_moder�rrr�)r*rrr�getType�szMenuEntry.getTypecCs@||_||_tjj||�jdd�|_tjj|jj	�s<|j
�dS)NrD�-)r�PrefixrLrIrMr�rA�isabsrr��_MenuEntry__setFilename)r*r�r0r�rrrr��s
zMenuEntry.setAttributescCs.|j�dkr*t|j|j�|j�|_|j�dS)Nr�)r�r�rr�r�r�r�)r*rrr�updateAttributes�szMenuEntry.updateAttributescCsbtjjdkrtd}ntd}|jj�dkr<tjj|d�}ntjj|d�}tjj||j	�|j_
dS)NFrrEZApplication�applicationszdesktop-directories)r�r�r�rrr�rLrIrMrr�)r*rIr0rrrZ
__setFilename�s
zMenuEntry.__setFilenamecCstj|jj�|jj��S)N)rr6rr7)r*r/rrrr8�szMenuEntry.__cmp__cCst|jj��S)z&Key function for locale-aware sorting.)rrr7)r*rrrr9�szMenuEntry._keycCs.y|j�}Wntk
r YnX|j�|kS)N)r9r:)r*r/rrrr;�s
zMenuEntry.__lt__cCs|jt|�krdSdSdS)NTF)rAr=)r*r/rrrr>�szMenuEntry.__eq__cCs|jS)N)rA)r*rrr�__repr__�szMenuEntry.__repr__N)rr)rr)rVrWrXrYr+r�r�r�r�r�r�r8r9r;r>r�rrrrr��s


r�c@seZdZdZdd�ZdS)rxz!Just a dummy class for SeparatorscCs||_d|_dS)NT)rr)r*rNrrrr+szSeparator.__init__N)rVrWrXrYr+rrrrrxsrxc@s eZdZdZdd�Zdd�ZdS)�HeaderzClass for Inline HeaderscCs||_||_||_dS)N)r�GenericName�Comment)r*rPZgeneric_nameZcommentrrrr+szHeader.__init__cCs|jS)N)r)r*rrrr,szHeader.__str__N)rVrWrXrYr+r,rrrrr�
sr�cCs`tdd�}tjjdkr"|jd�x8|D]0}tjj|d|�}tjj|�r(tjj	|�r(|Sq(WdS)NTrrr)
rr�r�r�rKrLrIrM�isdir�isfile)r��dirsr0Zmenunamerrr�
__getFileNames

r�c
Cs*|rtjj|�rt|�}|s8tjjdd�d}t|�}|sJtdd|��tjj|�ddkshtd|��ytj	j
j|�}Wn$tjj
jk
r�td	|��YnXdtd
<gtd<gtd<t�td
<t||td
�ttd
�ttd
�|td
_|td
_ttd
�ttd
�ttd
�td
S)z�Load an applications.menu file.
    
    filename : str, optional
      The default is ``$XDG_CONFIG_DIRS/menus/${XDG_MENU_PREFIX}applications.menu``.
    ZXDG_MENU_PREFIXrzapplications.menuzFile not foundz/etc/xdg/menus/%srEz.menuzNot a .menu filezNot a valid .menu file�Root�
mergeFilesr#�cache)rLrIr�r��environ�getr�splitext�xml�dom�minidom�parse�parsers�expat�
ExpatError�tmp�MenuEntryCache�__parse�__parsemove�__postparserr�__genmenuNotOnlyAllocated�__genmenuOnlyAllocated�sort)r��	candidate�docrrrr�!s4



r�cCs��x�|jD�]�}|jtkr
|jdkr2t|||�q
|jdkrvyt|jdj||�Wntk
rrtd|��YnXq
|jdkr�t	||�q
|jdkr�yt
|jdj||�Wntk
r�td|��YnXq
|jdkr�t||�q
|jd	k�r(y|jdj|_Wn tk
�r$td
|��YnXq
|jdk�rpy|j
j|jdj�Wn tk
�rltd|��YnXq
|jd
k�r�d|_q
|jdk�r�d|_q
|jdk�r�d|_q
|jdk�r�d|_q
|jdk�s�|jdk�r�|jjt|j|��q
|jdk�rXy:|jd�dk�rtd|||�nt|jdj|||�Wn tk
�rTtd|��YnXq
|jdk�r�yt|jdj|||�Wn tk
�r�td|��YnXq
|jdk�r�t|||�q
|jdk�r�|jjt|��q
|jdk�rt|j�dk�r�t|�|_q
|jd k�r*t|j�dk�r�t|�|_q
|jd!k�rzy t|jdj|jd"�||�Wn tk
�rvtd#|��YnXq
|jd$kr
t||�q
WdS)%NrZAppDirrzAppDir cannot be emptyZDefaultAppDirsZDirectoryDirzDirectoryDir cannot be emptyZDefaultDirectoryDirsrzName cannot be emptyrzDirectory cannot be emptyr'TZNotOnlyUnallocatedFr!Z
NotDeletedr�ZExcludeZ	MergeFileryrNzapplications.menuzMergeFile cannot be emptyZMergeDirzMergeDir cannot be emptyZDefaultMergeDirsrZr$rEr Z	LegacyDirr�zLegacyDir cannot be emptyZ
KDELegacyDirs)r_r`rarb�__parseMenu�
__parseAppDirrdrer�__parseDefaultAppDir�__parseDirectoryDir�__parseDefaultDirectoryDirrr"r-r'r!r(r�ru�__parseMergeFile�__parseMergeDir�__parseDefaultMergeDirsr&rZrGr$r �__parseLegacyDir�__parseKDELegacyDirs)r^r�rNrgrrrr�Ts�





 
r�cCs�x|jD]}t|�qWx�|jD]�}|j|j�}|r |j|j�}|jjd�}d}xdt|�dkr�|sf|}|j|d�}|s�t�}|d|_	t|�dkr�d|_
|j|�|}|jd�qRW||7}|j
jj|�q WdS)NrDrrET)r)r�r&rHr\r]rFrGrrrr.rKr�remove)�menur4r3Zmove_from_menuZmove_to_menurrZ	oldparentrUrrrr��s,

r�cCs�|jdkrd|_|jdkr d|_|js0|jr�|jr@|j|_nV|jrf|jdkr\|jj|_q�t�|_n0|jdkr�|jj|_|jj|_nt�|_t�|_|jdkr�|jj|j|_|jj|j|_t|j	�|_	t|j�|_t|j�|_x|j
D]}t|�q�W|j	j�|jj�|jj�x�|j	D]z}xh|jD]^}t
jjt
jj||���r.t||�}|j�sd||_n&|j�dk�r.|jj�dk�r.||j_�q.W|j�r"P�q"WdS)NrFrr�r�)r!r'r$r rrrr#�__removeDuplicatesr"r)r�rJrLrIr�rMr�rr�r�)r�r4r1r0rCrrrr��sL











r�cCs.t�}t|||�|r"|j|�n|td<dS)Nr�)rr�r.r�)rgr�rN�mrrrr��s
r�cCs�tjj|�}tjj|�s&tjj||�}tjj|�}|dkrVtjj|�rVtjj|�rV|S|dkrztjj|�rztjj|�rz|SdSdS)Nr0�fileF)	rLrI�dirnamer�rM�abspath�existsr�r�)rhr�ryrIrrr�__check�s  r�cCs t||d�}|r|jj|�dS)Nr0)r�rr-)rhr�rNrrrr�	sr�cCs,x&tt�D]}ttjj|d�||�q
WdS)Nr�)�reversedrr�rLrIrM)r�rNr0rrrr�sr�cCs t||d�}|r|jj|�dS)Nr0)r�r#r-)rhr�rNrrrr�sr�cCs,x&tt�D]}ttjj|d�||�q
WdS)Nzdesktop-directories)r�rr�rLrIrM)r�rNr0rrrr�sr�cCs�|jd�dkr~x�tD]d}|j|d�jd�}||krxDtD]<}||krFq8tjjtjj||��r8ttjj||�||�Pq8WqWnt	||d�}|r�t|||�dS)NryrNrrDr�)
rurr�r�rLrIr�rM�__mergeFiler�)rhrgr�rNr0Zrel_file�prrrr�s

r�cCsnt||d�}|rjxXtj|�D]J}y.tjj|�ddkrLttjj||�||�Wqtk
rdwYqXqWdS)Nr0rEz.menu)r�rL�listdirrIr�r�rM�UnicodeDecodeError)rhrgr�rN�itemrrrr�,sr�cCsLtjjtjj|��d}x.tt�D]"}ttjj|d|d�|||�q"WdS)Nrrrz-merged)rLrIr��basenamer�rr�rM)rgr�rNr�r0rrrr�6sr�c
Cs�|tdkr trtd|��ndStdj|�ytjjj|�}WnTtk
rhtr`td|��ndSYn.tj	j
jk
r�tr�td|��ndSYnXx&|jD]}|j
tkr�t|||�Pq�WdS)Nr�z Infinite MergeFile loop detectedzFile not foundzNot a valid .menu file)r�rrr-r�r�r�r��IOErrorr�r�r�r_r`rar�)r�rgrNr�rrrr�;s&

r�cCst||||�}|r||7}dS)N)�__mergeLegacyDir)r0r�r�rNr�rrrr�Zsr�c

Csft||d�}|o|tdk�rbtdj|�t�}|jj|�|jj|�tjj|�|_	d|_
xxtj|�D]j}yN|dkr�|jj|�n4tjj
tjj||��r�|jttjj||�|||��Wqjtk
r�wjYqjXqjWtdj|g|d�tdj|gd�}x^|D]V}|j}t|�dk�r<td�}	|	j|j�|jj|	�||jk�r|jd	�||_�qW|SdS)
Nr0r#Tz
.directoryr�Frr�ZLegacy)r�r�r-rrr#rLrIr�rrr�r"r�rMr.r�r��addMenuEntries�getMenuEntriesr�rGr�r}rAr()
r0r�r�rNr�r�r�rCZ
categories�rrrrr�_s8"

r�cCs�y,tjdddgtjdd�}|j�dj�}Wntk
r@dSXy*x$|djd�D]}t|d||�qTWWntk
r�YnXdS)	Nz
kde-configz--pathZappsT)�stdoutZuniversal_newlinesr�:Zkde)	�
subprocess�Popen�PIPEZcommunicate�
splitlines�OSErrorrFr�re)r�rN�proc�outputr0rrrr��sr�cs*i�|j��fdd�|D�}|j�|S)Ncs g|]}|�kr�j||��qSr)�
setdefault)�.0�e)r�rr�
<listcomp>�sz&__removeDuplicates.<locals>.<listcomp>)rJ)�listr)r�rr��s
r�cCs�x|jD]}t|�qW|jdkr�tdj|j�g}x*|jD] }|jtdj|j�|j	d�}q>Wx:|D]2}|j
dkrh|jj|�d|_
d|_
|jj|�qhWdS)NFr�rET)r)r�r'r�r�rr(r�r�r�r�r�r-r�r%)r�r4r�r2rCrrrr��s
 

r�cCs�x|jD]}t|�qW|jdkr�tdj|j�g}x*|jD] }|jtdj|j�|j	d�}q>Wx.|D]&}|j
dkrh|jj|�|j
j|�qhWdS)NTr�r�)r)r�r'r�r�rr(r�r�r�r�r�r-r%)r�r4r�r2rCrrrr��s
 

r�cCsRg|_d|_x|jD]}t|�qWg}g}xF|jjD]:}|ddkrV|j|d�q6|ddkr6|j|d�q6W�xZ|jjD�]L}|ddkr�t|�}t|j�dkr�t	|jdt�r�d|_
|jj|�q�|ddkr�|j|d�}|r�|jj|�q�|ddk�r&|j|d�}|�r�t
||�q�|ddkr�|ddk�sN|dd	k�r�|jj�xt|jD]}||k�r`|jj|��q`Wq�|dd
k�s�|dd	kr�|jj�x&|jD]}|j|k�r�t
||��q�Wq�W�x�|jD�]�}d|_
|jd7_t	|t��r�|jdk�r$d|_
|jd8_n\t	|jt��r�|jjj�dk�rZd
|_
|jd8_n&|jjj�dk�r�d|_
|jd8_n�t	|t��rf|jj�dk�r�d
|_
|jd8_n�|jj�dk�r�d|_
|jd8_n�|jj��rt|jj���rd|_
|jd8_nVtjj�r�|jj�gk�r<tjj|jj�k�sPtjj|jj�k�r�d|_
|jd8_nt	|t��r�|jd8_�q�Wt|j�dk�r�t	|jdt��r�d|jd_
t|j�dk�r�t	|jdt��r�d|jd_
xj|jdd�D]X}t	|t��r�|jjdk�r�|jdk�r�d|_
|jd8_|jdk�r�|jj |��q�WdS)NrrrErwrxFrqrsrzrrTr!Z	NoDisplayZHiddenZNoExecZ	NotShowInrjZEmptyrrr)!rrr)r�r$rtr-rxrGr	rrBrH�__parse_inliner%rrr!rr�rZgetNoDisplayZ	getHiddenZ
getTryExec�
__try_execr�r�Z
windowmanagerZ
getOnlyShowInZgetNotShowInrirr�)r�r4Ztmp_sZtmp_ertZ	separatorrCr?rrrr��s�



$&r�cCsptjdjtj�}tjj|�sZxL|D]0}tjj||�}tjj|�r$tj|tj�r$dSq$Wntj|tj�rldSdS)N�PATHTF)	rLr�rF�pathseprIr�rM�access�X_OK)�
executable�pathsr��frrrr�s

r�cCs
|jjdkr�t|j�dkr�|jjdkr�|jd}|jjd|j�dd�|jjd|j�dd�|jjd|j	�dd�|jj
|�nxt|j�|jjks�|jjdkr�|jjdkr�t
|j�|j�|j	��}|jj
|�x(|jD]}|jj
|�q�Wn|jj
|�n|jj
|�dS)	NrorErrT)rr�r�)r$rkrGrrprr�r7rRrSr-rlrnr�)r4r�rC�headerr?rrrr�$s
r�c@s4eZdZdZdd�Zddd�Zdd	�Zddd�Zd
S)r�zClass to cache Desktop EntriescCsi|_g|jd<i|_dS)N�legacy)�cacheEntriesr�)r*rrrr+9s
zMenuEntryCache.__init__rFcCs6x0|D](}||jkrg|j|<|j|d||�qWdS)Nr)r	�_MenuEntryCache__addFiles)r*r�r�rr0rrrr�>s


zMenuEntryCache.addMenuEntriescCs�x�tjtjj||��D]�}tjj|�ddkr�yttjj||�||�}Wntk
r^wYnX|j|j|�|dkr�|jdj|�qtjj	tjj|||��r|dkr|j
|tjj||�||�qWdS)NrEz.desktopTrF)rLr�rIrMr�r�rr	r-r�r
)r*r0Zsubdirr�rr�rCrrrZ
__addFilesDs zMenuEntryCache.__addFilesTcCs�g}g}|dd�}|dkr&|jd�dj|�}y
|j|Stk
rNYnXx�|D]�}x�|j|D]r}yV|j|kr�|j|j�|j|�n0|j�dkr�|j|�}	||	}
|
j�dkr�||
_Wqft	k
r�wfYqfXqfWqVW||j|<|S)NTrrr�r�)
r-rMr��KeyErrorr	rAr��indexr�r�)r*r�rr�ZidsZappdirs�keyr0rC�ir�rrrr�Rs2







zMenuEntryCache.getMenuEntriesN)rF)T)rVrWrXrYr+r�r
r�rrrrr�7s

r�)N)N)9rYrrLZxml.dom.minidomr�r�Zxdg.BaseDirectoryrrZxdg.DesktopEntryrZxdg.ExceptionsrrrZxdg.utilrZ
xdg.Localer�Z
xdg.Configr�ZNoderarrrZr$r�r�rxr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sX
	7 ;j^

3
F:	
#[