+
    Ki,  c                   s    R t ^ RIt^ RIt^ RIt^ RI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	 t]! 4       t]! 4       t ! R
 R4      tR tR# )z=Threading module, used to launch games while monitoring them.N)copy)List)GLib)settings)system)logger)get_terminal_scriptc            
     sn   Rp \         P                  P                  \         P                  P                  \         P                  P	                  \         P                  P                  \
        P                  ^ ,          4      4      R4      4      \         P                  P	                  \         P                  P	                  \        P                  4      4      RR.pV FK  p\         P                  P                  W 4      p\         P                  P                  V4      '       g   KI  Vu # 	  \        R4      h)z-Return absolute path of lutris-wrapper scriptzshare/lutris/bin/lutris-wrapperz..z/usrz
/usr/localzDCouldn't find lutris-wrapper script in any of the expected locations)ospathZabspathjoinZdirnamesysZargvr   Z__file__ZisfileZFileNotFoundError)Zwrapper_relpathZ
candidatesZ	candidateZwrapper_abspaths       =/usr/lib/python3.14/site-packages/lutris/monitored_command.pyget_wrapper_script_locationr      s    7O
RWW__RWW__SXXa[5Q%RTXYZ
(9(9:;	J  	'',,yB77>>/**""   b
cc    c                   s   a  ] tR t^*t o RtRtRR lt]R 4       tV 3R lR lt	R t
R	 t]R
 4       tR tR tV 3R lR ltR tR tR tR tR tR tRR ltR tRtV tR# )MonitoredCommandz5Exexcutes a commmand while keeping track of its state/tmpNc
                s   R V n         V P                  V4      V n        RV n        Wn        W n        R V n        RV n        RV n        RV n	        W@n
        R V n        RV n        V P                  V P                  .V n        V P!                  V4       RV n        T;'       g    . V n        T;'       g    . V n        V P)                  V4      V n        \,        P.                  ! 4       V n        V	'       d	   Wn        R# V^ ,          V n        R# )TZ0c                  s    R # )T r   r   r   Z<lambda>Z+MonitoredCommand.__init__.<locals>.<lambda>B   s    r   NF)ready_stateget_environmentenvaccepted_return_codecommandrunner	stop_funcgame_processprevent_on_stopreturn_codeterminal
is_runningerrorlog_handler_stdoutlog_handler_console_outputlog_handlersset_log_bufferstdout_monitorinclude_processesexclude_processesget_cwdcwdioZStringIO_stdout_title)
selfr   r   r   Ztermr&   r#   r$   
log_bufferZtitles
   &&&&&&&&&&r   __init__ZMonitoredCommand.__init__/   s      '',$'!% $
##++
 	J'"!2!8!8b!2!8!8b<<${{}$e'!*r   c                s6    V P                   P                  4       # N)r(   Zgetvalue)r*      &r   stdoutZMonitoredCommand.stdoutX   s    ||$$&&r   c                s0   < V ^8  d   QhRS[ S[,          /# )   return)r   strZformat__classdict__   "r   __annotate__MonitoredCommand.__annotate__\   s     D DT#Y Dr   c                s   \         V P                  \        \        V P                  4      4      \        \        V P
                  4      4      .V P                  ,           V P
                  ,           pV P                  '       g   WP                  ,           # \        P                  ! V P                  4      p\        V P                  V P                  V P                  4      pWRV.,           # )z.Return launch arguments for the wrapper scriptz-e)WRAPPER_SCRIPTr)   r2   Zlenr#   r$   r   r   r   Zfind_required_executabler   r&   r   )r*   wrapper_commandZterminal_pathZscript_path   &   r   get_wrapper_commandZ$MonitoredCommand.get_wrapper_command\   s     C../0C../0	 $$% $$% 	 }}}"\\1177F)$,,$((K{!CCCr   c                s    V'       g   R# Wn         V P                  V P                  9  d(   V P                  P                  V P                  4       R# R# )z>Attach a TextBuffer to this command enables the buffer handlerN)r+   log_handler_bufferr    Zappend)r*   r+      &&r   r!   ZMonitoredCommand.set_log_buffero   s@    $""$*;*;;$$T%<%<= <r   c                s    V'       g+   V P                   '       d   V P                   P                  MRp\        P                  P	                  T;'       g    R4      # )z*Return the current working dir of the gameNZ~)r   Zworking_dirr   r   Z
expanduser)r*   r&   r=   r   r%   ZMonitoredCommand.get_cwdw   s9    -1[[[$++))dCww!!#**--r   c                s   V '       d   \        V 4      M/ pRP                  \        P                  4      VR&   \	        \
        P                  ! 4       4      VR&   / pVP                  4        F  w  r4RV9   d   \        P                  ! RV4       K%  Vf   \        P                  ! RV4       KB  \        V\        4      '       g'   \        P                  ! RW44       \	        V4      W#&   K~  WBV&   K  	  V# )zCProcess the user provided environment variables for use as self.envZ:Z
PYTHONPATHLUTRIS_GAME_UUIDZ=zJEnvironment variable name '%s' contains '=' so it can't be used; skipping.z;Environment variable '%s' has None for its value; skipping.zAEnvironment variable '%s' value '%s' is not a string; converting.)r    r	   r
   r   r2   uuidZuuid4itemsr   warning
isinstance)Zuser_envr   Zcleanedkeyvalues   &    r   r   Z MonitoredCommand.get_environment}   s     !)d8nb  HHSXX.L #&djjl"3))+JCczkmpq\^abs++bdgo"5z$ & r   c                sf    \         P                  ! 4       pVP                  V P                  4       V# )z9Returns the calculated environment for the child process.)r   r   Zupdater   )r*   r      & r   get_child_environmentZ&MonitoredCommand.get_child_environment   s%    $$&

488
r   c                s   \         P                  P                  R4      R8X  d;   V P                  P	                  4        F  w  r\
        P                  ! RW4       K  	  V P                  4       pV P                  4       pV P                  W44      V n
        \        P                  V 4       V P                  '       g   \
        P                  ! R4       R# \        P                  ! V P                  P                   V P"                  4       V P                  P$                  P'                  4       p\(        P(                  ! V\(        P*                  \(        P(                  ! V\(        P,                  4      \         P.                  ,          4       \        P0                  ! V P                  P$                  \        P2                  \        P4                  ,          V P6                  4      V n        R# )zRun the thread.ZLUTRIS_DEBUG_ENVZ1z%s="%s"zNo game process availableN)r   ZenvironZgetr   r@   r   debugr;   rF   execute_processr   RUNNING_COMMANDSZaddr   r   Zchild_watch_addpidon_stopr/   filenofcntlZF_SETFLZF_GETFLZ
O_NONBLOCKZio_add_watchZIO_INIO_HUPon_stdout_outputr"   )r*   rC   rD   r9   r   rL   s   &     r   startZMonitoredCommand.start   s<   ::>>,-4"hhnn.
Y3 /224((* 00FT"   LL45T..22DLLA ""))002FEMM5;;vu}}+MPRP]P]+]^"//$$JJ$!!
r   c                s&   < V ^8  d   QhRS[ RS[/# )r0   liner1   )r2   Zboolr3   r5   r   r6   r7      s     
 
s 
t 
r   c                sN    RV9   d   R# RV9   d   R# RV9   d   R# RV9   d   R# R# )z:Filter out some message we don't want to show to the user.zGStreamer-WARNING **FzBad file descriptorz&'libgamemodeauto.so.0' from LD_PRELOADzUnable to read VR Path RegistryTr   r*   rQ   r=   r   
log_filterZMonitoredCommand.log_filter   s1    !T) D(3t;,4r   c                sn    V P                  V4      '       g   R# V P                  P                  V4       R# )z/Add the line to this command's stdout attributeN)rS   r(   writerR   r=   r   r   Z#MonitoredCommand.log_handler_stdout   s&    t$$4 r   c                sp    V P                   P                  V P                   P                  4       VR4       R# )z/Add the line to the associated LogBuffer objectNi)r+   ZinsertZget_end_iterrR   r=   r   r<   Z#MonitoredCommand.log_handler_buffer   s%    t;;=tRHr   c                s0   V P                  V4      '       g   R# \        P                  ! \        4      ;_uu_ 4        \        P
                  P                  V4       \        P
                  P                  4        RRR4       R#   + '       g   i     R# ; i)zPrint the line to stdoutN)rS   
contextlibZsuppressZBlockingIOErrorr
   r/   rT   ZflushrR   r=   r   r   Z+MonitoredCommand.log_handler_console_output   sV    t$$  11JJT"JJ 2111s   >BB	c                sh   RV P                   R,          ,          p\        P                  P                  V4      '       dG   \	        VRR7      ;_uu_ 4       pVP                  4       pRRR4       \        P                  ! V4       X# Rp\        P                  ! RV4       V#   + '       g   i     LC; i)z8Get the return code from the file written by the wrapperz/tmp/lutris-%sr>   utf-8)ZencodingN z
No file %s)	r   r   r   ZexistsZopenreadZunlinkr   rA   )r*   Zreturn_code_pathZreturn_code_filer   r:   r   get_return_codeZ MonitoredCommand.get_return_code   s    +dhh7I.JJ77>>*++&99=M.335 :II&'  KNN<)9: :9s   B!!B1	c                s<   V P                   '       d   R# V P                  P                  4        V P                  4       V n        RV n        \        P                  ! RWP                  4       V P                  4       pV'       g   \        P                  ! R4       R# R# )z/Callback registered on game process terminationFz&Process %s has terminated with code %szFull shutdown prevented)
r   r   ZwaitrY   r   r   r   rG   stopZinfo)r*   rJ   Z
_user_dataresume_stops   &&& r   rK   ZMonitoredCommand.on_stop   sq     //1=sDTDTUiikKK12r   c                s   V\         P                  8X  d
   RV n        R# V P                  '       g   R#  VP	                  R4      P                  RRR7      pRT9   d   R# T P                   F  pT! T4       K  	  R#   \         d     R# i ; i)	z?Called by the stdout monitor to dispatch output to log handlersNFi   rV   Zignore)ZerrorsTzwinemenubuilder.exe)r   rN   r"   r   rX   ZdecodeZ
ValueErrorr    )r*   r/   Z	conditionrQ   Zlog_handlers   &&&  r   rO   Z!MonitoredCommand.on_stdout_output   s    #"&D	;;v&--gh-GD !D(,,K -  		s   "A< <B
Bc                sz   \        V4       FK  w  r4\        V\        4      '       d   K  \        P                  ! RV4       V'       d   \        V4      MRW&   KM  	  RV9   d   VR VP                  4        F  w  rV\        V\        4      '       d   VP                  4       '       d(   \        P                  ! RWVV4       \        V4      pW% KX  \        V\        4      '       d   Kp  \        P                  ! RWVV4       V'       d   \        V4      MRW%&   K  	  V P                  '       dH   \        P                  ! V P                  4      '       g"    \        P                  ! V P                  4        \         P"                  ! V\         P$                  \         P&                  V P                  VR7      #   \         d,    \        P                  ! RT P                  4       RT n         Lwi ; i  \         dD   p\        P(                  ! RR	P+                  T4      T4       TP,                  T n         R
p?R
# R
p?ii ; i)zExecute and return a subprocessz)Wrapper command contains a non-string: %srW   z4Environment contains a non-string as a key %s=%s: %szEEnvironment contains a non-string as the value for the key: %s=%s: %sz6Failed to create working directory, falling back to %sr   )r/   Zstderrr&   r   zFailed to execute %s: %sZ N)Z	enumeraterB   r2   r   rA   r@   Zisspacer    r&   r   Zpath_existsr   ZmakedirsZOSErrorr   fallback_cwd
subprocessZPopenZPIPEZSTDOUTZ	exceptionr	   Zstrerror)r*   r   r   ZiZitemrC   rD   Zexs   &&&     r   rH   Z MonitoredCommand.execute_process  s    !)GAdC((JGT*.SYB
 *
 9B))+JCc3''3;;==UWZcfg3iHeS))fhktwx).3u:B & 888F..txx88"DHH%
	%##!!((HH 	  "UW[WhWhi!"  	%7'9JBODJJ	%s+    F3 2A G, 33G)(G),H:78H55H:c                s   RV n          V P                  P                  4        V P	                  4       pV'       g   \
        P                  ! R4       R# V P                  '       d(   \        P                  ! V P                  4       RV n        RV n
        RV n        \        P                  V 4       R#   \         d     Li ; i)z9Stops the current game process and cleans up the instanceTz,Stop execution halted by demand of stop_funcFN)r   r   Z	terminateZProcessLookupErrorr   r   rA   r"   r   Zsource_remover   r   rI   Zdiscard)r*   r[   rE   r   rZ   ZMonitoredCommand.stop-  s      $	'')
 nn&NNIJt223"&D   &! " 		s   B1 1B?>B?)r(   r)   r   r   r&   r   r   r$   r   r#   r   r+   r    r   r   r   r   r"   r   r   )NNNNNNNNr-   )Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r\   r,   Zpropertyr/   r;   r!   r%   Zstaticmethodr   rF   rP   rS   r   r<   r   rY   rK   rO   rH   rZ   Z__static_attributes__Z__classdictcell__)r4   s   @r   r   r   *   s     ?L'5R ' 'D D&>.  0
6
 
!I
$*%X r   r   c                sh    \        \        P                  ! V 4      / R7      p V P                  4        V # )zWExecute arbitrary command in a MonitoredCommand

Used by the --exec command line flag.
)r   )r   shlexZsplitrP   )r   r.   r   exec_commandr`   G  s'    
 u{{73<GMMONr   )r^   rU   rM   r'   r   r_   r]   r
   r?   r    Ztypingr   Zgi.repositoryr   Zlutrisr   Zlutris.utilr   Zlutris.util.logr   Zlutris.util.shellr   r   r8   ZsetrI   r   r`   r   r   r   <module>ra      s_    C   	 	   
       " 1d  -.5 Z Zzr   