rtCommon.fileWatcher

FileWatcher implements a class that watches for files to be created in a directory and then returns the notification that the files is now available.

The FileWatcher class is a virtual class of sorts with two underlying implementations, one for Mac and Windows (WatchdogFileWatcher) and one for Linux (InotifyFileWatcher).

Module Contents

Classes

FileWatcher

Virtual class to watch for the arrival of new files and notify.

WatchdogFileWatcher

Version of FileWatcher for Mac and Windows using Watchdog toolkit.

FileNotifyHandler

Handler class that will receive the watchdog notifications. It will queue the notifications

InotifyFileWatcher

Version of FileWatcher for Linux using Inotify interface.

class rtCommon.fileWatcher.FileWatcher

Virtual class to watch for the arrival of new files and notify.

__del__()
initFileNotifier(dir, filePattern, minFileSize, demoStep=0)
waitForFile(filename, timeout=0, timeCheckIncrement=1)
class rtCommon.fileWatcher.WatchdogFileWatcher

Version of FileWatcher for Mac and Windows using Watchdog toolkit.

__del__()
initFileNotifier(dir: str, filePattern: str, minFileSize: int, demoStep: int = 0) None

Initialize the file watcher to watch in the specified directory for the specified regex-based filepattern.

Parameters
  • dir (str) – Directory to watch in

  • filePattern (str) – Regex-based filepattern to watch for

  • minFileSize (int) – Minimum file size necessary to consider the file is wholely written. Below this size the filewatcher will assume file is paritally written and continue to wait.

  • demoStep (int) – If non-zero then it will space out file notifications by demoStep seconds. This is used when the image files are pre-existing but we want to simulate as if the arrive from the scanner every few seconds (demoStep seconds).

waitForFile(filename: str, timeout: int = 0, timeCheckIncrement: int = 1) Optional[str]

Wait for a specific filename to be created in the directory specified in initFileNotifier.

Parameters
  • filename – Name of File to watch for creation of. If filename includes a path it must match that specified in initFileNotifier.

  • timeout – Max number of seconds to watch for the file creation. If timeout expires before the file is created then None will be returned

  • timeCheckIncrement – Time interval (secs) to check if file exists in case file creation events are somehow missed.

Returns

The filename of the created file (same as input arg) or None if timeout expires

class rtCommon.fileWatcher.FileNotifyHandler(q, patterns)

Bases: watchdog.events.PatternMatchingEventHandler

Handler class that will receive the watchdog notifications. It will queue the notifications int the queue provided during to the init function.

on_created(event)
on_modified(event)
class rtCommon.fileWatcher.InotifyFileWatcher

Version of FileWatcher for Linux using Inotify interface.

__del__()
initFileNotifier(dir: str, filePattern: str, minFileSize: int, demoStep: int = 0) None

Initialize the file watcher to watch for files in the specified directory. Note: inotify doesn’t use filepatterns

Parameters
  • dir (str) – Directory to watch in

  • filePattern (str) – ignored by inotify implementation

  • minFileSize (int) – Minimum file size necessary to consider the file is wholely written. Below this size the filewatcher will assume file is paritally written and continue to wait.

  • demoStep (int) – If non-zero then it will space out file notifications by demoStep seconds. This is used when the image files are pre-existing but we want to simulate as if the arrive from the scanner every few seconds (demoStep seconds).

waitForFile(filename: str, timeout: int = 0, timeCheckIncrement: int = 1) Optional[str]

Wait for a specific filename to be created in the directory specified in initFileNotifier.

Parameters
  • filename – Name of File to watch for creation of. If filename includes a path it must match that specified in initFileNotifier.

  • timeout – Max number of seconds to watch for the file creation. If timeout expires before the file is created then None will be returned

  • timeCheckIncrement – Time interval (secs) to check if file exists in case file creation events are somehow missed.

Returns

The filename of the created file (same as input arg) or None if timeout expires

notifyEventLoop()

Thread function which gets notifications and queues them in the fileNotifyQ