API Reference

watchdog.events

watchdog.observers.api

watchdog.observers

watchdog.observers.polling

watchdog.utils

module:watchdog.utils
synopsis:Utility classes and functions.
author:yesudeep@google.com (Yesudeep Mangalapilly)

Classes

class watchdog.utils.BaseThread[source]

Bases: threading.Thread

Convenience class for creating stoppable threads.

on_thread_start()[source]

Override this method instead of start(). start() calls this method.

This method is called right before this thread is started and this object’s run() method is invoked.

on_thread_stop()[source]

Override this method instead of stop(). stop() calls this method.

This method is called immediately after the thread is signaled to stop.

should_keep_running()[source]

Determines whether the thread should continue running.

stop()[source]

Signals the thread to stop.

watchdog.utils.dirsnapshot

module:watchdog.utils.dirsnapshot
synopsis:Directory snapshots and comparison.
author:yesudeep@google.com (Yesudeep Mangalapilly)

Where are the moved events? They “disappeared”

This implementation does not take partition boundaries into consideration. It will only work when the directory tree is entirely on the same file system. More specifically, any part of the code that depends on inode numbers can break if partition boundaries are crossed. In these cases, the snapshot diff will represent file/directory movement as created and deleted events.

Classes

class watchdog.utils.dirsnapshot.DirectorySnapshot(path, recursive=True, walker_callback=<function <lambda> at 0xa8beb8c>, stat=<built-in function stat>, listdir=<built-in function listdir>)[source]

Bases: object

A snapshot of stat information of files in a directory.

Parameters:
  • path (str) – The directory path for which a snapshot should be taken.
  • recursive (bool) – True if the entire directory tree should be included in the snapshot; False otherwise.
  • walker_callback

    Deprecated since version 0.7.2.

  • stat

    Use custom stat function that returns a stat structure for path. Currently only st_dev, st_ino, st_mode and st_mtime are needed.

    A function with the signature walker_callback(path, stat_info) which will be called for every entry in the directory tree.

  • listdir – Use custom listdir function. See os.listdir for details.
inode(path)[source]

Returns an id for path.

path(id)[source]

Returns path for id. None if id is unknown to this snapshot.

paths

Set of file/directory paths in the snapshot.

stat_info(path)[source]

Returns a stat information object for the specified path from the snapshot.

Attached information is subject to change. Do not use unless you specify stat in constructor. Use inode(), mtime(), isdir() instead.

Parameters:path – The path for which stat information should be obtained from a snapshot.
class watchdog.utils.dirsnapshot.DirectorySnapshotDiff(ref, snapshot)[source]

Bases: object

Compares two directory snapshots and creates an object that represents the difference between the two snapshots.

Parameters:
  • ref (DirectorySnapshot) – The reference directory snapshot.
  • snapshot (DirectorySnapshot) – The directory snapshot which will be compared with the reference snapshot.
dirs_created

List of directories that were created.

dirs_deleted

List of directories that were deleted.

dirs_modified

List of directories that were modified.

dirs_moved

List of directories that were moved.

Each event is a two-tuple the first item of which is the path that has been renamed to the second item in the tuple.

files_created

List of files that were created.

files_deleted

List of files that were deleted.

files_modified

List of files that were modified.

files_moved

List of files that were moved.

Each event is a two-tuple the first item of which is the path that has been renamed to the second item in the tuple.