platypush.backend.file.monitor

class platypush.backend.file.monitor.FileMonitorBackend(paths: Iterable[Union[str, Dict[str, Any], platypush.backend.file.monitor.entities.resources.MonitoredResource]], **kwargs)[source]

This backend monitors changes to local files and directories using the Watchdog API.

Triggers:

Requires:

  • watchdog (pip install watchdog)

class EventHandlerFactory[source]

Create a file system event handler from a string, dictionary or MonitoredResource resource.

static from_resource(resource: Union[str, Dict[str, Any], platypush.backend.file.monitor.entities.resources.MonitoredResource])platypush.backend.file.monitor.entities.handlers.EventHandler[source]
__init__(paths: Iterable[Union[str, Dict[str, Any], platypush.backend.file.monitor.entities.resources.MonitoredResource]], **kwargs)[source]
Parameters

paths

List of paths to monitor. Paths can either be expressed in any of the following ways:

  • Simple strings. In this case, paths will be interpreted as absolute references to a file or a directory to monitor. Example:

    backend.file.monitor:
        paths:
            # Monitor changes on the /tmp folder
            - /tmp
            # Monitor changes on /etc/passwd
            - /etc/passwd
    
  • Path with monitoring properties expressed as a key-value object. Example showing the supported attributes:

    backend.file.monitor:
        paths:
            # Monitor changes on the /tmp folder and its subfolders
            - path: /tmp
              recursive: True
    
  • Path with pattern-based search criteria for the files to monitor and exclude. Example:

    backend.file.monitor:
        paths:
            # Recursively monitor changes on the ~/my-project folder that include all
            # *.py files, excluding those whose name starts with tmp_ and
            # all the files contained in the __pycache__ folders
            - path: ~/my-project
              recursive: True
              patterns:
                - "*.py"
              ignore_patterns:
                - "tmp_*"
              ignore_directories:
                - "__pycache__"
    
  • Path with regex-based search criteria for the files to monitor and exclude. Example:

    backend.file.monitor:
        paths:
            # Recursively monitor changes on the ~/my-images folder that include all
            # the files matching a JPEG extension in case-insensitive mode,
            # excluding those whose name starts with tmp_ and
            # all the files contained in the __MACOSX folders
            - path: ~/my-images
              recursive: True
              case_sensitive: False
              regexes:
                - '.*\.jpe?g$'
              ignore_patterns:
                - '^tmp_.*'
              ignore_directories:
                - '__MACOSX'
    

on_stop()[source]

Callback invoked when the process stops

run()[source]

Starts the backend thread. To be implemented in the derived classes if the loop method isn’t defined.