From 018da105ef2c10497a982650edd0621dd685a8f9 Mon Sep 17 00:00:00 2001 From: alejopm03 Date: Mon, 4 Mar 2024 23:27:29 -0300 Subject: [PATCH] feat(module): added method to create repeated modules --- can.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/can.py b/can.py index 9f9a28f..7db4830 100755 --- a/can.py +++ b/can.py @@ -279,6 +279,32 @@ def add_module(self, module): f"conflict between module {m['name']} and {module.get()['name']}") self.modules.append(module.get()) + + def add_multiple_modules(self, module: Module, quantity: int) -> None: + ''' + Add multiple modules based on a template module and a quantity + ''' + for i in range(quantity): + # Create topics + topics = [] + for topic in module.get()["topics"]: + new_topic = Can.Topic.from_dict(topic) + # Update topic id + new_topic.id = topic["id"] + i + topics.append(new_topic) + + # Create module + new_module = Can.Module( + name=module.get()["name"] + "_" + str(i + 1), + signature=module.get()["signature"] + i, + description=module.get()["description"] + " " + str(i + 1) + ) + # Add topics to module + for topic in topics: + new_module.add_topic(topic) + + # Add module to database + self.add_module(new_module) def import_json(self, filename: str): with open(filename, 'r') as file: