def expandGlobStrings(h5N5File, globStrings):
        """Matches a list of globStrings to internal paths of files

        Args:
            h5N5File: h5py or z5py File object, or path(string). If a string is given,
              the file is opened and closed in this method.
            globStrings: string. glob or path strings delimited by os.pathsep

        Returns:
            List of internal paths matching the globstrings that were found in
            the provided h5py.File object
        """
        if not isinstance(h5N5File, (h5py.File, z5py.N5File)):
            with OpStreamingH5N5Reader.get_h5_n5_file(h5N5File, mode="r") as f:
                ret = OpStreamingH5N5SequenceReaderS.expandGlobStrings(
                    f, globStrings)
            return ret

        ret = []
        # Parse list into separate globstrings and combine them
        for globString in globStrings.split(os.path.pathsep):
            s = globString.strip()
            components = PathComponents(s)
            ret += sorted(
                globH5N5(h5N5File, components.internalPath.lstrip("/")))
        return ret
Exemplo n.º 2
0
    def testHdf5Glob(self):
        hdf5File = self.createHdf5Data()

        globString = "here/is/the/data/test-*"

        expectedPaths = ["here/is/the/data/test-{index:02d}".format(index=index) for index in range(5)]

        globbedPaths = globH5N5(hdf5File, globString)
        assert all([a == b for a, b in zip(globbedPaths, expectedPaths)])
Exemplo n.º 3
0
 def globInternalPaths(cls, file_path: str, glob_str: str, cwd: str = None) -> List[str]:
     glob_str = glob_str.lstrip("/")
     internal_paths = set()
     for path in cls.expand_path(file_path, cwd=cwd):
         f = None
         try:
             if cls.pathIsNpz(path):
                 internal_paths |= set(globNpz(path, glob_str))
                 continue
             elif cls.pathIsHdf5(path):
                 f = h5py.File(path, "r")
             elif cls.pathIsN5(path):
                 f = z5py.N5File(path)  # FIXME
             else:
                 raise Exception(f"{path} is not an 'n5' or 'h5' file")
             internal_paths |= set(globH5N5(f, glob_str))
         finally:
             if f is not None:
                 f.close()
     return sorted(internal_paths)
    def expandGlobStrings(h5N5File, globStrings):
        """Matches a list of globStrings to internal paths of files

        Args:
            h5N5File: h5py or z5py File object, or path(string). If a string is given,
              the file is opened and closed in this method.
            globStrings: string. glob or path strings delimited by os.pathsep

        Returns:
            List of internal paths matching the globstrings that were found in
            the provided h5py.File object
        """
        if not isinstance(h5N5File, (h5py.File, z5py.N5File)):
            with OpStreamingH5N5Reader.get_h5_n5_file(h5N5File, mode="r") as f:
                ret = OpStreamingH5N5SequenceReaderS.expandGlobStrings(f, globStrings)
            return ret

        ret = []
        # Parse list into separate globstrings and combine them
        for globString in globStrings.split(os.path.pathsep):
            s = globString.strip()
            components = PathComponents(s)
            ret += sorted(globH5N5(h5N5File, components.internalPath.lstrip("/")))
        return ret