Skip to content
Snippets Groups Projects
Commit cfc7d277 authored by Jammer, Tim's avatar Jammer, Tim
Browse files

Replace instructions by giving instructions

parent 2236f39c
No related branches found
No related tags found
1 merge request!14Infrastructure: Remove Instructionblock
...@@ -252,14 +252,16 @@ class TemplateManager: ...@@ -252,14 +252,16 @@ class TemplateManager:
raise ValueError("Neither Both block name nor index is given") 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): if isinstance(ident, str):
return [idx for idx, inst in enumerate(self._instructions) if inst.get_identifier() == ident] return [idx for idx, inst in enumerate(self._instructions) if inst.get_identifier() == ident]
if isinstance(ident, Instruction): if isinstance(ident, Instruction):
return [idx for idx, inst in enumerate(self._instructions) if inst == ident] 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") raise ValueError("Provide string or instruction")
def insert_instruction(self, new_instruction: Instruction, after_instruction: Instruction | str | int = None, def insert_instruction(self, new_instruction: Instruction, after_instruction: Instruction | str | int = None,
...@@ -365,10 +367,6 @@ class TemplateManager: ...@@ -365,10 +367,6 @@ class TemplateManager:
else: else:
new_instruction_list = new_instruction new_instruction_list = new_instruction
if old_instruction is not None:
raise EnvironmentError("NOT IMPLEMENTED")
# TODO implement
idxs_to_replace = [] idxs_to_replace = []
if idx is not None: if idx is not None:
if isinstance(idx, int): if isinstance(idx, int):
...@@ -378,6 +376,11 @@ class TemplateManager: ...@@ -378,6 +376,11 @@ class TemplateManager:
if identifier is not None: if identifier is not None:
idxs_to_replace = self.__get_instruction_index(identifier) 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): if len(idxs_to_replace) == len(new_instruction_list):
raise ValueError("Number of instructions to Replace does not match number of given instructions") raise ValueError("Number of instructions to Replace does not match number of given instructions")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment