+
    )j]C                        R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^R
IHtHtHtHtHt ^RIHtHtHt ]
! ]4      t  ! R R]4      t! ! R R]4      t"R# ) )annotationsN)ConfigParser)	getLogger)Path)CalledProcessError)TemporaryDirectory)Iterable)ElementTree)UnixLexadd_xml_childindent_xml_tree
logged_rununlink)MenuMenuItemmenuitem_defaultsc                     a  ] tR t^tRt]! R4      t]! R4      tV 3R ltR R lt	R R lt
]R	 V 3R
 ll4       tR tR R ltR tR R ltR tR R ltR R ltR tR tR R ltRtV ;t# )	LinuxMenuz
Menus in Linux are governed by the freedesktop.org standards,
spec'd here https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html

menuinst will populate the relevant XML config and create a .directory entry
z	/etc/xdg/z
/usr/sharec                	  < \         SV `  ! V/ VB  V P                  R 8X  d$   V P                  V n        V P
                  V n        Mx\        \        P                  P                  RR4      4      P                  4       V n        \        \        P                  P                  RR4      4      P                  4       V n        \        P                  P                  RR4       R2pV P                  R,          V,          V n        V P                  R,          V,          V n        V P                  R	,          V P                  V P                  R
R7       R2,          V n        V P                  R,          V n        R# )systemXDG_CONFIG_HOMEz	~/.configXDG_DATA_HOMEz~/.local/shareXDG_MENU_PREFIXr   zapplications.menumenusdesktop-directoriesTslug
.directoryapplicationsN)super__init__mode_system_config_directoryconfig_directory_system_data_directorydata_directoryr   osenvironget
expandusersystem_menu_config_locationmenu_config_locationrendernamedirectory_entry_locationdesktop_entries_location)selfargskwargs
menu_fname	__class__s   &*, 8lib/python3.14/site-packages/menuinst/platforms/linux.pyr!   LinuxMenu.__init__"   s5   $)&)99 $($A$AD!"&"="=D$(

0+>%jl ! #'

0@A#jl 
 

'8"=>>OP
+/+H+H7+RU_+_($($9$9G$Cj$P! #$TYYT23:>? 	%
 )-(;(;n(L%    c                   V ^8  d   QhRR/#    returnztuple[os.PathLike] )formats   "r6   __annotate__LinuxMenu.__annotate__;   s      * r8   c                	    V P                  4        V P                  4       pV P                  4       '       d   V P                  4       '       d   V3# V P	                  4        V P                  4        V3# N)_ensure_directories_exist_write_directory_entry_is_valid_menu_file_has_this_menu_ensure_menu_file_add_this_menu)r1   paths   & r6   createLinuxMenu.create;   s_    &&(**,##%%$*=*=*?*?7N wr8   c                   V ^8  d   QhRR/# r:   r=   )r>   s   "r6   r?   r@   D   s      * r8   c                	   \        V P                  4      P                  4       '       g   \        4       # \        P
                  ! V P                  4       FD  pVP                  V P                  V P                  R R7       R24      '       g   K:  \        4       u # 	  V P                  4        V P                  P                  4       '       d%   \        V P                  R R7       V P                  3# \        4       # )Tr   _)
missing_ok)r   r0   existstupler'   listdir
startswithr-   r.   _remove_this_menur/   r   )r1   fns   & r6   removeLinuxMenu.removeD   s    D11299;;7N**T::;B}}DIID AB!DEEw < 	 ((//11400TB1133wr8   c                   V ^8  d   QhRR/# )r;   r<   zdict[str, str]r=   )r>   s   "r6   r?   r@   R   s      n r8   c                	T   < \         SV `  p\        V P                  4       4      VR &   V# )SP_DIR)r    placeholdersstr_site_packages)r1   r[   r5   s   & r6   r[   LinuxMenu.placeholdersQ   s+    w+!$T%8%8%:!;Xr8   c                	    V P                   R ,          V P                  R,          V P                  R,          .pV F,  p\        P                  RV4       VP	                  RRR7       K.  	  R# )r   r   r   zEnsuring path %s existsTparentsexist_okN)r$   r&   logdebugmkdirr1   pathsrI   s   &  r6   rC   #LinuxMenu._ensure_directories_existW   s_    !!G+"77.0

 DII/6JJtdJ3 r8   c                   V ^8  d   QhRR/# r;   r<   r   r=   )r>   s   "r6   r?   r@   e   s     - - -r8   c                	h   R RRRV P                  V P                  4       2.p\        P                  RV P                  4       \        V P                  R4      ;_uu_ 4       pVP                  RP                  V4      4       RRR4       V P                  #   + '       g   i     T P                  # ; i)[Desktop Entry]zType=DirectoryEncoding=UTF-8Name=zWriting directory entry at %sw
N)r-   r.   rc   rd   r/   openwritejoin)r1   linesfs   &  r6   rD    LinuxMenu._write_directory_entrye   s    DKK		*+,	
 			143P3PQ$//55GGDIIe$% 6 ,,, 65 ,,,s   !!BB1	c                	   \        V P                  4      P                  4       '       g   R # \        P	                  RV P                  V P                  V P                  4      4       \        P                  ! V P                  4      pVP                  4       pVP                  R4       FO  pVP                  R4      P                  V P                  V P                  4      8X  g   K>  VP                  V4       KQ  	  V P                  V4       R # )NzEditing %s to remove %s configr   Name)r   r,   rP   rc   rd   r-   r.   r
   parsegetrootfindallfindtextrV   _write_menu_file)r1   treerootelts   &   r6   rT   LinuxMenu._remove_this_menuv   s    D--.5577		,d.G.GUYU^U^I_	
   !:!:;||~<<'Cxx$$DII(>>C  ( 	d#r8   c                   V ^8  d   QhRR/# r;   r<   boolr=   )r>   s   "r6   r?   r@      s     X X Xr8   c                	  a  \         P                  ! S P                  4      P                  4       p\        ;QJ d.    V 3R  lVP                  R4       4       F  '       g   K   R# 	  R# ! V 3R  lVP                  R4       4       4      # )c              3  r   <"   T F,  qP                   SP                  SP                  4      8H  x  K.  	  R # 5irB   )r}   r-   r.   ).0er1   s   & r6   	<genexpr>+LinuxMenu._has_this_menu.<locals>.<genexpr>   s'     W=V66T[[33=Vs   47z	Menu/NameTF)r
   ry   r,   rz   anyr{   r1   r   s   f r6   rF   LinuxMenu._has_this_menu   s]      !:!:;CCEsWT\\+=VWssWsWsWT\\+=VWWWr8   c           	     	   \         P                  R V P                  V P                  V P                  4      4       \
        P                  ! V P                  4      pVP                  4       p\        VR4      p\        VRV P                  V P                  4      4       \        VRV P                  V P                  RR7       R24       \        VR4      p\        VRV P                  V P                  4      4       V P                  V4       R	# )
zEditing %s to add %s configr   rx   	DirectoryTr   r   IncludeCategoryN)
rc   rd   r,   r-   r.   r
   ry   rz   r   r~   )r1   r   r   menu_eltinc_elts   &    r6   rH   LinuxMenu._add_this_menu   s    		/1J1JDKKX\XaXaLbc  !:!:;||~ v.hDII(>?hDIID0Q/RR\-]^)4gz4;;tyy+ABd#r8   c                   V ^8  d   QhRR/# r   r=   )r>   s   "r6   r?   r@      s      T r8   c                	     \         P                  ! V P                  4      P                  4       pVR J;'       d    VP                  R8H  #   \
         d     R# i ; i)Nr   F)r
   ry   r,   rz   tag	Exceptionr   s   & r6   rE   LinuxMenu._is_valid_menu_file   sT    	$$T%>%>?GGIDt#::F(:: 		s   8A A AAc                   V ^8  d   QhRR/# )r;   r   zElementTree.ElementTreer=   )r>   s   "r6   r?   r@      s      %< r8   c                	v   \         P                  R V P                  4       \        VP	                  4       4       \        V P                  R4      ;_uu_ 4       pVP                  R4       VP                  R4       VP                  V4       VP                  R4       RRR4       R#   + '       g   i     R# ; i)z
Writing %swbs9   <!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
s<    "http://standards.freedesktop.org/menu-spec/menu-1.0.dtd">
   
N)rc   rd   r,   r   rz   rq   rr   )r1   r   ru   s   && r6   r~   LinuxMenu._write_menu_file   sx    		, 9 9:'$++T22aGGQRGGTUJJqMGGEN	 3222s   AB''B8	c                	   V P                   P                  4       '       d:   V P                   P                  4       '       g   \        R V P                    R24      hV P                   P                  4       '       d   \        P
                  ! R4      pV P                    RV 2p\        P                  ! V P                   V4       V P                  4       '       g#   \        P                  ! V P                   4       R# R# V P                  4        R# )zMenu config location z is not a file!z%Y-%m-%d_%Hh%Mm%S.N)r,   rP   is_fileRuntimeErrortimestrftimeshutilcopyfilerE   r'   rV   _new_menu_file)r1   cur_timebackup_menu_files   &  r6   rG   LinuxMenu._ensure_menu_file   s    $$++--d6O6O6W6W6Y6Y!6t7P7P6QQ`abb $$,,..}}%89H"&";";!<AhZHOOD557GH++--		$334 . !r8   c                	`   \         P                  R V P                  4       \        V P                  R4      ;_uu_ 4       pVP	                  R4       V P
                  R8X  d    VP	                  RV P                   R24       VP	                  R4       RRR4       R#   + '       g   i     R# ; i)Creating %sro   z<Menu><Name>Applications</Name>userz<MergeFile type="parent">z</MergeFile>z</Menu>
N)rc   rd   r,   rq   rr   r"   r+   )r1   ru   s   & r6   r   LinuxMenu._new_menu_file   s}    		-!:!:;$++S11QGG56yyF"3D4T4T3UUabcGGK 	 2111s   ABB-	c                   V ^8  d   QhRR/# )r;   r<   ztuple[Path]r=   )r>   s   "r6   r?   r@      s     0 0 0r8   c                	    V P                   3# rB   )r/   r1   s   &r6   _pathsLinuxMenu._paths   s    --//r8   )r$   r&   r0   r/   r,   r+   )__name__
__module____qualname____firstlineno____doc__r   r#   r%   r!   rJ   rV   propertyr[   rC   rD   rT   rF   rH   rE   r~   rG   r   r   __static_attributes____classcell__)r5   s   @r6   r   r      s|      $K0!,/M2  
4-"$X	$"$!0 0r8   r   c                      ] tR t^t]R R l4       tR R ltR R ltR tR R	 lt	R
 t
RR R lltRR R lltR R ltRR R lltR R ltRtR# )LinuxMenuItemc                   V ^8  d   QhRR/# rj   r=   )r>   s   "r6   r?   LinuxMenuItem.__annotate__   s     = =$ =r8   c                	    V P                  V P                  P                  R / R7      pV RV P                  RR / R7       R2pV P                  P                  V,          # )T)r   extrarN   r.   z.desktop)r-   menur.   
render_keyr0   )r1   menu_prefixfilenames   &  r6   locationLinuxMenuItem.location   sX    kk$))..t2kF "]!DOOFRO$P#QQYZyy11H<<r8   c                   V ^8  d   QhRR/# r;   r<   zIterable[os.PathLike]r=   )r>   s   "r6   r?   r      s      - r8   c                	    \         P                  R V P                  4       V P                  4        V P	                  4        V P                  RR7       V P                  4        V P                  4       # )r   Tregister)rc   rd   r   
_precreate_write_desktop_file_maybe_register_mime_types_update_desktop_databaser   r   s   &r6   rJ   LinuxMenuItem.create   sS    		-/  "'''6%%'{{}r8   c                   V ^8  d   QhRR/# r   r=   )r>   s   "r6   r?   r      s      - r8   c                	    R  V P                  4        4       pV P                  RR7       V'       d;   V F$  p\        P                  RV4       \	        V4       K&  	  V P                  4        V# )c              3  h   "   T F(  p\        V4      P                  4       '       g   K$  Vx  K*  	  R # 5irB   )r   r   )r   rI   s   & r6   r   'LinuxMenuItem.remove.<locals>.<genexpr>   s!     H-$4:3E3E3G-s   !2
2Fr   zRemoving %s)r   r   rc   rd   r   r   rf   s   &  r6   rV   LinuxMenuItem.remove   sX    H$++-H'''7		-.t  ))+r8   c                	    \         P                  ! R 4      pV'       d/   \        V\        V P                  P
                  4      .RR7       R# R# )zupdate-desktop-databaseFcheckN)r   whichr   r\   r   r0   )r1   exes   & r6   r   &LinuxMenuItem._update_desktop_database   s;    ll45c$))<<=> r8   c                   V ^8  d   QhRR/# )r;   r<   r\   r=   )r>   s   "r6   r?   r      s     < <# <r8   c           	     	@   . pV P                  R 4      pV'       d   VP                  V4       V P                  R,          '       dl   V P                  P                  pV P                  P                  V4      '       d   RpMRpVP                  RV RV RV P                  P                   R24       VP                  RP                  \        P                  ! V P                  R	4      4      4      4       R
\        P                  ! RP                  V4      4      ,           # )
precommandactivatezshell activatezshell.bash activatez	eval "$("z" z "z")" commandzbash -c z && )r   appendmetadatar   	conda_exe_is_micromambaprefixrs   r   
quote_argsshlexquote)r1   partsr   r   r   s   &    r6   _commandLinuxMenuItem._command   s    __\2
LL$==$$		++Iyy''	22+0LL9YKr(2dii>N>N=OsSTSXXg001KLMNEKKE(:;;;r8   c                	T   V P                   P                  4       '       d,   \        P                  R V P                  V P                   4       RRRRV P                  R4       2RV P                  4        2R\        V P                  R4      4      P                  4        2.pV P                  R	4      pV'       d$   VP                  R
V P                  R	4       24       V P                  R4      pV'       d$   VP                  RV P                  R4       24       V P                  R4      pV'       dN   \        \        P                  P                  V4      4      P                  RRR7       VP                  RV 24       \        R,          R,           F  pV. \        ORN59   d   K  V P                  V4      pVf   K,  \!        V\"        4      '       d   \        V4      P                  4       pM4\!        V\$        \&        34      '       d   RP)                  V4      R,           pVP                  V RV 24       K  	  \+        V P                   R4      ;_uu_ 4       pVP-                  RP)                  V4      4       VP-                  R4       RRR4       R#   + '       g   i     R# ; i)z$%s: Overwriting existing file at %s.rl   zType=Applicationrm   rn   r.   zExec=z	Terminal=terminaliconzIcon=descriptionzComment=working_dirTr`   zPath=	platformslinuxglob_patternsN;=ro   rp   )r   rP   rc   warning	_log_namer   r   r\   lowerr   r   r'   rI   
expandvarsre   r   
isinstancer   listrQ   rs   rq   rr   )r1   rt   r   r   r   keyvalueru   s   &       r6   r   !LinuxMenuItem._write_desktop_file   s   ==!!KK>PTP]P]^ DOOF+,-DMMO$%DOOJ78>>@AB
 v&LL5!8 9:;oom4LL8DOOM$B#CDEoom4##K0177t7TLL5./$[1'::C;);?;;OOC(E}%&&E
((*ED%=11#-LLC5%)* ; $--%%GGDIIe$%GGDM &%%%s   2JJ'	c                   V ^8  d   QhRR/# )r;   r   r   r=   )r>   s   "r6   r?   r     s     A A4 Ar8   c                	`    V P                  R 4      pV'       g   R# V P                  W!R7       R# )MimeTypeNr   )r   _register_mime_types)r1   r   
mime_typess   && r6   r   (LinuxMenuItem._maybe_register_mime_types  s'    __Z0
!!*!@r8   c                    V ^8  d   QhRRRR/# )r;   r  zIterable[str]r   r   r=   )r>   s   "r6   r?   r   "  s     7 7} 7 7r8   c           	     	   V P                  R 4      ;'       g    / pV F1  pVP                  V4      pV'       g   K  V P                  WEVR7       K3  	  V P                  P                  R,          pV'       Ede   \        RR7      pVP                  4       '       d   VP                  V4       \        P                  RW4       RVP                  4       9  d   VP                  R4       RVP                  4       9  d   VP                  R4       VR,          pVR,          p	V F  pWH9  d   V P                  P                  W&   WI9   dG   V P                  P                  W,          9  d&   W,           RV P                  P                   2W&   Km  V P                  P                  W&   K  	  \        VR	4      ;_uu_ 4       p
VP                  V
R
R7       RRR4       EMVP                  4       '       Edw   \        RR7      pVP                  V4       \        P                  RW4       R EF  pWP                  4       9  d   K  W{,          pVP!                  4        F  w  rV P                  P                  V8X  d   VP#                  V4       K3  V P                  P                  VP%                  R4      9   g   K_  RP'                  VP%                  R4       Uu. uF!  qV P                  P                  8w  g   K  VNK#  	  up4      W&   K  	  VP)                  4       '       d   K  VP+                  V4       EK  	  \        VR	4      ;_uu_ 4       p
VP                  V
R
R7       RRR4       \,        P.                  ! R4      pV'       d.   \1        VRV P                  P2                  R,          .R
R7       R# R#   + '       g   i     L]; iu upi   + '       g   i     Lu; i)r   )installzmimeapps.listN)default_sectionzRegistering %s to %s...Default ApplicationsAdded Associationsr   ro   F)space_around_delimiterszDeregistering %s from %s...zupdate-mime-databasez-Vmimer   )r  r  )r   r)   _glob_pattern_for_mime_typer   r$   r   r   readrc   rd   sectionsadd_sectionr   r.   rq   rr   itemspopsplitrs   keysremove_sectionr   r   r   r&   )r1   r  r   r   	mime_typeglob_patternmimeappsconfigdefaultsaddedru   section_namesectionmimetypedesktop_filesxupdate_mime_databases   &&&              r6   r  "LinuxMenuItem._register_mime_types"  s   8>>B#I(,,Y7L|00RZ0[ $
 99--?8!$7F!!H%II/F%V__->>""#9:#6??+<<""#7845H/0E'	,*.--*<*<H'%$--*<*<EDT*T*/*:);1T]]=O=O<P'QE$'+}}'9'9E$ ( h$$Q> %$!$7FKK!II3ZJ L'88 ./6}}+H}}))]:H-++}/B/B3/GG,/HH(5(;(;C(@\(@1I[I[D[QQ(@\-)	 0? ||~~)),7 !M h$$Q> %  &||,BC%tTYY-E-E-NO  1 %$  ] %$s$   ?N7O
9O
O7O	O	c                    V ^8  d   QhRRRR/# )r;   r  r\   r<   ztuple[Path, bool]r=   )r>   s   "r6   r?   r   [  s     
Y 
Y 
Y9J 
Yr8   c                	|   VP                  R R4      p\        V P                  P                  R,          R,          P	                  RV R24      4      pV'       d4   \        V4      ^8  d   Rp\        P                  WAV4       V^ ,          R3# V P                  P                  R,          R,          V R	2,          R
3# )/-r  r   *z*.xmlz;Found multiple files for MIME type %s: %s. Returning first.Tpackagesz.xmlF)replacer   r   r&   globlenrc   rd   )r1   r  basename	xml_filesmsgs   &&   r6   _xml_path_for_mime_type%LinuxMenuItem._xml_path_for_mime_type[  s    $$S#.YY%%.?EE(SXFYZ
	 9~!S		#)4Q<%%yy''&0:=8*D@QQSXXXr8   c               (    V ^8  d   QhRRRRRRRR/# )r;   r  r\   r  r
  r   r<   zPath | Noner=   )r>   s   "r6   r?   r   g  s8     6I 6I6I 6I 	6I
 
6Ir8   c           
     d   V P                  V4      w  rEV'       d   V# Rp\        P                  ! RVR7      p\        P                  ! VRVR7      p\        P                  ! VRVR7       RV R	V R
2p	V	\        P                  ! VR4      n        \        P                  ! V4      p
V'       d   RMRpRp \        4       ;_uu_ 4       p\        \        P                  P                  V\        P                  P                  V4      4      R4      ;_uu_ 4       pV
P                  VRRR7       RRR4       \        P                  ! R4      pV'       d2   \        WRV P                  P                   RXP"                  .RR7       M#\$        P'                  RV P(                  V4       RpRRR4       T'       d-   \$        P-                  RT4       T
P                  TRRR7       R# R#   + '       g   i     L; i  + '       g   i     LY; i  \*         d    Rp\$        P-                  RT4        Li ; i)z
See https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html
for more information on the default locations.
z5http://www.freedesktop.org/standards/shared-mime-infoz	mime-info)xmlnsz	mime-type)typer-  )patternzCustom MIME type z for 'z ' files (registered by menuinst)commentr
  	uninstallFr   zUTF-8T)encodingxml_declarationNzxdg-mimez--modez
--novendorr   ze%s: Unable to un/register MIME type '%s' for Desktop Entry: 'xdg-mime' is not present on the system.'z1Could not un/register MIME type %s with xdg-mime.zWriting to '%s' as a fallback.)r2  r
   Element
SubElementr}   r   rq   r'   rI   rs   r/  rr   r   r   r   r   r"   r.   rc   r   r   r   rd   )r1   r  r  r
  xml_pathrP   r6  	mime_infomime_type_tagdescrr   
subcommanduse_fallbacktmpru   xdg_mimes   &&&&            r6   r  )LinuxMenuItem._glob_pattern_for_mime_typeg  s     77	BO H''5A	#..y+IV}flK#I;f\NBbc@E}i8=&&y1")Y{
	V#%%"'',,sBGG,<,<X,FGNNRSJJq7DJI O "<<
3!xWXW]W]^"
 KKD $ $(L% &2 II6AJJx'4JH 1 ON &%& " 	V  LIII9U		VsP   4H	 AG6G#	+%G6AG6%H	 #G3.G66H	H	 H	 	#H/.H/c                   V ^8  d   QhRR/# r   r=   )r>   s   "r6   r?   r     s      - r8   c                	   V P                   .pV P                  R 4      ;'       g    RpV FH  pV P                  V4      w  rEV'       g   K   RVP                  4       9   g   K7  VP	                  V4       KJ  	  \        V4      # )r  zregistered by menuinstr=   )r   r   r2  	read_textr   rQ   )r1   rg   r  r  r?  rP   s   &     r6   r   LinuxMenuItem._paths  sn    __Z066B
D#;;DAHv2h6H6H6JJX&  U|r8   r=   N)T)r   r   r   r   r   r   rJ   rV   r   r   r   r   r  r2  r  r   r   r=   r8   r6   r   r      sQ    = =<(TA7r
Y6Ip r8   r   )#r   
__future__r   r'   r   r   r   configparserr   loggingr   pathlibr   
subprocessr   tempfiler   typingr	   	xml.etreer
   utilsr   r   r   r   r   baser   r   r   r   rc   r   r   r=   r8   r6   <module>rV     s_     " 	    %   ) '  ! O O 3 3f0 f0RfH fr8   