Watcher Manager

The WatcherManager class is responsible for orchestrating the watchers.

The watchers are created based on the files returned by the GlobManager instance that get provided to this class. For each file that the GlobManager returns a new Watcher is created. Multiple options can be provided to this class that allows for some configuration, please see the __init__() method documentation for details.

As an example, the following code would set up watchers for all files returned by glob_manager using the ModificationTime method. Newly created files are detected and added to the watch list and files that get deleted are considered to be a change (this is specified as the last two parameters of the constructor).

>>> manager = WatcherManager(
...     ModificationTime, glob_manager, True, True)

All of the changed files can be retrieved by calling get_changed_files().

>>> manager.get_changed_files()
class watch_do.watcher_manager.WatcherManager(watcher, glob_manager, reglob, changed_on_remove)[source]

This class creates and manages watchers.

A Watcher and an instance of GlobManager are passed in, which provides the necessary information for the class to create the required watchers that can be used to detect changes.

Initialise the WatcherManager.

Parameters:
  • watcher (Watcher) – A reference to a subclass of Watcher (i.e. ModificationTime) that will be used watch the files provided by the GlobManager.
  • glob_manager (GlobManager) – The glob manager responsible for providing a list of files.
  • reglob (bool) – A boolean value indicating whether to re-evaluate globs when get_changed_files() is called.
  • changed_on_remove (bool) – A boolean value indicating whether to consider the removal of a file a change.
changed_on_remove

bool – A boolean value indicating if removed files count as a change.

files

set – The set of file names (relative to the current directory) that are being watched.

get_changed_files()[source]

Get a set containing the changed files since the last call.

This method determines which files have changed since the last time this method was called. Added files, changed files (determined by the type of watcher) and removed files (if changed_on_remove is True) are all counted as changed files.

The watchers are stored and managed internally to this class.

Returns:A set of files that have changed since the last time this method was called.
Return type:set
glob_manager

GlobManager – The instance of the GlobManager that was passed in.

reglob

bool – A boolean value indicating whether we are re-evaluating file globs each time get_changed_files() is called.

watcher

Watcher – A reference to the Watcher class that is being used to detect changes.