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)
Ejemplo n.º 2
0
 def setUp(self):
     self._directory = tempfile.mkdtemp()  # The watched directory
     self._junk_directory = tempfile.mkdtemp()  # A scrap directory.
     self._watcher = mtime_file_watcher.MtimeFileWatcher(self._directory)
     self._watcher._watcher_thread = FakeThread()
     logging.debug('watched directory=%r, junk directory=%r',
                   self._directory, self._junk_directory)
Ejemplo n.º 3
0
 def setUp(self):
     self._directory = tempfile.mkdtemp()  # The watched directory
     self._junk_directory = tempfile.mkdtemp()  # A scrap directory.
     self._watcher = mtime_file_watcher.MtimeFileWatcher(self._directory)