コード例 #1
0
    def scan(self, path: str, datasets: Mapping[DatasetType,
                                                List[FileDataset]], *,
             log: Log, predicate: Callable[[DataCoordinate], bool]):
        """Process a directory.

        Parameters
        ----------
        path : `str`
            Full path to the directory to be processed.
        datasets : `dict` [`DatasetType`, `list` [`FileDataset`] ]
            Dictionary that found datasets should be added to.
        log : `Log`, optional
            Log to use to report warnings and debug information.
        predicate : `~collections.abc.Callable`
            A callable taking a single `DataCoordinate` argument and returning
            `bool`, indicating whether that (Gen3) data ID represents one
            that should be included in the scan.
        """
        unrecognized = []
        for entry in os.scandir(path):
            if entry.is_file():
                handlers = self._files
            elif entry.is_dir():
                handlers = self._subdirectories
            else:
                continue
            for handler in handlers:
                if handler(entry.path,
                           entry.name,
                           datasets,
                           log=log,
                           predicate=predicate):
                    break
            else:
                unrecognized.append(entry.name)
        if unrecognized:
            log.warn("Skipped unrecognized entries in %s: %s", path,
                     unrecognized)
コード例 #2
0
 def handle(self, path: str, nextDataId2: dict,
            datasets: Mapping[DatasetType, List[FileDataset]], *, log: Log,
            predicate: Callable[[DataCoordinate], bool]):
     # Docstring inherited from ParsedPathElementHandler.
     if self._message is not None:
         log.warn("Skipping %s: %s", path, self._message)