From cfc7d27750f90e51e13bba612fad1a99bdf06d31 Mon Sep 17 00:00:00 2001 From: Tim Jammer <tim.jammer@tu-darmstadt.de> Date: Thu, 8 Feb 2024 15:02:20 +0100 Subject: [PATCH] Replace instructions by giving instructions --- scripts/Infrastructure/Template.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/Infrastructure/Template.py b/scripts/Infrastructure/Template.py index 32c17bca3..a279c5d27 100644 --- a/scripts/Infrastructure/Template.py +++ b/scripts/Infrastructure/Template.py @@ -252,14 +252,16 @@ class TemplateManager: raise ValueError("Neither Both block name nor index is given") - def __get_instruction_index(self, ident: str | Instruction) -> typing.List[int]: + def __get_instruction_index(self, ident: str | Instruction | typing.List[Instruction]) -> typing.List[int]: """ - internal helper function to receive the indices of instructions with ghe given identifier oris the given isntruction + internal helper function to receive the indices of instructions with ghe given identifier oris the given instruction """ if isinstance(ident, str): return [idx for idx, inst in enumerate(self._instructions) if inst.get_identifier() == ident] if isinstance(ident, Instruction): return [idx for idx, inst in enumerate(self._instructions) if inst == ident] + if isinstance(ident, list): + return [idx for idx, inst in enumerate(self._instructions) if inst in ident] raise ValueError("Provide string or instruction") def insert_instruction(self, new_instruction: Instruction, after_instruction: Instruction | str | int = None, @@ -365,10 +367,6 @@ class TemplateManager: else: new_instruction_list = new_instruction - if old_instruction is not None: - raise EnvironmentError("NOT IMPLEMENTED") - # TODO implement - idxs_to_replace = [] if idx is not None: if isinstance(idx, int): @@ -378,6 +376,11 @@ class TemplateManager: if identifier is not None: idxs_to_replace = self.__get_instruction_index(identifier) + if old_instruction is not None: + if isinstance(old_instruction, Instruction): + old_instruction = [old_instruction] + idxs_to_replace = self.__get_instruction_index(old_instruction) + if len(idxs_to_replace) == len(new_instruction_list): raise ValueError("Number of instructions to Replace does not match number of given instructions") -- GitLab