cosapp.tools.trigger

Utility classes for executing CoSApp simulation following file events.

Those classes use third-party watchdog package to observe file events.

Classes

FileCreationHandler(owner, folder, timeout, …)

Specific watchdog class to monitor file creation events

FileModificationHandler(owner, folder, …)

Specific watchdog class to monitor file modification events.

WatchdogHandler(owner, folder, timeout, …)

Define a watchdog class that allows to trigger actions on file events (creation, modification, etc.).

class cosapp.tools.trigger.FileCreationHandler(owner: cosapp.systems.system.System, folder: str, timeout: float = 30.0, patterns: Union[List, AnyStr] = '*.*')[source]

Bases: cosapp.tools.trigger.WatchdogHandler

Specific watchdog class to monitor file creation events

Parameters
  • owner (System) – Owner of the watchdog. Actions will be triggered on him on events

  • folder (str) – Folder to supervise with the watchdog

  • timeout (float, optional) – Define the max inactivity duration of the watchdog

  • patterns (Union[List, AnyStr], optional) – Define the file patterns to monitor in the chosen path

on_created(event: watchdog.events.FileCreatedEvent)None[source]

Actions to complete when a creation event is triggered

Parameters

event – Event that triggered the watchdog

class cosapp.tools.trigger.FileModificationHandler(owner: cosapp.systems.system.System, folder: str, timeout: float = 30.0, patterns: Union[List, AnyStr] = '*.*')[source]

Bases: cosapp.tools.trigger.WatchdogHandler

Specific watchdog class to monitor file modification events.

Parameters
  • owner (System) – Owner of the watchdog. Actions will be triggered on him on events

  • folder (str) – Folder to supervise with the watchdog

  • timeout (float, optional) – Define the max inactivity duration of the watchdog

  • patterns (Union[List, AnyStr], optional) – Define the file patterns to monitor in the chosen path

on_modified(event: watchdog.events.FileModifiedEvent)None[source]

Actions to complete when a modification event is triggered

Parameters

event – Event that triggered the watchdog

class cosapp.tools.trigger.WatchdogHandler(owner: cosapp.systems.system.System, folder: str, timeout: float = 30.0, patterns: Union[List, AnyStr] = '*.*')[source]

Bases: watchdog.events.PatternMatchingEventHandler

Define a watchdog class that allows to trigger actions on file events (creation, modification, etc.).

Parameters
  • owner (System) – Owner of the watchdog. Actions will be triggered on him on events

  • folder (str) – Folder to supervise with the watchdog

  • timeout (float, optional) – Define the max inactivity duration of the watchdog

  • patterns (Union[List, AnyStr], optional) – Define the file patterns to monitor in the chosen path

compute(file_full_path: str)None[source]

Actions to do while an event is detected

Parameters

file_full_path (str) – Gives access to the file that triggered an event

is_alive()bool[source]

Is the watcher alive?

reset()None[source]

Reset the watchdog by stopping the timer countdown and starting a new one

start(time_step: float = 1.0)None[source]

Starts the watchdog monitoring

Parameters

time_step (float, optional) – Gives the time step at which the watchdog will check events in the supervised folder

stop()None[source]

Exits the watchdog monitoring