o
    çÕÊc‘  ã                   @   sJ   d dl Z d dlmZ d dlmZ d dlmZ e  e¡Z	G dd„ deƒZ
dS )é    N)Ú
BaseThread)ÚDelayedQueue)ÚInotifyc                       sL   e Zd Z	 dZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )ÚInotifyBufferg      à?Fc                    s.   t ƒ  ¡  t| jƒ| _t||ƒ| _|  ¡  d S ©N)ÚsuperÚ__init__r   ÚdelayÚ_queuer   Ú_inotifyÚstart)ÚselfÚpathÚ	recursive©Ú	__class__© úeG:\Development\the-witcher-3-mod-manager\.venv\lib\site-packages\watchdog\observers\inotify_buffer.pyr       s   
zInotifyBuffer.__init__c                 C   s   	 | j  ¡ S r   )r
   Úget©r   r   r   r   Ú
read_event&   s   
zInotifyBuffer.read_eventc                 C   s   | j  ¡  | j ¡  d S r   )r   Úcloser
   r   r   r   r   Úon_thread_stop-   s   
zInotifyBuffer.on_thread_stopc                 C   s   |   ¡  |  ¡  d S r   )ÚstopÚjoinr   r   r   r   r   1   s   zInotifyBuffer.closec                    s    	 g }|D ]H‰ t  dˆ ¡ ‡ fdd„}ˆ jrHt|ƒD ]\}}||ƒr*|ˆ f||<  nq| j |¡}|d ur=| |ˆ f¡ qt  d¡ | ˆ ¡ q| ˆ ¡ q|S )Nzin-event %sc                    s   t | tƒ o| jo| jˆ jkS r   )Ú
isinstanceÚtupleÚis_moved_fromÚcookie)Úevent©Úinotify_eventr   r   Úmatching_from_event;   s   
ÿz8InotifyBuffer._group_events.<locals>.matching_from_eventz'could not find matching move_from event)ÚloggerÚdebugÚis_moved_toÚ	enumerater
   ÚremoveÚappend)r   Ú
event_listÚgroupedr"   Úindexr   Z
from_eventr   r    r   Ú_group_events5   s&   þ

€zInotifyBuffer._group_eventsc                 C   s²   	 d}|   ¡ rS|sU| j ¡ }|  |¡}|D ]5}t|tƒs)|jr)|j| jjkr(d}qt|tƒ o1|j	}| j
 ||¡ t|tƒsJ|jrJ|j| jjkrJd}q|   ¡ rW|r	d S d S d S d S )NFT)Úshould_keep_runningr   Úread_eventsr,   r   r   Ú
is_ignoredÚsrc_pathr   r   r
   ÚputÚis_delete_self)r   Zdeleted_selfZinotify_eventsZgrouped_eventsr!   r	   r   r   r   ÚrunQ   s"   

€îzInotifyBuffer.run)F)Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   r   r,   r3   Ú__classcell__r   r   r   r   r      s    r   )ÚloggingÚwatchdog.utilsr   Úwatchdog.utils.delayed_queuer   Úwatchdog.observers.inotify_cr   Ú	getLoggerr4   r#   r   r   r   r   r   Ú<module>   s   
