Skip to content

Commit

Permalink
feat(module): added method to create repeated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejoPm03 committed Mar 5, 2024
1 parent ec16b00 commit 27b5b1a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions can.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 27b5b1a

Please sign in to comment.