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.ThreadConvenience class for creating stoppable threads.
-
daemon¶ A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are left.
-
ident¶ Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.
-
isAlive()¶ Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
-
is_alive()¶ Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
-
join(timeout=None)¶ Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.
-
name¶ A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.
-
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.
-
run()¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
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>>, stat=<built-in function stat>, listdir=<built-in function listdir>)[source]¶ Bases:
objectA snapshot of stat information of files in a directory.
Parameters: - path (
str) – The directory path for which a snapshot should be taken. - recursive (
bool) –Trueif the entire directory tree should be included in the snapshot;Falseotherwise. - 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.listdirfor details.
-
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.
- path (
-
class
watchdog.utils.dirsnapshot.DirectorySnapshotDiff(ref, snapshot)[source]¶ Bases:
objectCompares 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.
- ref (