def _add_watch_for_path(self, path): 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.remove_ignored_dirs(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 = InotifyFileWatcher._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.remove_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 _add_watch_for_path(self, path): 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.remove_ignored_dirs(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()