.\" Man page generated from reStructuredText. . .TH "WATCHDOG" "3" "Dec 01, 2018" "0.9.0" "watchdog" .SH NAME watchdog \- watchdog Documentation . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .sp Python API library and shell utilities to monitor file system events. .SH DIRECTORY MONITORING MADE EASY WITH .INDENT 0.0 .IP \(bu 2 A cross\-platform API. .IP \(bu 2 A shell tool to run commands in response to directory changes. .UNINDENT .sp Get started quickly with a simple example in quickstart\&. .SH EASY INSTALLATION .sp You can use \fI\%pip\fP to install \fBwatchdog\fP quickly and easily: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ pip install watchdog .ft P .fi .UNINDENT .UNINDENT .sp Need more help with installing? See installation\&. .SH INSTALLATION .sp \fBwatchdog\fP requires Python 2.6 or above to work. If you are using a Linux/FreeBSD/Mac OS X system, you already have Python installed. However, you may wish to upgrade your system to Python 2.7 at least, because this version comes with updates that can reduce compatibility problems. See a list of \fI\%Dependencies\fP\&. .SS Installing from PyPI using pip .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ pip install \fBwatchdog\fP .ft P .fi .UNINDENT .UNINDENT .SS Installing from source tarballs .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ wget \-c \fI\%http://pypi.python.org/packages/source/w/watchdog/watchdog\fP\-0.9.0\&.tar.gz $ tar zxvf \fBwatchdog\fP\-0.9.0\&.tar.gz $ cd \fBwatchdog\fP\-0.9.0 $ python setup.py install .ft P .fi .UNINDENT .UNINDENT .SS Installing from the code repository .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ git clone \-\-recursive git://github.com/gorakhargosh/watchdog.git $ cd watchdog $ python setup.py install .ft P .fi .UNINDENT .UNINDENT .SS Dependencies .sp \fBwatchdog\fP depends on many libraries to do its job. The following is a list of dependencies you need based on the operating system you are using. .TS center; |l|l|l|l|l|. _ T{ Operating system Dependency (row) T} T{ Windows T} T{ Linux 2.6 T} T{ .INDENT 0.0 .TP .B Mac OS X/ Darwin .UNINDENT T} T{ BSD T} _ T{ \fI\%XCode\fP T} T{ T} T{ T} T{ Yes T} T{ T} _ T{ \fI\%PyYAML\fP T} T{ Yes T} T{ Yes T} T{ Yes T} T{ Yes T} _ T{ \fI\%argh\fP T} T{ Yes T} T{ Yes T} T{ Yes T} T{ Yes T} _ T{ \fI\%argparse\fP T} T{ Yes T} T{ Yes T} T{ Yes T} T{ Yes T} _ T{ \fI\%select_backport\fP (Python 2.6) T} T{ T} T{ T} T{ Yes T} T{ Yes T} _ T{ \fI\%pathtools\fP T} T{ Yes T} T{ Yes T} T{ Yes T} T{ Yes T} _ .TE .SS Installing Dependencies .sp The \fBwatchmedo\fP script depends on \fI\%PyYAML\fP which links with \fI\%LibYAML\fP\&. On Mac OS X, you can use \fI\%homebrew\fP to install LibYAML: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C brew install libyaml .ft P .fi .UNINDENT .UNINDENT .sp On Linux, use your favorite package manager to install LibYAML. Here\(aqs how you do it on Ubuntu: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C sudo aptitude install libyaml\-dev .ft P .fi .UNINDENT .UNINDENT .sp On Windows, please install \fI\%PyYAML\fP using the binaries they provide. .SS Supported Platforms (and Caveats) .sp \fBwatchdog\fP uses native APIs as much as possible falling back to polling the disk periodically to compare directory snapshots only when it cannot use an API natively\-provided by the underlying operating system. The following operating systems are currently supported: .sp \fBWARNING:\fP .INDENT 0.0 .INDENT 3.5 Differences between behaviors of these native API are noted below. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Linux 2.6+ Linux kernel version 2.6 and later come with an API called \fI\%inotify\fP that programs can use to monitor file system events. .sp \fBNOTE:\fP .INDENT 7.0 .INDENT 3.5 On most systems the maximum number of watches that can be created per user is limited to \fB8192\fP\&. \fBwatchdog\fP needs one per directory to monitor. To change this limit, edit \fB/etc/sysctl.conf\fP and add: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C fs.inotify.max_user_watches=16384 .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .TP .B Mac OS X The Darwin kernel/OS X API maintains two ways to monitor directories for file system events: .INDENT 7.0 .IP \(bu 2 \fI\%kqueue\fP .IP \(bu 2 \fI\%FSEvents\fP .UNINDENT .sp \fBwatchdog\fP can use whichever one is available, preferring FSEvents over \fBkqueue(2)\fP\&. \fBkqueue(2)\fP uses open file descriptors for monitoring and the current implementation uses \fI\%Mac OS X File System Monitoring Performance Guidelines\fP to open these file descriptors only to monitor events, thus allowing OS X to unmount volumes that are being watched without locking them. .sp \fBNOTE:\fP .INDENT 7.0 .INDENT 3.5 More information about how \fBwatchdog\fP uses \fBkqueue(2)\fP is noted in \fI\%BSD Unix variants\fP\&. Much of this information applies to Mac OS X as well. .UNINDENT .UNINDENT .TP .B BSD variants come with \fI\%kqueue\fP which programs can use to monitor changes to open file descriptors. Because of the way \fBkqueue(2)\fP works, \fBwatchdog\fP needs to open these files and directories in read\-only non\-blocking mode and keep books about them. .sp \fBwatchdog\fP will automatically open file descriptors for all new files/directories created and close those for which are deleted. .sp \fBNOTE:\fP .INDENT 7.0 .INDENT 3.5 The maximum number of open file descriptor per process limit on your operating system can hinder \fBwatchdog\fP\(aqs ability to monitor files. .sp You should ensure this limit is set to at least \fB1024\fP (or a value suitable to your usage). The following command appended to your \fB~/.profile\fP configuration file does this for you: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C ulimit \-n 1024 .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .TP .B Windows Vista and later The Windows API provides the \fI\%ReadDirectoryChangesW\fP\&. \fBwatchdog\fP currently contains implementation for a synchronous approach requiring additional API functionality only available in Windows Vista and later. .sp \fBNOTE:\fP .INDENT 7.0 .INDENT 3.5 Since renaming is not the same operation as movement on Windows, \fBwatchdog\fP tries hard to convert renames to movement events. Also, because the \fI\%ReadDirectoryChangesW\fP API function returns rename/movement events for directories even before the underlying I/O is complete, \fBwatchdog\fP may not be able to completely scan the moved directory in order to successfully queue movement events for files and directories within it. .UNINDENT .UNINDENT .sp \fBNOTE:\fP .INDENT 7.0 .INDENT 3.5 Since the Windows API does not provide information about whether an object is a file or a directory, delete events for directories may be reported as a file deleted event. .UNINDENT .UNINDENT .TP .B OS Independent Polling \fBwatchdog\fP also includes a fallback\-implementation that polls watched directories for changes by periodically comparing snapshots of the directory tree. .UNINDENT .SH QUICKSTART .sp Below we present a simple example that monitors the current directory recursively (which means, it will traverse any sub\-directories) to detect changes. Here is what we will do with the API: .INDENT 0.0 .IP 1. 3 Create an instance of the \fBwatchdog.observers.Observer\fP thread class. .IP 2. 3 Implement a subclass of \fBwatchdog.events.FileSystemEventHandler\fP (or as in our case, we will use the built\-in \fBwatchdog.events.LoggingEventHandler\fP, which already does). .IP 3. 3 Schedule monitoring a few paths with the observer instance attaching the event handler. .IP 4. 3 Start the observer thread and wait for it generate events without blocking our main thread. .UNINDENT .sp By default, an \fBwatchdog.observers.Observer\fP instance will not monitor sub\-directories. By passing \fBrecursive=True\fP in the call to \fBwatchdog.observers.Observer.schedule()\fP monitoring entire directory trees is ensured. .SS A Simple Example .sp The following example program will monitor the current directory recursively for file system changes and simply log them to the console: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C import sys import logging from watchdog.observers import Observer from watchdog.events import LoggingEventHandler if __name__ == "__main__": logging.basicConfig(level=logging.INFO, format=\(aq%(asctime)s \- %(message)s\(aq, datefmt=\(aq%Y\-%m\-%d %H:%M:%S\(aq) path = sys.argv[1] if len(sys.argv) > 1 else \(aq.\(aq event_handler = LoggingEventHandler() observer = Observer() observer.schedule(event_handler, path, recursive=True) observer.start() try: while observer.isAlive(): observer.join(1) except KeyboardInterrupt: observer.stop() observer.join() .ft P .fi .UNINDENT .UNINDENT .sp To stop the program, press Control\-C. .SH API REFERENCE .SS \fIwatchdog.events\fP .INDENT 0.0 .TP .B module watchdog.events .TP .B synopsis File system events and event handlers. .TP .B author \fI\%yesudeep@google.com\fP (Yesudeep Mangalapilly) .UNINDENT .SS Event Classes .INDENT 0.0 .TP .B class watchdog.events.FileSystemEvent(src_path) Bases: \fBobject\fP .sp Immutable type that represents a file system event that is triggered when a change occurs on the monitored file system. .sp All FileSystemEvent objects are required to be immutable and hence can be used as keys in dictionaries or be added to sets. .INDENT 7.0 .TP .B event_type = None The type of the event as a string. .UNINDENT .INDENT 7.0 .TP .B is_directory = False True if event was emitted for a directory; False otherwise. .UNINDENT .INDENT 7.0 .TP .B src_path Source path of the file system object that triggered this event. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.FileSystemMovedEvent(src_path, dest_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing any kind of file system movement. .INDENT 7.0 .TP .B dest_path The destination path of the move event. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.FileMovedEvent(src_path, dest_path) Bases: \fI\%watchdog.events.FileSystemMovedEvent\fP .sp File system event representing file movement on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.DirMovedEvent(src_path, dest_path) Bases: \fI\%watchdog.events.FileSystemMovedEvent\fP .sp File system event representing directory movement on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.FileModifiedEvent(src_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing file modification on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.DirModifiedEvent(src_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing directory modification on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.FileCreatedEvent(src_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing file creation on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.DirCreatedEvent(src_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing directory creation on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.FileDeletedEvent(src_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing file deletion on the file system. .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.DirDeletedEvent(src_path) Bases: \fI\%watchdog.events.FileSystemEvent\fP .sp File system event representing directory deletion on the file system. .UNINDENT .SS Event Handler Classes .INDENT 0.0 .TP .B class watchdog.events.FileSystemEventHandler Bases: \fBobject\fP .sp Base file system event handler that you can override methods from. .INDENT 7.0 .TP .B dispatch(event) Dispatches events to the appropriate methods. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%FileSystemEvent\fP) \-\- The event object representing the file system event. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_any_event(event) Catch\-all event handler. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%FileSystemEvent\fP) \-\- The event object representing the file system event. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_created(event) Called when a file or directory is created. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirCreatedEvent\fP or \fI\%FileCreatedEvent\fP) \-\- Event representing file/directory creation. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_deleted(event) Called when a file or directory is deleted. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirDeletedEvent\fP or \fI\%FileDeletedEvent\fP) \-\- Event representing file/directory deletion. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_modified(event) Called when a file or directory is modified. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirModifiedEvent\fP or \fI\%FileModifiedEvent\fP) \-\- Event representing file/directory modification. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_moved(event) Called when a file or a directory is moved or renamed. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirMovedEvent\fP or \fI\%FileMovedEvent\fP) \-\- Event representing file/directory movement. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.PatternMatchingEventHandler(patterns=None, ignore_patterns=None, ignore_directories=False, case_sensitive=False) Bases: \fI\%watchdog.events.FileSystemEventHandler\fP .sp Matches given patterns with file paths associated with occurring events. .INDENT 7.0 .TP .B case_sensitive (Read\-only) \fBTrue\fP if path names should be matched sensitive to case; \fBFalse\fP otherwise. .UNINDENT .INDENT 7.0 .TP .B dispatch(event) Dispatches events to the appropriate methods. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%FileSystemEvent\fP) \-\- The event object representing the file system event. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B ignore_directories (Read\-only) \fBTrue\fP if directories should be ignored; \fBFalse\fP otherwise. .UNINDENT .INDENT 7.0 .TP .B ignore_patterns (Read\-only) Patterns to ignore matching event paths. .UNINDENT .INDENT 7.0 .TP .B patterns (Read\-only) Patterns to allow matching event paths. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.RegexMatchingEventHandler(regexes=[\(aq.*\(aq], ignore_regexes=[], ignore_directories=False, case_sensitive=False) Bases: \fI\%watchdog.events.FileSystemEventHandler\fP .sp Matches given regexes with file paths associated with occurring events. .INDENT 7.0 .TP .B case_sensitive (Read\-only) \fBTrue\fP if path names should be matched sensitive to case; \fBFalse\fP otherwise. .UNINDENT .INDENT 7.0 .TP .B dispatch(event) Dispatches events to the appropriate methods. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%FileSystemEvent\fP) \-\- The event object representing the file system event. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B ignore_directories (Read\-only) \fBTrue\fP if directories should be ignored; \fBFalse\fP otherwise. .UNINDENT .INDENT 7.0 .TP .B ignore_regexes (Read\-only) Regexes to ignore matching event paths. .UNINDENT .INDENT 7.0 .TP .B regexes (Read\-only) Regexes to allow matching event paths. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.events.LoggingEventHandler Bases: \fI\%watchdog.events.FileSystemEventHandler\fP .sp Logs all the events captured. .INDENT 7.0 .TP .B on_created(event) Called when a file or directory is created. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirCreatedEvent\fP or \fI\%FileCreatedEvent\fP) \-\- Event representing file/directory creation. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_deleted(event) Called when a file or directory is deleted. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirDeletedEvent\fP or \fI\%FileDeletedEvent\fP) \-\- Event representing file/directory deletion. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_modified(event) Called when a file or directory is modified. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirModifiedEvent\fP or \fI\%FileModifiedEvent\fP) \-\- Event representing file/directory modification. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B on_moved(event) Called when a file or a directory is moved or renamed. .INDENT 7.0 .TP .B Parameters \fBevent\fP (\fI\%DirMovedEvent\fP or \fI\%FileMovedEvent\fP) \-\- Event representing file/directory movement. .UNINDENT .UNINDENT .UNINDENT .SS \fIwatchdog.observers.api\fP .SS Immutables .INDENT 0.0 .TP .B class watchdog.observers.api.ObservedWatch(path, recursive) Bases: \fBobject\fP .sp An scheduled watch. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBpath\fP \-\- Path string. .IP \(bu 2 \fBrecursive\fP \-\- \fBTrue\fP if watch is recursive; \fBFalse\fP otherwise. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B is_recursive Determines whether subdirectories are watched for the path. .UNINDENT .INDENT 7.0 .TP .B path The path that this watch monitors. .UNINDENT .UNINDENT .SS Collections .INDENT 0.0 .TP .B class watchdog.observers.api.EventQueue(maxsize=0) Bases: \fBwatchdog.utils.bricks.SkipRepeatsQueue\fP .sp Thread\-safe event queue based on a special queue that skips adding the same event (\fBFileSystemEvent\fP) multiple times consecutively. Thus avoiding dispatching multiple event handling calls when multiple identical events are produced quicker than an observer can consume them. .UNINDENT .SS Classes .INDENT 0.0 .TP .B class watchdog.observers.api.EventEmitter(event_queue, watch, timeout=1) Bases: \fI\%watchdog.utils.BaseThread\fP .sp Producer thread base class subclassed by event emitters that generate events and populate a queue with them. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBevent_queue\fP (\fBwatchdog.events.EventQueue\fP) \-\- The event queue to populate with generated events. .IP \(bu 2 \fBwatch\fP (\fI\%ObservedWatch\fP) \-\- The watch to observe and produce events for. .IP \(bu 2 \fBtimeout\fP (\fBfloat\fP) \-\- Timeout (in seconds) between successive attempts at reading events. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B queue_event(event) Queues a single event. .INDENT 7.0 .TP .B Parameters \fBevent\fP (An instance of \fI\%watchdog.events.FileSystemEvent\fP or a subclass.) \-\- Event to be queued. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B queue_events(timeout) Override this method to populate the event queue with events per interval period. .INDENT 7.0 .TP .B Parameters \fBtimeout\fP (\fBfloat\fP) \-\- Timeout (in seconds) between successive attempts at reading events. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B run() Method representing the thread\(aqs activity. .sp You may override this method in a subclass. The standard run() method invokes the callable object passed to the object\(aqs constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively. .UNINDENT .INDENT 7.0 .TP .B timeout Blocking timeout for reading events. .UNINDENT .INDENT 7.0 .TP .B watch The watch associated with this emitter. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.observers.api.EventDispatcher(timeout=1) Bases: \fI\%watchdog.utils.BaseThread\fP .sp Consumer thread base class subclassed by event observer threads that dispatch events from an event queue to appropriate event handlers. .INDENT 7.0 .TP .B Parameters \fBtimeout\fP (\fBfloat\fP) \-\- Event queue blocking timeout (in seconds). .UNINDENT .INDENT 7.0 .TP .B dispatch_events(event_queue, timeout) Override this method to consume events from an event queue, blocking on the queue for the specified timeout before raising \fBqueue.Empty\fP\&. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBevent_queue\fP (\fI\%EventQueue\fP) \-\- Event queue to populate with one set of events. .IP \(bu 2 \fBtimeout\fP (\fBfloat\fP) \-\- Interval period (in seconds) to wait before timing out on the event queue. .UNINDENT .TP .B Raises \fBqueue.Empty\fP .UNINDENT .UNINDENT .INDENT 7.0 .TP .B event_queue The event queue which is populated with file system events by emitters and from which events are dispatched by a dispatcher thread. .UNINDENT .INDENT 7.0 .TP .B run() Method representing the thread\(aqs activity. .sp You may override this method in a subclass. The standard run() method invokes the callable object passed to the object\(aqs constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively. .UNINDENT .INDENT 7.0 .TP .B timeout Event queue block timeout. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.observers.api.BaseObserver(emitter_class, timeout=1) Bases: \fI\%watchdog.observers.api.EventDispatcher\fP .sp Base observer. .INDENT 7.0 .TP .B add_handler_for_watch(event_handler, watch) Adds a handler for the given watch. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBevent_handler\fP (\fI\%watchdog.events.FileSystemEventHandler\fP or a subclass) \-\- An event handler instance that has appropriate event handling methods which will be called by the observer in response to file system events. .IP \(bu 2 \fBwatch\fP (An instance of \fI\%ObservedWatch\fP or a subclass of \fI\%ObservedWatch\fP) \-\- The watch to add a handler for. .UNINDENT .UNINDENT .UNINDENT .INDENT 7.0 .TP .B dispatch_events(event_queue, timeout) Override this method to consume events from an event queue, blocking on the queue for the specified timeout before raising \fBqueue.Empty\fP\&. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBevent_queue\fP (\fI\%EventQueue\fP) \-\- Event queue to populate with one set of events. .IP \(bu 2 \fBtimeout\fP (\fBfloat\fP) \-\- Interval period (in seconds) to wait before timing out on the event queue. .UNINDENT .TP .B Raises \fBqueue.Empty\fP .UNINDENT .UNINDENT .INDENT 7.0 .TP .B emitters Returns event emitter created by this observer. .UNINDENT .INDENT 7.0 .TP .B on_thread_stop() Override this method instead of \fBstop()\fP\&. \fBstop()\fP calls this method. .sp This method is called immediately after the thread is signaled to stop. .UNINDENT .INDENT 7.0 .TP .B remove_handler_for_watch(event_handler, watch) Removes a handler for the given watch. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBevent_handler\fP (\fI\%watchdog.events.FileSystemEventHandler\fP or a subclass) \-\- An event handler instance that has appropriate event handling methods which will be called by the observer in response to file system events. .IP \(bu 2 \fBwatch\fP (An instance of \fI\%ObservedWatch\fP or a subclass of \fI\%ObservedWatch\fP) \-\- The watch to remove a handler for. .UNINDENT .UNINDENT .UNINDENT .INDENT 7.0 .TP .B schedule(event_handler, path, recursive=False) Schedules watching a path and calls appropriate methods specified in the given event handler in response to file system events. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBevent_handler\fP (\fI\%watchdog.events.FileSystemEventHandler\fP or a subclass) \-\- An event handler instance that has appropriate event handling methods which will be called by the observer in response to file system events. .IP \(bu 2 \fBpath\fP (\fBstr\fP) \-\- Directory path that will be monitored. .IP \(bu 2 \fBrecursive\fP (\fBbool\fP) \-\- \fBTrue\fP if events will be emitted for sub\-directories traversed recursively; \fBFalse\fP otherwise. .UNINDENT .TP .B Returns An \fI\%ObservedWatch\fP object instance representing a watch. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B start() Start the thread\(aqs activity. .sp It must be called at most once per thread object. It arranges for the object\(aqs run() method to be invoked in a separate thread of control. .sp This method will raise a RuntimeError if called more than once on the same thread object. .UNINDENT .INDENT 7.0 .TP .B unschedule(watch) Unschedules a watch. .INDENT 7.0 .TP .B Parameters \fBwatch\fP (An instance of \fI\%ObservedWatch\fP or a subclass of \fI\%ObservedWatch\fP) \-\- The watch to unschedule. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B unschedule_all() Unschedules all watches and detaches all associated event handlers. .UNINDENT .UNINDENT .SS \fIwatchdog.observers\fP .INDENT 0.0 .TP .B module watchdog.observers .TP .B synopsis Observer that picks a native implementation if available. .TP .B author \fI\%yesudeep@google.com\fP (Yesudeep Mangalapilly) .UNINDENT .SS Classes .INDENT 0.0 .TP .B watchdog.observers.Observer alias of \fBwatchdog.observers.inotify.InotifyObserver\fP .UNINDENT .sp Observer thread that schedules watching directories and dispatches calls to event handlers. .sp You can also import platform specific classes directly and use it instead of \fI\%Observer\fP\&. Here is a list of implemented observer classes.: .TS center; |l|l|l|. _ T{ Class T} T{ Platforms T} T{ Note T} _ T{ \fBinotify.InotifyObserver\fP T} T{ Linux 2.6.13+ T} T{ \fBinotify(7)\fP based observer T} _ T{ \fBfsevents.FSEventsObserver\fP T} T{ Mac OS X T} T{ FSEvents based observer T} _ T{ \fBkqueue.KqueueObserver\fP T} T{ Mac OS X and BSD with kqueue(2) T} T{ \fBkqueue(2)\fP based observer T} _ T{ \fBread_directory_changes.WindowsApiObserver\fP T} T{ MS Windows T} T{ Windows API\-based observer T} _ T{ \fI\%polling.PollingObserver\fP T} T{ Any T} T{ fallback implementation T} _ .TE .SS \fIwatchdog.observers.polling\fP .INDENT 0.0 .TP .B module watchdog.observers.polling .TP .B synopsis Polling emitter implementation. .TP .B author \fI\%yesudeep@google.com\fP (Yesudeep Mangalapilly) .UNINDENT .SS Classes .INDENT 0.0 .TP .B class watchdog.observers.polling.PollingObserver(timeout=1) Bases: \fI\%watchdog.observers.api.BaseObserver\fP .sp Platform\-independent observer that polls a directory to detect file system changes. .UNINDENT .INDENT 0.0 .TP .B class watchdog.observers.polling.PollingObserverVFS(stat, listdir, polling_interval=1) Bases: \fI\%watchdog.observers.api.BaseObserver\fP .sp File system independent observer that polls a directory to detect changes. .INDENT 7.0 .TP .B __init__(stat, listdir, polling_interval=1) .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBstat\fP \-\- stat function. See \fBos.stat\fP for details. .IP \(bu 2 \fBlistdir\fP \-\- listdir function. See \fBos.listdir\fP for details. .IP \(bu 2 \fBpolling_interval\fP (\fIfloat\fP) \-\- interval in seconds between polling the file system. .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SS \fIwatchdog.utils\fP .INDENT 0.0 .TP .B module watchdog.utils .TP .B synopsis Utility classes and functions. .TP .B author \fI\%yesudeep@google.com\fP (Yesudeep Mangalapilly) .UNINDENT .SS Classes .INDENT 0.0 .TP .B class watchdog.utils.BaseThread Bases: \fBthreading.Thread\fP .sp Convenience class for creating stoppable threads. .INDENT 7.0 .TP .B daemon A boolean value indicating whether this thread is a daemon thread. .sp 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. .sp The entire Python program exits when no alive non\-daemon threads are left. .UNINDENT .INDENT 7.0 .TP .B ident Thread identifier of this thread or None if it has not been started. .sp This is a nonzero integer. See the 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. .UNINDENT .INDENT 7.0 .TP .B isAlive() Return whether the thread is alive. .sp 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. .UNINDENT .INDENT 7.0 .TP .B is_alive() Return whether the thread is alive. .sp 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. .UNINDENT .INDENT 7.0 .TP .B join(timeout=None) Wait until the thread terminates. .sp 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. .sp 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. .sp When the timeout argument is not present or None, the operation will block until the thread terminates. .sp A thread can be join()ed many times. .sp 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. .UNINDENT .INDENT 7.0 .TP .B name A string used for identification purposes only. .sp It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor. .UNINDENT .INDENT 7.0 .TP .B on_thread_start() Override this method instead of \fI\%start()\fP\&. \fI\%start()\fP calls this method. .sp This method is called right before this thread is started and this object’s run() method is invoked. .UNINDENT .INDENT 7.0 .TP .B on_thread_stop() Override this method instead of \fI\%stop()\fP\&. \fI\%stop()\fP calls this method. .sp This method is called immediately after the thread is signaled to stop. .UNINDENT .INDENT 7.0 .TP .B run() Method representing the thread\(aqs activity. .sp You may override this method in a subclass. The standard run() method invokes the callable object passed to the object\(aqs constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively. .UNINDENT .INDENT 7.0 .TP .B should_keep_running() Determines whether the thread should continue running. .UNINDENT .INDENT 7.0 .TP .B start() Start the thread\(aqs activity. .sp It must be called at most once per thread object. It arranges for the object\(aqs run() method to be invoked in a separate thread of control. .sp This method will raise a RuntimeError if called more than once on the same thread object. .UNINDENT .INDENT 7.0 .TP .B stop() Signals the thread to stop. .UNINDENT .UNINDENT .SS \fIwatchdog.utils.dirsnapshot\fP .INDENT 0.0 .TP .B module watchdog.utils.dirsnapshot .TP .B synopsis Directory snapshots and comparison. .TP .B author \fI\%yesudeep@google.com\fP (Yesudeep Mangalapilly) .UNINDENT .INDENT 0.0 .INDENT 3.5 .IP "Where are the moved events? They "disappeared"" .sp 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. .UNINDENT .UNINDENT .SS Classes .INDENT 0.0 .TP .B class watchdog.utils.dirsnapshot.DirectorySnapshot(path, recursive=True, walker_callback=>, stat=, listdir=) Bases: \fBobject\fP .sp A snapshot of stat information of files in a directory. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBpath\fP (\fBstr\fP) \-\- The directory path for which a snapshot should be taken. .IP \(bu 2 \fBrecursive\fP (\fBbool\fP) \-\- \fBTrue\fP if the entire directory tree should be included in the snapshot; \fBFalse\fP otherwise. .IP \(bu 2 \fBwalker_callback\fP \-\- .sp Deprecated since version 0.7.2. .IP \(bu 2 \fBstat\fP \-\- .sp Use custom stat function that returns a stat structure for path. Currently only st_dev, st_ino, st_mode and st_mtime are needed. .sp A function with the signature \fBwalker_callback(path, stat_info)\fP which will be called for every entry in the directory tree. .IP \(bu 2 \fBlistdir\fP \-\- Use custom listdir function. See \fBos.listdir\fP for details. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B inode(path) Returns an id for path. .UNINDENT .INDENT 7.0 .TP .B path(id) Returns path for id. None if id is unknown to this snapshot. .UNINDENT .INDENT 7.0 .TP .B paths Set of file/directory paths in the snapshot. .UNINDENT .INDENT 7.0 .TP .B stat_info(path) Returns a stat information object for the specified path from the snapshot. .sp Attached information is subject to change. Do not use unless you specify \fIstat\fP in constructor. Use \fI\%inode()\fP, \fBmtime()\fP, \fBisdir()\fP instead. .INDENT 7.0 .TP .B Parameters \fBpath\fP \-\- The path for which stat information should be obtained from a snapshot. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class watchdog.utils.dirsnapshot.DirectorySnapshotDiff(ref, snapshot) Bases: \fBobject\fP .sp Compares two directory snapshots and creates an object that represents the difference between the two snapshots. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBref\fP (\fI\%DirectorySnapshot\fP) \-\- The reference directory snapshot. .IP \(bu 2 \fBsnapshot\fP (\fI\%DirectorySnapshot\fP) \-\- The directory snapshot which will be compared with the reference snapshot. .UNINDENT .UNINDENT .INDENT 7.0 .TP .B dirs_created List of directories that were created. .UNINDENT .INDENT 7.0 .TP .B dirs_deleted List of directories that were deleted. .UNINDENT .INDENT 7.0 .TP .B dirs_modified List of directories that were modified. .UNINDENT .INDENT 7.0 .TP .B dirs_moved List of directories that were moved. .sp 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. .UNINDENT .INDENT 7.0 .TP .B files_created List of files that were created. .UNINDENT .INDENT 7.0 .TP .B files_deleted List of files that were deleted. .UNINDENT .INDENT 7.0 .TP .B files_modified List of files that were modified. .UNINDENT .INDENT 7.0 .TP .B files_moved List of files that were moved. .sp 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. .UNINDENT .UNINDENT .SH CONTRIBUTING .sp Welcome hacker! So you have got something you would like to see in \fBwatchdog\fP? Whee. This document will help you get started. .SS Important URLs .sp \fBwatchdog\fP uses \fI\%git\fP to track code history and hosts its \fI\%code repository\fP at \fI\%github\fP\&. The \fI\%issue tracker\fP is where you can file bug reports and request features or enhancements to \fBwatchdog\fP\&. .SS Before you start .sp Ensure your system has the following programs and libraries installed before beginning to hack: .INDENT 0.0 .IP 1. 3 \fI\%Python\fP .IP 2. 3 \fI\%git\fP .IP 3. 3 ssh .IP 4. 3 \fI\%XCode\fP (on Mac OS X) .IP 5. 3 \fI\%select_backport\fP (on BSD/Mac OS X if you\(aqre using Python 2.6) .UNINDENT .SS Setting up the Work Environment .sp \fBwatchdog\fP makes extensive use of \fI\%zc.buildout\fP to set up its work environment. You should get familiar with it. .sp Steps to setting up a clean environment: .INDENT 0.0 .IP 1. 3 Fork the \fI\%code repository\fP into your \fI\%github\fP account. Let us call you \fBhackeratti\fP for the sake of this example. Replace \fBhackeratti\fP with your own username below. .IP 2. 3 Clone your fork and setup your environment: .INDENT 3.0 .INDENT 3.5 .sp .nf .ft C $ git clone \-\-recursive git@github.com:hackeratti/watchdog.git $ cd watchdog $ python tools/bootstrap.py \-\-distribute $ bin/buildout .ft P .fi .UNINDENT .UNINDENT .UNINDENT .sp \fBIMPORTANT:\fP .INDENT 0.0 .INDENT 3.5 Re\-run \fBbin/buildout\fP every time you make a change to the \fBbuildout.cfg\fP file. .UNINDENT .UNINDENT .sp That\(aqs it with the setup. Now you\(aqre ready to hack on \fBwatchdog\fP\&. .SS Enabling Continuous Integration .sp The repository checkout contains a script called \fBautobuild.sh\fP which you must run prior to making changes. It will detect changes to Python source code or restructuredText documentation files anywhere in the directory tree and rebuild \fI\%sphinx\fP documentation, run all tests using \fI\%nose\fP, and generate \fI\%coverage\fP reports. .sp Start it by issuing this command in the \fBwatchdog\fP directory checked out earlier: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ tools/autobuild.sh \&... .ft P .fi .UNINDENT .UNINDENT .sp Happy hacking! .sp Found a bug in or want a feature added to \fBwatchdog\fP? You can fork the official \fI\%code repository\fP or file an issue ticket at the \fI\%issue tracker\fP\&. You can also ask questions at the official \fI\%mailing list\fP\&. You may also want to refer to hacking for information about contributing code or documentation to \fBwatchdog\fP\&. .INDENT 0.0 .IP \(bu 2 genindex .IP \(bu 2 modindex .IP \(bu 2 search .UNINDENT .SH AUTHOR Yesudeep Mangalapilly .SH COPYRIGHT 2018, Yesudeep Mangalapilly .\" Generated by docutils manpage writer. .