
    Je]                         d Z ddlmZ ddl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ZdZdZdZdZdZd	Z ej$                  e      Zd
 Zd Z ed      d        Zd ZddZd Zy)zKite status functions.    )	lru_cacheNznot installedreadyznot runningz,https://release.kite.com/dls/windows/currentz*https://release.kite.com/dls/linux/currentz(https://release.kite.com/dls/mac/currentc                  *   d} t         j                  dk(  rd} nRt        j                  j	                  d      rt        j                  d      } nt        j                  dk(  r
t               } t        j                  t        j                  |             | fS )z=Detect if kite is installed and return the installation path. ntzC:\Program Files\Kite\kited.exelinuxz~/.local/share/kite/kiteddarwin)
osnamesysplatform
startswithosp
expanduserlocate_kite_darwinexistsrealpath)paths    W/usr/lib/python3/dist-packages/spyder/plugins/completion/providers/kite/utils/status.pycheck_if_kite_installedr   !   si    D	ww$3		 	 	)~~9:		!!#::cll4()4//    c                      d} 	 t        j                  g d      D ]@  }t        |      st        j	                  dj                  |j                               d}  | S  	 | S # t        $ r Y | S w xY w)zDetect if kite is running.F)pidr   usernamestatus)attrsz)Kite process already running with PID {0}T)psutilprocess_iteris_proc_kiteloggerdebugformatr   OSError)runningprocs     r   check_if_kite_runningr&   -   s    G
'' /9 : 	DD! 44:F4884DF N	 N  Ns   &A" 1A" A" "	A/.A/   )maxsizec                     d} d}	 t        j                  ddg      }t        |      dkD  }|r2|j                  dd      j	                         j                  d      d   n| }|S # t         j                  t        f$ r | }Y |S w xY w# |c cY S xY w)	z
    Looks up where Kite.app is installed on macOS systems. The bundle ID
    is checked first and if nothing is found or an error occurs, the
    default path is used.
    z/Applications/Kite.appr   mdfindz)kMDItemCFBundleIdentifier="com.kite.Kite"r   zutf-8replace
)
subprocesscheck_outputlendecodestripsplitCalledProcessErrorUnicodeDecodeError)default_pathr   out	installeds       r   r   r   >   s     ,LD
%%BCEHqL	 

7I.446<<TB1E". 	 	 ))+=> 	 s$   AA# #B>B BB Bc                     	 | j                         }t        j                   dk(  st        j                  j                  d      rd|v xr | j                         dk7  }|S d|k(  }|S # t        $ r d}Y aw xY w)Nr   r   r   kitedzombieKite)r   	Exceptionr
   r   r   r   r   )r%   r   is_kites      r   r   r   T   sx     yy{ 
ww$#,,11':T/?dkkmx&? N D.N  s   A& &A43A4c                 j    t               \  }}|s	t        | z   S t               r	t        | z   S t        | z   S )z;Kite completions status: not installed, ready, not running.)r   NOT_INSTALLEDr&   RUNNINGNOT_RUNNING)extra_statuskite_installed_s      r   r   r   d   s9    /1NA|++		 %%\))r   c                  t   t         } t        j                  dk(  rt        } nt        j
                  dk(  rt        } d}	 t        j                  | d      }|j                  }|j                  r<|j                  r0|j                  d   }t        j                  |      }|j                  }|S # t        $ r Y |S w xY w)z'Check if Kite installers are available.r   r	   Fg?)timeoutLocation)	LINUX_URLr
   r   WINDOWS_URLr   r   MAC_URLrequestsheadokis_redirectheadersr<   )url	availablereqlocs       r   "check_kite_installers_availabilityrT   o   s    
C	ww$		!I	mmC-FF	66kk*-mmC(FF	   s   A+B* *	B76B7)r   )__doc__	functoolsr   loggingr
   os.pathr   r   r-   r   r   rK   r?   r@   rA   rI   rH   rJ   	getLogger__name__r    r   r&   r   r   r   rT    r   r   <module>r\      s        	   
  
 =8	
4			8	$	0" 1 * *r   