def _load_data(self): if not self._data_is_loaded: bag_store = obnamlib.BagStore() bag_store.set_location(self._fs, self.get_dirname()) blob_store = obnamlib.BlobStore() blob_store.set_bag_store(bag_store) blob = blob_store.get_well_known_blob(self._well_known_blob) leaf_store = obnamlib.LeafStore() leaf_store.set_blob_store(blob_store) if blob is None: self._by_chunk_id_tree = self._empty_cowtree(leaf_store) self._by_checksum_tree = self._empty_cowtree(leaf_store) self._used_by_tree = self._empty_cowtree(leaf_store) else: data = obnamlib.deserialise_object(blob) self._checksum_name = data['checksum_algorithm'] self._by_chunk_id_tree = self._load_cowtree( leaf_store, data['by_chunk_id']) self._by_checksum_tree = self._load_cowtree( leaf_store, data['by_checksum']) self._used_by_tree = self._load_cowtree( leaf_store, data['used_by']) self._data_is_loaded = True
def setUp(self): self.tempdir = tempfile.mkdtemp() self.fs = obnamlib.LocalFS(self.tempdir) self.store = obnamlib.BagStore() self.store.set_location(self.fs, '.') self.bag = obnamlib.Bag() bag_id = self.store.reserve_bag_id() self.bag.set_id(bag_id)
def _save_data(self): assert self._data is not None blob = obnamlib.serialise_object(self._data) bag_store = obnamlib.BagStore() bag_store.set_location(self._fs, self.get_dirname()) blob_store = obnamlib.BlobStore() blob_store.set_bag_store(bag_store) blob_store.put_well_known_blob(self._well_known_blob, blob)
def set_fs(self, fs): self._fs = fs self._bag_store = obnamlib.BagStore() self._bag_store.set_location(fs, self._dirname) self._blob_store = obnamlib.BlobStore() self._blob_store.set_bag_store(self._bag_store) self._blob_store.set_max_cache_bytes(self._chunk_cache_size) if self._max_chunk_size is not None: self._blob_store.set_max_bag_size(self._max_chunk_size)
def _get_blob_store(self): if self._blob_store is None: bag_store = obnamlib.BagStore() bag_store.set_location(self._fs, self._dirname) self._blob_store = obnamlib.BlobStore() self._blob_store.set_bag_store(bag_store) self._blob_store.set_max_bag_size(self._dir_bag_size) self._blob_store.set_max_cache_bytes(self._dir_cache_size) return self._blob_store
def _save_data(self): root = { 'checksum_algorithm': self._checksum_name, 'by_chunk_id': self._by_chunk_id_tree.commit(), 'by_checksum': self._by_checksum_tree.commit(), 'used_by': self._used_by_tree.commit(), } blob = obnamlib.serialise_object(root) bag_store = obnamlib.BagStore() bag_store.set_location(self._fs, self.get_dirname()) blob_store = obnamlib.BlobStore() blob_store.set_bag_store(bag_store) blob_store.put_well_known_blob(self._well_known_blob, blob)
def _load_data(self): if self._data_is_loaded: assert self._data is not None else: assert self._data is None if not self._data_is_loaded: bag_store = obnamlib.BagStore() bag_store.set_location(self._fs, self.get_dirname()) blob_store = obnamlib.BlobStore() blob_store.set_bag_store(bag_store) blob = blob_store.get_well_known_blob(self._well_known_blob) if blob is None: self._data = { 'clients': {}, } else: self._data = obnamlib.deserialise_object(blob) assert self._data is not None self._data_is_loaded = True
def test_has_no_bags_initially(self): store = obnamlib.BagStore() store.set_location(self.fs, 'empty') self.assertEqual(list(store.get_bag_ids()), [])