
    G@d                        d Z ddlZddlmZmZ ddlmZ ddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ  ej        e          Z G d	 d
ej        j                  Zeej        _         G d dee          Z G d de          ZdS )z@Watcher to detect filesystem changes in the project's directory.    N)QObjectSignal)QMessageBox)Observer)FileSystemEventHandler)_)to_text_stringc                   ,     e Zd ZdZdZ fdZd Z xZS )BaseThreadWrapperzk
    Wrapper around watchdog BaseThread class.
    This is necessary for issue spyder-ide/spyder#11370
    Nc                     t          t          |                                            | j        | _        | j        | _        d S N)superr   __init__run_original_runrun_wrapper)self	__class__s    Elib/python3.11/site-packages/spyder/plugins/projects/utils/watcher.pyr   zBaseThreadWrapper.__init__"   s8    &&//111!X#    c                     	 |                                   d S # t          $ rE}t                              d|j                   | j                            |           Y d }~d S d }~ww xY w)Nz$Watchdog thread exited with error %s)r   OSErrorlogger	exceptionstrerrorqueueput)r   es     r   r   zBaseThreadWrapper.run_wrapper'   s    	      	 	 	CZ) ) )JNN1	s    
A':A""A')__name__
__module____qualname____doc__r   r   r   __classcell__r   s   @r   r   r      sX          E$ $ $ $ $
      r   r   c                       e Zd ZdZ eeee          Z eee          Z eee          Z	 eee          Z
d	dZd Zd Zd Zd Zd ZdS )
WorkspaceEventHandlerz
    Event handler for watchdog notifications.

    This class receives notifications about file/folder moving, modification,
    creation and deletion and emits a corresponding signal about it.
    Nc                 X    t          j        | |           t          j        |            d S r   )r   r   r   )r   parents     r   r   zWorkspaceEventHandler.__init__B   s,    v&&&'-----r   c                     |rdndS )N	directoryfile )r   is_dirs     r   
fmt_is_dirz WorkspaceEventHandler.fmt_is_dirF   s    $0{{&0r   c                     |j         }|j        }|j        }t                              d                    |                     |          ||                     | j                            |||           d S )NzMoved {0}: {1} to {2})	src_path	dest_pathis_directoryr   infoformatr.   sig_file_movedemit)r   eventr0   r1   r-   s        r   on_movedzWorkspaceEventHandler.on_movedI   su    >O	#+22OOF##Xy: : 	; 	; 	;  9f=====r   c                     |j         }|j        }t                              d                    |                     |          |                     | j                            ||           d S )NzCreated {0}: {1})r0   r2   r   r3   r4   r.   sig_file_createdr6   r   r7   r0   r-   s       r   
on_createdz WorkspaceEventHandler.on_createdQ   j    >#&--OOF##X/ / 	0 	0 	0""8V44444r   c                     |j         }|j        }t                              d                    |                     |          |                     | j                            ||           d S )NzDeleted {0}: {1})r0   r2   r   r3   r4   r.   sig_file_deletedr6   r;   s       r   
on_deletedz WorkspaceEventHandler.on_deletedX   r=   r   c                     |j         }|j        }t                              d                    |                     |          |                     | j                            ||           d S )NzModified {0}: {1})r0   r2   r   r3   r4   r.   sig_file_modifiedr6   r;   s       r   on_modifiedz!WorkspaceEventHandler.on_modified_   sj    >#'..OOF##X/ / 	0 	0 	0##Hf55555r   r   )r   r    r!   r"   r   strboolr5   r:   r?   rB   r   r.   r8   r<   r@   rC   r,   r   r   r&   r&   5   s          VCd++Nvc4((vc4((sD)). . . .1 1 1> > >5 5 55 5 56 6 6 6 6r   r&   c                   :     e Zd ZdZdZd fd	Zd Zd Zd Z xZ	S )WorkspaceWatcherz{
    Wrapper class around watchdog observer and notifier.

    It provides methods to start and stop watching folders.
    Nc                 r    t                                          |           t          |           | _        d S r   )r   r   r&   event_handler)r   r(   r   s     r   r   zWorkspaceWatcher.__init__p   s1       2488r   c                 &   | j         j                            |j                   | j         j                            |j                   | j         j                            |j                   | j         j                            |j	                   d S r   )
rI   r:   connectfile_createdr5   
file_movedr?   file_deletedrB   file_modified)r   projects     r   connect_signalsz WorkspaceWatcher.connect_signalst   s|    +33G4HIII)11'2DEEE+33G4HIII,44W5JKKKKKr   c                    	 t                      | _        | j                            | j        |d           	 | j                                         d S # t
          $ r t                              d           Y d S w xY w# t
          $ r[}d | _        dt          |          v r6t          j
        |                                 dt          d                     n|Y d }~d S d }~ww xY w)NT)	recursivezWatcher could not be started.inotifySpydera  File system changes for this project can't be tracked because it contains too many files. To fix this you need to increase the inotify limit in your system, with the following command:<br><br><code>sudo sysctl -n -w fs.inotify.max_user_watches=524288</code><br><br>For a permanent solution you need to add to<code>/etc/sysctl.conf</code>the following line:<br><br><code>fs.inotify.max_user_watches=524288</code><br><br>After doing that, you need to close and start Spyder again so those changes can take effect.)r   observerschedulerI   startr   r   debugr	   r   warningr(   r   )r   workspace_folderr   s      r   rX   zWorkspaceWatcher.startz   s<   !	$JJDMM"""$4 # F F F>##%%%%% > > ><======>  	 	 	 DM^A....#KKMM @ A AB B B B* +B B B B B B	s5   5A> A $A;7A> :A;;A> >
C#ACC#c                     | j         O	 | j                                          | j                                          | ` d | _         d S # t          $ r Y d S w xY wd S r   )rV   stopjoinRuntimeError)r   s    r   r]   zWorkspaceWatcher.stop   sq    =$""$$$""$$$M $    %$s   ;A 
AAr   )
r   r    r!   r"   rV   r   rQ   rX   r]   r#   r$   s   @r   rG   rG   g   s          H9 9 9 9 9 9L L L$ $ $L      r   rG   )r"   loggingqtpy.QtCorer   r   qtpy.QtWidgetsr   watchdogwatchdog.observersr   watchdog.eventsr   spyder.config.baser   spyder.py3compatr	   	getLoggerr   r   utils
BaseThreadr   r&   rG   r,   r   r   <module>rk      sQ   G F  ( ' ' ' ' ' ' ' & & & & & &  ' ' ' ' ' ' 2 2 2 2 2 2 !           + + + + + +		8	$	$    1   . . /6 /6 /6 /6 /6G%; /6 /6 /6dD D D D Dw D D D D Dr   