def test_write(self): """Test writing to metadata file, then reading back contents""" global tempdir temprp = tempdir.append( "mirror_metadata.2005-11-03T12:51:06-06:00.snapshot.gz") if temprp.lstat(): temprp.delete() self.make_temp() rootrp = rpath.RPath(Globals.local_connection, os.path.join(old_test_dir, b"various_file_types")) # the following 3 lines make sure that we ignore incorrect files sel = selection.Select(rootrp) sel.parse_selection_args((), ()) rps = list(sel.set_iter()) assert not temprp.lstat() write_mf = MetadataFile(temprp, 'w') for rp in rps: write_mf.write_object(rp) write_mf.close() assert temprp.lstat() reread_rps = list(MetadataFile(temprp, 'r').get_objects()) assert len(reread_rps) == len(rps), (len(reread_rps), len(rps)) for i in range(len(reread_rps)): assert reread_rps[i] == rps[i], i
def write_metadata_to_temp(self): """If necessary, write metadata of bigdir to file metadata.gz""" global tempdir temprp = tempdir.append( "mirror_metadata.2005-11-03T14:51:06-06:00.snapshot.gz") if temprp.lstat(): return temprp self.make_temp() rootrp = rpath.RPath(Globals.local_connection, os.path.join(old_test_dir, b"bigdir")) rpath_iter = selection.Select(rootrp).set_iter() start_time = time.time() mf = MetadataFile(temprp, 'w') for rp in rpath_iter: mf.write_object(rp) mf.close() print("Writing metadata took %s seconds" % (time.time() - start_time)) return temprp