
    ce`                     z   d Z ddlZddlmZ ddlZddlZddlZddlm	Z	m
Z
 d Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zedk    rmej        dk    r eg d          dk    sJ n eg d          dk    sJ  e e                        e e                        e e                       dS dS )zMiscellaneous utilities.    N)LOCKFILEPIDFILEc                     t          j        |           d         dk    r3dD ]2}t          j        | |z             rt          j        | |z              1dS dS )zCEventually remove .pyc and .pyo files associated to a Python script   z.py)coN)ospsplitextexistsosremove)fnameendings     =lib/python3.11/site-packages/anaconda_navigator/utils/misc.py__remove_pyc_pyor      sh    
|E1&&  	* 	*Fz%&.)) *	%&.))) '&	* 	*    c                 N    t          j        | |           t          |            dS )zt
    Rename file from *source* to *dest*
    If file is a Python script, also rename .pyc and .pyo files if any
    N)r   renamer   sourcedests     r   rename_filer      s*    
 IfdVr   c                 L    t          j        |            t          |            dS )zd
    Remove file *fname*
    If file is a Python script, also rename .pyc and .pyo files if any
    N)r   r   r   )r   s    r   remove_filer   %   s(    
 IeUr   c                 N    t          j        | |           t          |            dS )zr
    Move file from *source* to *dest*
    If file is a Python script, also rename .pyc and .pyo files if any
    N)shutilcopyr   r   s     r   	move_filer   .   s*    
 Kr   c                 d    t          j        t          j        | t          j                            S )zReturn absolute parent dir)r	   abspathjoinr   pardir)paths    r   	abspardirr$   7   s     ;sxbi00111r   c           
         t          j        t          j        |                     }t          |          dk    rt          j        |          st          |          S | D ]R}t          j        t          j        ||t          |          dz   d                             st          |          c S St          j        |          S dS )z,Return common path for all paths in pathlistr   N)r	   normpathcommonprefixlenisdirr$   r!   r    )pathlistcommonr#   s      r   get_common_pathr,   <   s    \#*84455F
6{{Qy   	%V$$$ 	) 	)D9SXfd3v;;?3C3C.DEEFF ) ((((() {6"""4r   c                    t           j                            t           j                            t           j                            |                               } d}t           j                            |           r| }d}nt           j                            |           }d}|s'	 t          j        |            n# t          $ r Y dS w xY wt           j        	                    | t          j                    j        dd                   }	 t          |d          }n# t          t          f$ r Y dS w xY w|                                 	 |rt          j        |           |st          j        |            n# t          $ r Y nw xY wdS )z Check if given path is writable.FTN   za+)r   r#   r    
expanduser
expandvarsisfiler)   makedirs	Exceptionr!   uuiduuid4hexopenIOErrorOSErrorcloser   rmdir)r#   path_existstest_filepathr   fhs        r   path_is_writabler?   J   s   7??27--bg.@.@.F.FGGHHDK	w~~d AgmmD)) 	D!!!!   uu T4:<<+;BQB+?@@-&&W   uu HHJJJ 	%Im$$$ 	HTNNN   4s6   $B9 9
CC	D D/.D/,E4 4
F Fc                      t          j                    } 	 t          t          d          5 }|                    t          |                      ddd           n# 1 swxY w Y   n# t          $ r d} Y nw xY w| S )zSave navigator process ID.wN)r   getpidr7   r   writestrr3   )pidfs     r   save_pidrG   m   s    
)++C'3 	1GGCHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    Js4   A% #AA% AA%  A!A% %A43A4c                     	 t          t          d          5 } |                                 }ddd           n# 1 swxY w Y   t          |          }n# t          $ r d}Y nw xY w|t          j        |          }d}g }	 t          j        |          }|r|r|                                }n6# t
          j	        $ r Y n%t
          j
        $ r t                      sY dS Y nw xY wd |D             }d |D             }d |D             }d |D             }t          |          pt          |          pt          |          }|sd}|S )Load navigator process ID.rNFc                 6    g | ]}|                                 S  )lower.0cmds     r   
<listcomp>zload_pid.<locals>.<listcomp>   s     ,,,		,,,r   c                 "    g | ]}d |v sd|v 
|S )pythonzbootstrap.pyrL   rN   s     r   rQ   zload_pid.<locals>.<listcomp>   s5     
 
 
3.C"7"7 "7"7"7r   c                 "    g | ]}d |v sd|v 
|S )rS   zanaconda-navigatorrL   rN   s     r   rQ   zload_pid.<locals>.<listcomp>   s6     
 
 
3"6#"="= "="="=r   c                     g | ]}d |v |	S )znavigator.apprL   rN   s     r   rQ   zload_pid.<locals>.<listcomp>   s-     
 
 
#%% %%%r   )r7   r   readintr3   psutil
pid_existsProcesscmdlineNoSuchProcessAccessDenied
remove_pidany)	rF   rE   
is_runningprocesscmdsch1ch2ch3checks	            r   load_pidrg   z   s   '3 	1&&((C	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#hh    &s++

	nS))G ): )((# 	 	 	D" 	 	 	<< uu 	
 -,t,,,
 

 
 


 

 
 


 

 
 
 C0CHH0C 	CJsE   A 8A <A < A A"!A" ,B- -C >C C c                  d    d} 	 t          j        t                     n# t          $ r d} Y nw xY w| S rI   TF)r   r   r   r3   rf   s    r   r^   r^      sH    E
	'   L    --c                  d    d} 	 t          j        t                     n# t          $ r d} Y nw xY w| S ri   )r   r   r   r3   rj   s    r   remove_lockrm      sH    E
	(   Lrk   c                  j    	 ddl m}  d}| j                            |          S # t          $ r Y dS w xY w)z3Make sure correct icon is used on Windows 7 taskbarr   )windllzanaconda.Anaconda-Navigatorz1SetCurrentProcessExplicitAppUserModelID not found)ctypesro   shell32'SetCurrentProcessExplicitAppUserModelIDAttributeError)ro   names     r   set_windows_appusermodelidru      s]    C!!!!!!,~EEdKKK C C CBBBCs   !$ 
22c                 z    t           j        dk    r|                     dd          n|                     dd          S )zRemove `file:///` from path.ntzfile:/// zfile://)r   rt   replace)file_urls    r   convert_file_url_to_pathr{      s9    /1w$8J+++HDTDTU^`bDcDccr   __main__rw   )z#D:\Python\spyder-v21\spyder\widgetszD:\Python\spyder\spyder\utilszD:\Python\spyder\spyder\widgetsz!D:\Python\spyder-v21\spyder\utilsz	D:\Python)z!/Python/spyder-v21/spyder.widgetsz/Python/spyder/spyder.utilsz/Python/spyder/spyder.widgetsz/Python/spyder-v21/spyder.utilsz/Python)__doc__r   os.pathr#   r	   r   r4   rX   anaconda_navigator.configr   r   r   r   r   r   r$   r,   r?   rG   rg   r^   rm   ru   r{   __name__rt   printrL   r   r   <module>r      s     				          7 7 7 7 7 7 7 7* * *      2 2 2
       F
 
 
1 1 1h    C C Cd d d
 z	w$  
 
        
 
     
E((**	E((**	E**,,+ r   