Beispiel #1
0
    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
Beispiel #2
0
def deserialise_bag(serialised):
    obj = obnamlib.deserialise_object(serialised)
    bag = obnamlib.Bag()
    bag.set_id(obj['bag-id'])
    for blob in obj['blobs']:
        bag.append(blob)
    return bag
Beispiel #3
0
    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)

            if blob is None:
                self._data = {
                    'by_chunk_id': {
                    },
                    'by_checksum': {
                        self._checksum_name: {},
                    },
                    'used_by': {
                    },
                }
            else:
                self._data = obnamlib.deserialise_object(blob)
                assert self._data is not None

                keys = self._data['by_checksum'].keys()
                assert len(keys) == 1
                self._checksum_name = keys[0]

            self._data_is_loaded = True
Beispiel #4
0
def deserialise_bag(serialised):
    obj = obnamlib.deserialise_object(serialised)
    bag = obnamlib.Bag()
    bag.set_id(obj['bag-id'])
    for blob in obj['blobs']:
        bag.append(blob)
    return bag
Beispiel #5
0
    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
Beispiel #6
0
 def _get_dir_obj(self, dir_id):
     blob = self._blob_store.get_blob(dir_id)
     if blob is None:  # pragma: no cover
         return None
     as_dict = obnamlib.deserialise_object(blob)
     dir_obj = obnamlib.create_gadirectory_from_dict(as_dict)
     dir_obj.set_immutable()
     return dir_obj
Beispiel #7
0
 def _get_dir_obj(self, dir_id):
     blob = self._blob_store.get_blob(dir_id)
     if blob is None:  # pragma: no cover
         return None
     as_dict = obnamlib.deserialise_object(blob)
     dir_obj = obnamlib.create_gadirectory_from_dict(as_dict)
     dir_obj.set_immutable()
     return dir_obj
Beispiel #8
0
 def _load_per_client_data(self):
     filename = self._get_filename()
     if self._fs.exists(filename):
         blob = self._fs.cat(filename)
         data = obnamlib.deserialise_object(blob)
         self._client_keys.set_from_dict(data['keys'])
         for gen_dict in data['generations']:
             gen = GAGeneration()
             gen.set_from_dict(gen_dict)
             self._generations.append(gen)
Beispiel #9
0
 def _load_data(self):
     if not self._data_is_loaded:
         filename = self._get_filename()
         if self._fs.exists(filename):
             blob = self._fs.cat(filename)
             self._data = obnamlib.deserialise_object(blob)
             assert self._data is not None
         else:
             self._data = {}
         self._data_is_loaded = True
Beispiel #10
0
 def test_handles_more_complicated_object(self):
     obj = {
         'zero': 0,
         'true': True,
         'string': 'abc\0def',
         'list': ['foo'],
         'dict': {
             'one': 0,
         },
     }
     blob = obnamlib.serialise_object(obj)
     self.assertEqual(obnamlib.deserialise_object(blob), obj)
Beispiel #11
0
 def test_handles_more_complicated_object(self):
     obj = {
         'zero': 0,
         'true': True,
         'string': 'abc\0def',
         'list': ['foo'],
         'dict': {
             'one': 0,
         },
     }
     blob = obnamlib.serialise_object(obj)
     self.assertEqual(obnamlib.deserialise_object(blob), obj)
Beispiel #12
0
 def _load_per_client_data(self):
     blob_store = self._get_blob_store()
     blob = blob_store.get_well_known_blob(self._well_known_blob)
     if blob is None:
         self._checksum_algorithm = self._default_checksum_algorithm
     else:
         data = obnamlib.deserialise_object(blob)
         self._checksum_algorithm = data['whole-file-checksum']
         self._client_keys.set_from_dict(data['keys'])
         for gen_dict in data['generations']:
             gen = GAGeneration()
             gen.set_from_dict(gen_dict)
             self._generations.append(gen)
Beispiel #13
0
 def _load_per_client_data(self):
     blob_store = self._get_blob_store()
     blob = blob_store.get_well_known_blob(self._well_known_blob)
     if blob is None:
         self._checksum_algorithm = self._default_checksum_algorithm
     else:
         data = obnamlib.deserialise_object(blob)
         self._checksum_algorithm = data['whole-file-checksum']
         self._client_keys.set_from_dict(data['keys'])
         for gen_dict in data['generations']:
             gen = GAGeneration()
             gen.set_from_dict(gen_dict)
             self._generations.append(gen)
Beispiel #14
0
    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
Beispiel #15
0
 def test_handles_a_boolean_false(self):
     blob = obnamlib.serialise_object(False)
     self.assertEqual(obnamlib.deserialise_object(blob), False)
Beispiel #16
0
 def test_handles_empty_dict(self):
     blob = obnamlib.serialise_object({})
     self.assertEqual(obnamlib.deserialise_object(blob), {})
Beispiel #17
0
 def test_handles_list(self):
     blob = obnamlib.serialise_object([1, 2, 3])
     self.assertEqual(obnamlib.deserialise_object(blob), [1, 2, 3])
Beispiel #18
0
 def test_handles_list(self):
     blob = obnamlib.serialise_object([1, 2, 3])
     self.assertEqual(obnamlib.deserialise_object(blob), [1, 2, 3])
Beispiel #19
0
 def test_handles_dict(self):
     blob = obnamlib.serialise_object({'foo': 'bar'})
     self.assertEqual(obnamlib.deserialise_object(blob), {'foo': 'bar'})
Beispiel #20
0
 def test_handles_empty_string(self):
     blob = obnamlib.serialise_object('')
     self.assertEqual(obnamlib.deserialise_object(blob), '')
Beispiel #21
0
 def test_handles_empty_string(self):
     blob = obnamlib.serialise_object('')
     self.assertEqual(obnamlib.deserialise_object(blob), '')
Beispiel #22
0
 def test_handles_a_boolean_true(self):
     blob = obnamlib.serialise_object(True)
     self.assertEqual(obnamlib.deserialise_object(blob), True)
Beispiel #23
0
 def test_handles_an_int(self):
     blob = obnamlib.serialise_object(42)
     self.assertEqual(obnamlib.deserialise_object(blob), 42)
Beispiel #24
0
 def test_handles_an_int(self):
     blob = obnamlib.serialise_object(42)
     self.assertEqual(obnamlib.deserialise_object(blob), 42)
Beispiel #25
0
 def test_handles_a_boolean_true(self):
     blob = obnamlib.serialise_object(True)
     self.assertEqual(obnamlib.deserialise_object(blob), True)
Beispiel #26
0
 def test_handles_a_boolean_false(self):
     blob = obnamlib.serialise_object(False)
     self.assertEqual(obnamlib.deserialise_object(blob), False)
Beispiel #27
0
 def test_handles_empty_dict(self):
     blob = obnamlib.serialise_object({})
     self.assertEqual(obnamlib.deserialise_object(blob), {})
Beispiel #28
0
 def test_handles_dict(self):
     blob = obnamlib.serialise_object({'foo': 'bar'})
     self.assertEqual(obnamlib.deserialise_object(blob), {'foo': 'bar'})
Beispiel #29
0
 def test_handles_None(self):
     blob = obnamlib.serialise_object(None)
     self.assertEqual(obnamlib.deserialise_object(blob), None)
Beispiel #30
0
 def test_handles_None(self):
     blob = obnamlib.serialise_object(None)
     self.assertEqual(obnamlib.deserialise_object(blob), None)