HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/__pycache__/watchdog.cpython-310.pyc
o

�N�g�@s�dZddlZddlZddlZzddlmZddlmZdZ	Wne
y0dZ	Gdd�d�ZYnwd	Ze�e
�Zgd
�ZGdd�de�Zd
d�Zdd�ZGdd�de�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)!z�
Watch files and translate the changes into salt events.

.. versionadded:: 2019.2.0

:depends:   - watchdog Python module >= 0.8.3

�N)�FileSystemEventHandler)�ObserverTFc@seZdZdZdd�ZdS)rz%A dummy class to make the import workcCsdS�N�)�selfrr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/watchdog.py�__init__szFileSystemEventHandler.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrrsrZwatchdog)�create�delete�modify�movecsNeZdZd�fdd�	Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	�Z
S)�HandlerNcst���|pt|_||_dSr)�superr�DEFAULT_MASK�masks�queue)rrr��	__class__rrr.s


zHandler.__init__cC�|�|d�dS)Nr
��_append_if_mask�r�eventrrr�
on_created3�zHandler.on_createdcCr)Nrrrrrr�on_modified6rzHandler.on_modifiedcCr)Nrrrrrr�
on_deleted9rzHandler.on_deletedcCr)Nrrrrrr�on_moved<rzHandler.on_movedcCst�|�|�||�dSr)�logging�debug�_append_path_if_mask�rr�maskrrrr?s
zHandler._append_if_maskcCs||jvr
|j�|�dSdSr)rr�appendr%rrrr$Ds
�zHandler._append_path_if_maskr)r	r
rrrrr r!rr$�
__classcell__rrrrr-srcCs"trtSd}t�dt|�d|fS)Nzwatchdog library is missing.zUnable to load %s beacon: %sF)�HAS_WATCHDOG�__virtualname__�log�error)�err_msgrrr�__virtual__Is
r.cCszdtvr9t��}t�}|�di�D]}|�d��|�}|�dt�}t||�}|�||�q|��|td<|td<tdS)zL
    Check the context for the notifier and construct it if not present
    �watchdog.observer�directoriesr&zwatchdog.queue)	�__context__�collections�dequer�getrrZschedule�start)�configr�observer�pathZpath_paramsrZ
event_handlerrrr�
_get_queueQs
r9c@seZdZdS)�ValidationErrorN)r	r
rrrrrr:gsr:c
Cs@zt|�WdSty}zdt|�fWYd}~Sd}~ww)z+
    Validate the beacon configuration
    )TzValid beacon configurationFN)�	_validater:�str)r6r,rrr�validateks��r=cCsrt|t�s	td��i}|D]}|�|�q
d|vrtd��t|dt�s(td��|dD]
}t|d|�q,dS)Nz1Configuration for watchdog beacon must be a list.r0z;Configuration for watchdog beacon must include directories.zCConfiguration for watchdog beacon directories must be a dictionary.)�
isinstance�listr:�update�dict�_validate_path)r6Z_config�partr8rrrr;ws 
���r;cCs.t|t�s	td��d|vrt|d�dSdS)NzFConfiguration for watchdog beacon directory path must be a dictionary.r&)r>rAr:�_validate_mask)Zpath_configrrrrB�s
��rBcs<gd��t|t�s
td��t�fdd�|D��rtd��dS)N)r
rrrz4Configuration for watchdog beacon mask must be list.c3s�|]}|�vVqdSrr)�.0r&�Z
valid_maskrr�	<genexpr>�s�z!_validate_mask.<locals>.<genexpr>z7Configuration for watchdog beacon contains invalid mask)r>r?r:�any)Zmask_configrrFrrD�s
�rDcCst|j|jd�S)N)�tagr8Zchange)r*Zsrc_pathZ
event_type)rrrr�
to_salt_event�s�rJcCs8tjj�|�}t|�}g}|r|�t|����|s|S)a�
    Watch the configured directories

    Example Config

    .. code-block:: yaml

        beacons:
          watchdog:
            - directories:
                /path/to/dir:
                  mask:
                    - create
                    - modify
                    - delete
                    - move

    The mask list can contain the following events (the default mask is create,
    modify delete, and move):

    * create  - File or directory is created in watched directory
    * modify  - The watched directory is modified
    * delete  - File or directory is deleted from watched directory
    * move    - File or directory is moved or renamed in the watched directory
    )�salt�utilsZbeaconsZlist_to_dictr9r'rJ�popleft)r6r�retrrr�beacon�s�rOcCs t�dd�}|r|��dSdS)Nr/)r1�pop�stop)r6r7rrr�close�s�rR)rr2r"Zsalt.utils.beaconsrKZwatchdog.eventsrZwatchdog.observersrr)�ImportErrorr*�	getLoggerr	r+rrr.r9�	Exceptionr:r=r;rBrDrJrOrRrrrr�<module>s4	�


&