diff --git a/scripts/Infrastructure/Template.py b/scripts/Infrastructure/Template.py index 32c17bca3c9fe4583939a3d3d105f4be8ba2cbd2..a279c5d27fdb7812444334b3f6a873dd2b9707c0 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")