From 565f5e8f8de4a43b26673846707f014dc08f5d6d Mon Sep 17 00:00:00 2001 From: Mohamed El Mouctar HAIDARA Date: Wed, 22 Sep 2021 19:31:54 +0200 Subject: [PATCH] fix: Add label prefix to TaskNode and RoleNode --- ansibleplaybookgrapher/graph.py | 20 ++++++++++++++++---- ansibleplaybookgrapher/parser.py | 7 ++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ansibleplaybookgrapher/graph.py b/ansibleplaybookgrapher/graph.py index a78e322..fa7455e 100644 --- a/ansibleplaybookgrapher/graph.py +++ b/ansibleplaybookgrapher/graph.py @@ -185,8 +185,14 @@ class TaskNode(Node): A task node. Can be pre_task, task or post_task """ - def __init__(self, node_label: str, node_id: str = None): - super().__init__(node_label, node_id or generate_id("task_")) + def __init__(self, node_label: str, node_id: str = None, label_prefix: str = "[task] "): + """ + + :param node_label: + :param node_id: + :param label_prefix: Prefix for the label + """ + super().__init__(label_prefix + node_label, node_id or generate_id("task_")) class RoleNode(CompositeNode): @@ -194,8 +200,14 @@ class RoleNode(CompositeNode): A role node. A role is a composition of tasks """ - def __init__(self, node_label: str, node_id: str = None): - super().__init__(node_label, node_id or generate_id("role_")) + def __init__(self, node_label: str, node_id: str = None, label_prefix: str = "[role] "): + """ + + :param node_label: + :param node_id: + :param label_prefix: Prefix for the label + """ + super().__init__(label_prefix + node_label, node_id or generate_id("role_")) @property def tasks(self): diff --git a/ansibleplaybookgrapher/parser.py b/ansibleplaybookgrapher/parser.py index f24ffcc..882b600 100644 --- a/ansibleplaybookgrapher/parser.py +++ b/ansibleplaybookgrapher/parser.py @@ -79,9 +79,10 @@ class BaseParser(ABC): when = "".join(map(str, task.when)) task_edge_name += " [when: " + when + "]" - task_name = clean_name(f"[{node_type}] " + self.template(task.get_name(), task_vars)) + task_name = clean_name(self.template(task.get_name(), task_vars)) - edge_node = EdgeNode(task_edge_name, parent_node, TaskNode(task_name, generate_id(f"{node_type}_"))) + edge_node = EdgeNode(task_edge_name, parent_node, + TaskNode(task_name, generate_id(f"{node_type}_"), label_prefix=f"[{node_type}] ")) parent_node.add_node(target_composition=f"{node_type}s", node=edge_node) return True @@ -167,7 +168,7 @@ class PlaybookParser(BaseParser): # Go to the next role continue - role_node = RoleNode("[role] " + clean_name(role.get_name())) + role_node = RoleNode(clean_name(role.get_name())) # edge from play to role play_node.add_node("roles", EdgeNode(str(role_counter + len(play_node.pre_tasks)), play_node, role_node))