Example #1
0
    def _update_version6(self, filepath):
        logging.debug('Updating from "version 6"')

        hdf5file = h5py.File(filepath, 'r+')

        hdf5file.attrs['version'] = b'7' # Change version
        hdf5file.attrs['_class'] = b'Results'

        # Update root options
        options_source = _update_options(hdf5file.attrs['options'])
        hdf5file.attrs['options'] = options_source

        # Create identifier of results
        identifier = Options.read(BytesIO(options_source)).uuid
        hdf5file.attrs.create('identifiers', [identifier],
                              dtype=h5py.special_dtype(vlen=str))

        result_groups = list(hdf5file)
        group = hdf5file.create_group('result-' + identifier)
        group.attrs['options'] = options_source

        for result_group in result_groups:
            hdf5file[result_group].attrs['_class'] = \
                np.string_(hdf5file[result_group].attrs['_class'])
            hdf5file.copy(result_group, group)
            del hdf5file[result_group]

        hdf5file.close()

        return self._update_version7(filepath)
Example #2
0
def _load(filepaths, list_options=None):
    for filepath in filepaths:
        if os.path.isdir(filepath):
            _load(glob.glob(os.path.join(filepath, '*.xml')), list_options)
            list_options.sort()
            return

        list_options.append(Options.read(filepath))
Example #3
0
def _load(filepaths, list_options=None):
    for filepath in filepaths:
        if os.path.isdir(filepath):
            _load(glob.glob(os.path.join(filepath, '*.xml')), list_options)
            list_options.sort()
            return

        list_options.append(Options.read(filepath))
Example #4
0
    def _update_version2(self, filepath):
        logging.debug('Updating from "version 2"')

        # Find options
        xmlfilepath = os.path.splitext(filepath)[0] + '.xml'
        if not os.path.exists(xmlfilepath):
            raise ValueError('Update requires an options file saved at %s' % xmlfilepath)
        with open(xmlfilepath, 'rb') as fp:
            source = fp.read()
        source = _update_options(source)
        options = Options.read(BytesIO(source))

        oldzip = ZipFile(filepath, 'r')
        newzip = ZipFile(filepath + ".new", 'w')

        # Add options file
        fp = BytesIO()
        options.write(fp)
        newzip.writestr(OPTIONS_FILENAME, fp.getvalue())

        # Add other files to new zip
        for zipinfo in oldzip.infolist():
            data = oldzip.read(zipinfo)
            newzip.writestr(zipinfo, data)

        # Add version
        newzip.comment = b'version=3'

        oldzip.close()
        newzip.close()

        # Remove old zip and replace with new one
        os.remove(filepath)
        os.rename(filepath + ".new", filepath)

        return self._update_version3(filepath)
Example #5
0
 def _validate(self, filepath):
     Options.read(filepath)