def setUp(self): self._directory = tempfile.mkdtemp() # The watched directory self._junk_directory = tempfile.mkdtemp() # A scrap directory. self._watcher = inotify_file_watcher.InotifyFileWatcher( [self._directory]) logging.debug('watched directory=%r, junk directory=%r', self._directory, self._junk_directory)
def get_file_watcher(directories, use_mtime_file_watcher): """Returns an instance that monitors a hierarchy of directories. Args: directories: A list representing the paths of the directories to monitor. use_mtime_file_watcher: A bool containing whether to use mtime polling to monitor file changes even if other options are available on the current platform. Returns: A FileWatcher appropriate for the current platform. start() must be called before has_changes(). """ assert not isinstance(directories, types.StringTypes), 'expected list got str' if len(directories) != 1: return _MultipleFileWatcher(directories, use_mtime_file_watcher) directory = directories[0] if use_mtime_file_watcher: return mtime_file_watcher.MtimeFileWatcher(directory) elif sys.platform.startswith('linux'): return inotify_file_watcher.InotifyFileWatcher(directory) elif sys.platform.startswith('win'): return win32_file_watcher.Win32FileWatcher(directory) return mtime_file_watcher.MtimeFileWatcher(directory)
def setUp(self): self._directories = [tempfile.mkdtemp() for _ in range(4)] self._watcher = inotify_file_watcher.InotifyFileWatcher(self._directories) self._watcher.start()