B
    `                 @   sX   d dl mZ d dlZd dlZd dlmZ d dlmZ ddl	m
Z
 G dd deee
ZdS )	    )absolute_importN)FileSystemEventHandler)Observer   )IFileMonitorc                   sP   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )WatchdogFileMonitora  
    An :class:`hupper.interfaces.IFileMonitor` that uses ``watchdog``
    to watch for file changes uses inotify.

    ``callback`` is a callable that accepts a path to a changed file.

    ``logger`` is an :class:`hupper.interfaces.ILogger` instance.

    c                s8   t t|   || _|| _t | _t | _t	 | _
d S )N)superr   __init__callbackloggersetpathsdirpaths	threadingLocklock)selfr
   r   kw)	__class__ W/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/hupper/watchdog.pyr	      s    zWatchdogFileMonitor.__init__c             C   s   | j  tj|}|| jkrvy| | | W n: ttfk
rh } z| j	dt
|  W d d }~X Y nX | j| || jkr| j| W d Q R X d S )Nzwatchdog error: )r   ospathdirnamer   ZscheduleOSErrorIOErrorr   errorstraddr   )r   r   dirpathexr   r   r   add_path   s    
&
zWatchdogFileMonitor.add_pathc          	   C   s*   | j  || jkr| | W d Q R X d S )N)r   r   r
   )r   r   r   r   r   _check.   s    
zWatchdogFileMonitor._checkc             C   s   |  |j d S )N)r"   src_path)r   eventr   r   r   
on_created3   s    zWatchdogFileMonitor.on_createdc             C   s   |  |j d S )N)r"   r#   )r   r$   r   r   r   on_modified6   s    zWatchdogFileMonitor.on_modifiedc             C   s(   |  |j |  |j | |j d S )N)r"   r#   	dest_pathr!   )r   r$   r   r   r   on_moved9   s    zWatchdogFileMonitor.on_movedc             C   s   |  |j d S )N)r"   r#   )r   r$   r   r   r   
on_deleted>   s    zWatchdogFileMonitor.on_deleted)__name__
__module____qualname____doc__r	   r!   r"   r%   r&   r(   r)   __classcell__r   r   )r   r   r      s   	r   )
__future__r   os.pathr   r   Zwatchdog.eventsr   Zwatchdog.observersr   Z
interfacesr   r   r   r   r   r   <module>   s   