def test_globStringValidity(self):
        """Check whether globStrings are correctly verified"""
        testGlobString = '/tmp/test.h5'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError):
            OpStreamingHdf5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = '/tmp/test.h5/a' + os.pathsep + '/tmp/test2.h5/a'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError):
            OpStreamingHdf5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = '/tmp/test*.h5/a' + os.pathsep + '/tmp/test*.h5/a'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            OpStreamingHdf5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = '/tmp/test.jpg/*'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderS.WrongFileTypeError):
            OpStreamingHdf5SequenceReaderS.checkGlobString(testGlobString)

        validGlobStrings = [
            '/tmp/test.h5/*',
            '/tmp/test.h5/data1' + os.pathsep + '/tmp/test.h5/data2',
            '/tmp/test.h5/data*'
        ]

        # Implicit test for validity; test fails if an exception is raised
        for testGlobString in validGlobStrings:
            OpStreamingHdf5SequenceReaderS.checkGlobString(testGlobString)

        self.assertTrue(True)
Пример #2
0
    def _applyPattern(self):
        globStrings = encode_from_qstring(self.patternEdit.text())
        H5EXTS = OpStreamingHdf5SequenceReaderM.H5EXTS
        filenames = []
        # see if some glob strings include HDF5 files
        globStrings = globStrings.split(os.path.pathsep)
        pcs = [PathComponents(x) for x in globStrings]
        ish5 = [x.extension in H5EXTS for x in pcs]

        h5GlobStrings = os.path.pathsep.join(
            [x for x, y in zip(globStrings, ish5) if y is True])
        globStrings = os.path.pathsep.join(
            [x for x, y in zip(globStrings, ish5) if y is False])

        filenames.extend(OpStackLoader.expandGlobStrings(globStrings))

        try:
            OpStreamingHdf5SequenceReaderS.checkGlobString(h5GlobStrings)
            # OK, if nothing raised there is a single h5 file in h5GlobStrings:
            pathComponents = PathComponents(
                h5GlobStrings.split(os.path.pathsep)[0])
            h5file = h5py.File(pathComponents.externalPath, mode='r')
            filenames.extend(
                "{}/{}".format(pathComponents.externalPath, internal)
                for internal in OpStreamingHdf5SequenceReaderS.
                expandGlobStrings(h5file, h5GlobStrings))
        except (OpStreamingHdf5SequenceReaderS.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError,
                OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            pass

        try:
            OpStreamingHdf5SequenceReaderM.checkGlobString(h5GlobStrings)
            filenames.extend(
                "{}/{}".format(external, internal)
                for external, internal in zip(
                    *OpStreamingHdf5SequenceReaderM.expandGlobStrings(
                        h5GlobStrings)))
        except (OpStreamingHdf5SequenceReaderM.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderM.SameFileError,
                OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            pass

        self._updateFileList(filenames)
    def _applyPattern(self):
        globStrings = self.patternEdit.text()
        H5EXTS = OpStreamingHdf5SequenceReaderM.H5EXTS
        filenames = []
        # see if some glob strings include HDF5 files
        globStrings = globStrings.split(os.path.pathsep)
        pcs = [PathComponents(x) for x in globStrings]
        ish5 = [x.extension in H5EXTS for x in pcs]

        h5GlobStrings = os.path.pathsep.join([x for x, y in zip(globStrings, ish5) if y is True])
        globStrings = os.path.pathsep.join([x for x, y in zip(globStrings, ish5) if y is False])

        filenames.extend(OpStackLoader.expandGlobStrings(globStrings))

        try:
            OpStreamingHdf5SequenceReaderS.checkGlobString(h5GlobStrings)
            # OK, if nothing raised there is a single h5 file in h5GlobStrings:
            pathComponents = PathComponents(h5GlobStrings.split(os.path.pathsep)[0])
            h5file = h5py.File(pathComponents.externalPath, mode='r')
            filenames.extend(
                "{}/{}".format(pathComponents.externalPath, internal)
                for internal in OpStreamingHdf5SequenceReaderS.expandGlobStrings(h5file, h5GlobStrings))
        except (
                OpStreamingHdf5SequenceReaderS.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError,
                OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            pass

        try:
            OpStreamingHdf5SequenceReaderM.checkGlobString(h5GlobStrings)
            filenames.extend(
                "{}/{}".format(external, internal)
                for external, internal
                in zip(*OpStreamingHdf5SequenceReaderM.expandGlobStrings(h5GlobStrings))
            )
        except (
                OpStreamingHdf5SequenceReaderM.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderM.SameFileError,
                OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            pass

        self._updateFileList(filenames)
Пример #4
0
    def _attemptOpenAsHdf5Stack(self, filePath):
        if not ('*' in filePath or os.path.pathsep in filePath):
            return ([], None)

        # Now use the .checkGlobString method of the stack readers
        isSingleFile = True
        try:
            OpStreamingHdf5SequenceReaderS.checkGlobString(filePath)
        except OpStreamingHdf5SequenceReaderS.WrongFileTypeError:
            return ([], None)
        except (OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError,
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            isSingleFile = False

        isMultiFile = True
        try:
            OpStreamingHdf5SequenceReaderM.checkGlobString(filePath)
        except (OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingHdf5SequenceReaderM.SameFileError,
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            isMultiFile = False

        assert (not (isMultiFile and isSingleFile))

        if isSingleFile is True:
            opReader = OpStreamingHdf5SequenceReaderS(parent=self)
        elif isMultiFile is True:
            opReader = OpStreamingHdf5SequenceReaderM(parent=self)

        try:
            opReader.SequenceAxis.connect(self.SequenceAxis)
            opReader.GlobString.setValue(filePath)
            return ([opReader], opReader.OutputImage)
        except (OpStreamingHdf5SequenceReaderM.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderS.WrongFileTypeError):
            return ([], None)
        else:
            return ([], None)