Exemple #1
0
    def remove_generation(self, gen_number):
        self._load_data()
        remaining = []
        removed = False

        for generation in self._generations:
            if generation.get_number() == gen_number:
                removed = True
            else:
                remaining.append(generation)

        if not removed:
            raise obnamlib.RepositoryGenerationDoesNotExist(
                client_name=self._client_name, gen_id=gen_number)

        import cliapp
        dumper = cliapp.MemoryProfileDumper({
            'dump-memory-profile': True,
            'memory-dump-interval': 0,
        })
        self._dumper = dumper

        chunks_to_remove = set(self._generate_generation_chunk_ids(gen_number))
        dumper.dump_memory_profile('after getting chunks in removed gen')

        for chunk_id in self._generate_chunk_ids_in_generations(remaining):
            if chunk_id in chunks_to_remove:
                chunks_to_remove.remove(chunk_id)
                if len(chunks_to_remove) == 0:
                    break
        dumper.dump_memory_profile('after computing chunk uniq to removed gen')

        self._generations.set_generations(remaining)

        return list(chunks_to_remove)
Exemple #2
0
 def _lookup_generation_by_gen_number(self, gen_number):
     if 'generations' in self._data:
         generations = self._data['generations']
         for generation in generations:
             if generation['id'] == gen_number:
                 return generation
     raise obnamlib.RepositoryGenerationDoesNotExist(
         gen_id=gen_number, client_name=self._client_name)
Exemple #3
0
    def _require_existing_file(self, generation_id, filename):
        client_name, _ = self._unpack_gen_id(generation_id)

        if generation_id not in self.get_client_generation_ids(client_name):
            raise obnamlib.RepositoryGenerationDoesNotExist(
                client_name=client_name, gen_id=generation_id)

        if not self.file_exists(generation_id, filename):
            raise obnamlib.RepositoryFileDoesNotExistInGeneration(
                client_name=client_name,
                genspec=self.make_generation_spec(generation_id),
                filename=filename)
Exemple #4
0
 def interpret_generation_spec(self, client_name, genspec):
     ids = self.get_client_generation_ids(client_name)
     if not ids:
         raise obnamlib.RepositoryClientHasNoGenerations(
             client_name=client_name)
     if genspec == 'latest':
         return ids[-1]
     for gen_id in ids:
         if self.make_generation_spec(gen_id) == genspec:
             return gen_id
     raise obnamlib.RepositoryGenerationDoesNotExist(
         client_name=client_name, gen_id=genspec)
Exemple #5
0
 def interpret_generation_spec(self, genspec):
     ids = self.data.get_value('generation-ids', [])
     if not ids:
         raise obnamlib.RepositoryClientHasNoGenerations(
             client_name=self.name)
     if genspec == 'latest':
         if ids:
             return ids[-1]
     else:
         gen_number = int(genspec)
         if (self.name, gen_number) in ids:
             return (self.name, gen_number)
     raise obnamlib.RepositoryGenerationDoesNotExist(client_name=self.name,
                                                     gen_id=genspec)
Exemple #6
0
    def remove_generation(self, gen_number):
        self._require_lock()
        generations = self._data.get('generations', [])
        remaining = []
        removed = False

        for generation in generations:
            if generation['id'] == gen_number:
                removed = True
            else:
                remaining.append(generation)

        if not removed:
            raise obnamlib.RepositoryGenerationDoesNotExist(
                client_name=self._client_name, gen_id=gen_number)

        self._data['generations'] = remaining
Exemple #7
0
 def _require_existing_generation(self, generation_id):
     client_name, _ = self._unpack_gen_id(generation_id)
     if generation_id not in self.get_client_generation_ids(client_name):
         raise obnamlib.RepositoryGenerationDoesNotExist(
             client_name=client_name, gen_id=generation_id)
Exemple #8
0
 def _require_generation(self, gen_id):
     ids = self.data.get_value('generation-ids', [])
     if gen_id not in ids:
         raise obnamlib.RepositoryGenerationDoesNotExist(
             client_name=self.name, gen_id=gen_id)
Exemple #9
0
 def _lookup_generation_by_gen_number(self, gen_number):
     generation = self._generations.get_generation(gen_number)
     if generation is None:
         raise obnamlib.RepositoryGenerationDoesNotExist(
             gen_id=gen_number, client_name=self._client_name)
     return generation