Ejemplo n.º 1
0
Archivo: io.py Proyecto: stroxler/la
def repack(file):
    """
    Repack archive to remove freespace.

    Parameters
    ----------
    file : h5py File or str
        A h5py File instance of an archive such as h5py.File('/tmp/data.hdf5')
        or a filename.

    Returns
    -------
    file : h5py File or None
        If the input is a h5py.File then a h5py File instance of the
        repacked archive is returned. The input File instance will no longer
        be useable. If the input was a filename, then None is returned.

    """
    f1, opened = _openfile(file)
    filename1 = f1.filename
    filename2 = filename1 + '_repack_tmp_' + randstring(4)
    f2 = h5py.File(filename2)
    for key in f1.keys():
        f1.copy(key, f2)
    f1.close()
    f2.close()
    filename_tmp = filename1 + '_repack_rename_tmp_' + randstring(4)
    os.rename(filename1, filename_tmp)
    os.rename(filename2, filename1)
    if opened:
        f = None
    else:
        f = h5py.File(filename1)
    os.remove(filename_tmp)
    return f
Ejemplo n.º 2
0
def repack(file):
    """
    Repack archive to remove freespace.

    Parameters
    ----------
    file : h5py File or str
        A h5py File instance of an archive such as h5py.File('/tmp/data.hdf5')
        or a filename.

    Returns
    -------
    file : h5py File or None
        If the input is a h5py.File then a h5py File instance of the
        repacked archive is returned. The input File instance will no longer
        be useable. If the input was a filename, then None is returned.

    """
    f1, opened = _openfile(file)
    filename1 = f1.filename
    filename2 = filename1 + '_repack_tmp_' + randstring(4)
    f2 = h5py.File(filename2)
    for key in f1.keys():
        f1.copy(key, f2)
    f1.close()
    f2.close()
    filename_tmp = filename1 + '_repack_rename_tmp_' + randstring(4)
    os.rename(filename1, filename_tmp)
    os.rename(filename2, filename1)
    if opened:
        f = None
    else:
        f = h5py.File(filename1)
    os.remove(filename_tmp)
    return f
Ejemplo n.º 3
0
 def test_randstring_1(self):
     "util.misc.randstring_1"
     rs = randstring(4)
     self.assertTrue(len(rs) == 4, 'Wrong length string.')
Ejemplo n.º 4
0
 def test_randstring_1(self):
     "util.misc.randstring_1"
     rs = randstring(4)
     self.assertTrue(len(rs) == 4, 'Wrong length string.')