def _generate_filename_to_mtime(self):
     filename_to_mtime = {}
     num_files = 0
     for dirname, dirnames, filenames in os.walk(self._directory,
                                                 followlinks=True):
         watcher_common.skip_ignored_dirs(dirnames)
         filenames = [
             f for f in filenames if not watcher_common.ignore_file(f)
         ]
         for filename in filenames + dirnames:
             if num_files == 10000:
                 warnings.warn(
                     'There are too many files in your application for '
                     'changes in all of them to be monitored. You may have to '
                     'restart the development server to see some changes to your '
                     'files.')
                 return filename_to_mtime
             num_files += 1
             path = os.path.join(dirname, filename)
             try:
                 mtime = os.path.getmtime(path)
             except (IOError, OSError):
                 pass
             else:
                 filename_to_mtime[path] = mtime
     return filename_to_mtime
  def _generate_filename_to_mtime(directory):
    """Records the state of a directory.

    Args:
      directory: the root directory to traverse.

    Returns:
      A dictionary of subdirectories and files under
      directory associated with their timestamps.
      the keys are absolute paths and values are epoch timestamps.
    """
    filename_to_mtime = {}
    num_files = 0
    for dirname, dirnames, filenames in os.walk(directory,
                                                followlinks=True):
      watcher_common.skip_ignored_dirs(dirnames)
      filenames = [f for f in filenames if not watcher_common.ignore_file(f)]
      for filename in filenames + dirnames:
        if num_files == _MAX_MONITORED_FILES:
          warnings.warn(
              'There are too many files in your application for '
              'changes in all of them to be monitored. You may have to '
              'restart the development server to see some changes to your '
              'files.')
          return filename_to_mtime
        num_files += 1
        path = os.path.join(dirname, filename)
        try:
          filename_to_mtime[path] = os.path.getmtime(path)
        except (IOError, OSError):
          pass
    return filename_to_mtime
    def _add_watch_for_path(self, path):
        # Must be called with _inotify_fd_lock held.
        logging.debug('_add_watch_for_path(%r)', path)

        if path not in self._directory_to_rootdir:  # a newly created dir, perhaps
            self._directory_to_rootdir[path] = (
                self._directory_to_rootdir[os.path.dirname(path)])

        # Get the skip-files-re that applies to this subtree, if any.
        rootdir = self._directory_to_rootdir[path]
        skip_files_re = self._skip_files_re.get(rootdir)

        for dirpath, directories, _ in itertools.chain(
            [(os.path.dirname(path), [os.path.basename(path)], None)],
                os.walk(path, topdown=True, followlinks=True)):
            relative_dirpath = os.path.relpath(dirpath, rootdir)
            if relative_dirpath == '.':
                relative_dirpath = ''
            if relative_dirpath != '..':  # never skip the top-level directory
                watcher_common.skip_ignored_dirs(directories, relative_dirpath,
                                                 skip_files_re)
            # TODO: this is not an ideal solution as there are other ways for
            # symlinks to confuse our algorithm but a general solution is going to
            # be very complex and this is good enough to solve the immediate problem
            # with Dart's directory structure.
            watcher_common.skip_local_symlinks(self._real_directories, dirpath,
                                               directories)
            for directory in directories:
                directory_path = os.path.join(dirpath, directory)
                # dirpath cannot be used as the parent directory path because it is the
                # empty string for symlinks :-(
                parent_path = os.path.dirname(directory_path)

                watch_descriptor = _libc.inotify_add_watch(
                    self._inotify_fd,
                    ctypes.create_string_buffer(directory_path),
                    _INTERESTING_INOTIFY_EVENTS)
                if watch_descriptor < 0:
                    if ctypes.get_errno() == errno.ENOSPC:
                        logging.warning(
                            'There are too many directories in your application for '
                            'changes in all of them to be monitored. You may have to '
                            'restart the development server to see some changes to your '
                            'files.')
                        return
                    error = OSError('could not add watch for %r' %
                                    directory_path)
                    error.errno = ctypes.get_errno()
                    error.strerror = errno.errorcode[ctypes.get_errno()]
                    error.filename = directory_path
                    raise error

                if parent_path in self._directory_to_subdirs:
                    self._directory_to_subdirs[parent_path].add(directory_path)
                self._watch_to_directory[watch_descriptor] = directory_path
                self._directory_to_watch_descriptor[
                    directory_path] = watch_descriptor
                self._directory_to_subdirs[directory_path] = set()
                self._directory_to_rootdir[directory_path] = (
                    self._directory_to_rootdir[path])
Example #4
0
    def _generate_filename_to_mtime(directory):
        """Records the state of a directory.

    Args:
      directory: the root directory to traverse.

    Returns:
      A dictionary of subdirectories and files under
      directory associated with their timestamps.
      the keys are absolute paths and values are epoch timestamps.
    """
        filename_to_mtime = {}
        num_files = 0
        for dirname, dirnames, filenames in os.walk(directory,
                                                    followlinks=True):
            watcher_common.skip_ignored_dirs(dirnames)
            filenames = [
                f for f in filenames if not watcher_common.ignore_file(f)
            ]
            for filename in filenames + dirnames:
                if num_files == _MAX_MONITORED_FILES:
                    warnings.warn(
                        'There are too many files in your application for '
                        'changes in all of them to be monitored. You may have to '
                        'restart the development server to see some changes to your '
                        'files.')
                    return filename_to_mtime
                num_files += 1
                path = os.path.join(dirname, filename)
                try:
                    filename_to_mtime[path] = os.path.getmtime(path)
                except (IOError, OSError):
                    pass
        return filename_to_mtime
  def _add_watch_for_path(self, path):
    # Must be called with _inotify_fd_lock held.
    logging.debug('_add_watch_for_path(%r)', path)

    if path not in self._directory_to_rootdir:   # a newly created dir, perhaps
      self._directory_to_rootdir[path] = (
        self._directory_to_rootdir[os.path.dirname(path)])

    # Get the skip-files-re that applies to this subtree, if any.
    rootdir = self._directory_to_rootdir[path]
    skip_files_re = self._skip_files_re.get(rootdir)

    for dirpath, directories, _ in itertools.chain(
        [(os.path.dirname(path), [os.path.basename(path)], None)],
        os.walk(path, topdown=True, followlinks=True)):
      relative_dirpath = os.path.relpath(dirpath, rootdir)
      if relative_dirpath == '.':
        relative_dirpath = ''
      if relative_dirpath != '..':     # never skip the top-level directory
        watcher_common.skip_ignored_dirs(directories, relative_dirpath,
                                         skip_files_re)
      # TODO: this is not an ideal solution as there are other ways for
      # symlinks to confuse our algorithm but a general solution is going to
      # be very complex and this is good enough to solve the immediate problem
      # with Dart's directory structure.
      watcher_common.skip_local_symlinks(
          self._real_directories, dirpath, directories)
      for directory in directories:
        directory_path = os.path.join(dirpath, directory)
        # dirpath cannot be used as the parent directory path because it is the
        # empty string for symlinks :-(
        parent_path = os.path.dirname(directory_path)

        watch_descriptor = _libc.inotify_add_watch(
            self._inotify_fd,
            ctypes.create_string_buffer(directory_path),
            _INTERESTING_INOTIFY_EVENTS)
        if watch_descriptor < 0:
          if ctypes.get_errno() == errno.ENOSPC:
            logging.warning(
                'There are too many directories in your application for '
                'changes in all of them to be monitored. You may have to '
                'restart the development server to see some changes to your '
                'files.')
            return
          error = OSError('could not add watch for %r' % directory_path)
          error.errno = ctypes.get_errno()
          error.strerror = errno.errorcode[ctypes.get_errno()]
          error.filename = directory_path
          raise error

        if parent_path in self._directory_to_subdirs:
          self._directory_to_subdirs[parent_path].add(directory_path)
        self._watch_to_directory[watch_descriptor] = directory_path
        self._directory_to_watch_descriptor[directory_path] = watch_descriptor
        self._directory_to_subdirs[directory_path] = set()
        self._directory_to_rootdir[directory_path] = (
          self._directory_to_rootdir[path])
    def _generate_filename_to_mtime(self):
        """Records the state of a directory.

    Returns:
      A dictionary of subdirectories and files under
      directory associated with their timestamps.
      the keys are absolute paths and values are epoch timestamps.

    Raises:
      ShutdownError: if the quit event has been fired during processing.
    """
        filename_to_mtime = {}
        num_files = 0
        for dirname, dirnames, filenames in os.walk(self._directory,
                                                    followlinks=True):
            if self._quit_event.is_set():
                raise ShutdownError()
            relative_dirpath = os.path.relpath(dirname, self._directory)
            if relative_dirpath == '.':
                relative_dirpath = ''
            if relative_dirpath != '..':  # never skip the top-level directory
                watcher_common.skip_ignored_dirs(dirnames, relative_dirpath,
                                                 self._skip_files_re)
            filenames = [
                f for f in filenames if not watcher_common.ignore_file(
                    os.path.join(relative_dirpath, f), self._skip_files_re)
            ]
            for filename in filenames + dirnames:
                if self._quit_event.is_set():
                    raise ShutdownError()
                if num_files == _MAX_MONITORED_FILES:
                    warnings.warn(
                        'There are too many files in your application for '
                        'changes in all of them to be monitored. You may have to '
                        'restart the development server to see some changes to your '
                        'files.')
                    return filename_to_mtime
                num_files += 1
                path = os.path.join(dirname, filename)
                try:
                    filename_to_mtime[path] = os.path.getmtime(path)
                except (IOError, OSError):
                    pass
        return filename_to_mtime
Example #7
0
    def _generate_filename_to_mtime(self):
        """Records the state of a directory.

    Returns:
      A dictionary of subdirectories and files under
      directory associated with their timestamps.
      the keys are absolute paths and values are epoch timestamps.

    Raises:
      ShutdownError: if the quit event has been fired during processing.
    """
        filename_to_mtime = {}
        num_files = 0
        for dirname, dirnames, filenames in os.walk(self._directory, followlinks=True):
            if self._quit_event.is_set():
                raise ShutdownError()
            relative_dirpath = os.path.relpath(dirname, self._directory)
            if relative_dirpath == ".":
                relative_dirpath = ""
            if relative_dirpath != "..":  # never skip the top-level directory
                watcher_common.skip_ignored_dirs(dirnames, relative_dirpath, self._skip_files_re)
            filenames = [
                f
                for f in filenames
                if not watcher_common.ignore_file(os.path.join(relative_dirpath, f), self._skip_files_re)
            ]
            for filename in filenames + dirnames:
                if self._quit_event.is_set():
                    raise ShutdownError()
                if num_files == _MAX_MONITORED_FILES:
                    warnings.warn(
                        "There are too many files in your application for "
                        "changes in all of them to be monitored. You may have to "
                        "restart the development server to see some changes to your "
                        "files."
                    )
                    return filename_to_mtime
                num_files += 1
                path = os.path.join(dirname, filename)
                try:
                    filename_to_mtime[path] = os.path.getmtime(path)
                except (IOError, OSError):
                    pass
        return filename_to_mtime
    def _add_watch_for_path(self, path):
        # Must be called with _inotify_fd_lock held.
        logging.debug("_add_watch_for_path(%r)", path)

        for dirpath, directories, _ in itertools.chain(
            [(os.path.dirname(path), [os.path.basename(path)], None)], os.walk(path, topdown=True, followlinks=True)
        ):
            watcher_common.skip_ignored_dirs(directories)
            # TODO: this is not an ideal solution as there are other ways for
            # symlinks to confuse our algorithm but a general solution is going to
            # be very complex and this is good enough to solve the immediate problem
            # with Dart's directory structure.
            watcher_common.skip_local_symlinks(self._real_directories, dirpath, directories)
            for directory in directories:
                directory_path = os.path.join(dirpath, directory)
                # dirpath cannot be used as the parent directory path because it is the
                # empty string for symlinks :-(
                parent_path = os.path.dirname(directory_path)

                watch_descriptor = _libc.inotify_add_watch(
                    self._inotify_fd, ctypes.create_string_buffer(directory_path), _INTERESTING_INOTIFY_EVENTS
                )
                if watch_descriptor < 0:
                    if ctypes.get_errno() == errno.ENOSPC:
                        logging.warning(
                            "There are too many directories in your application for "
                            "changes in all of them to be monitored. You may have to "
                            "restart the development server to see some changes to your "
                            "files."
                        )
                        return
                    error = OSError("could not add watch for %r" % directory_path)
                    error.errno = ctypes.get_errno()
                    error.strerror = errno.errorcode[ctypes.get_errno()]
                    error.filename = directory_path
                    raise error

                if parent_path in self._directory_to_subdirs:
                    self._directory_to_subdirs[parent_path].add(directory_path)
                self._watch_to_directory[watch_descriptor] = directory_path
                self._directory_to_watch_descriptor[directory_path] = watch_descriptor
                self._directory_to_subdirs[directory_path] = set()
 def _generate_filename_to_mtime(self):
   filename_to_mtime = {}
   num_files = 0
   for dirname, dirnames, filenames in os.walk(self._directory,
                                               followlinks=True):
     watcher_common.skip_ignored_dirs(dirnames)
     filenames = [f for f in filenames if not watcher_common.ignore_file(f)]
     for filename in filenames + dirnames:
       if num_files == 10000:
         warnings.warn(
             'There are too many files in your application for '
             'changes in all of them to be monitored. You may have to '
             'restart the development server to see some changes to your '
             'files.')
         return filename_to_mtime
       num_files += 1
       path = os.path.join(dirname, filename)
       try:
         mtime = os.path.getmtime(path)
       except (IOError, OSError):
         pass
       else:
         filename_to_mtime[path] = mtime
   return filename_to_mtime