Skip to content

Commit

Permalink
(#CALM-39370) fix task tree indents (#270)
Browse files Browse the repository at this point in the history
### Summary
1. task tree decompile was failing due to indentation issues
2. context was not initialised when decompiling runbook

(cherry picked from commit d7f15ff1a630ff8bc508dd93d8e79bcea96304b0)
  • Loading branch information
Abhishekntnx authored and abhijeetkaurav1st committed Aug 22, 2023
1 parent 976697a commit 9ed2adf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion calm/dsl/cli/runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from calm.dsl.decompile.decompile_render import create_runbook_dir
from calm.dsl.decompile.file_handler import get_runbook_dir
from calm.dsl.decompile.main import init_decompile_context
from calm.dsl.runbooks import runbook, create_runbook_payload, RunbookType
from calm.dsl.builtins.models.metadata_payload import get_metadata_payload
from calm.dsl.config import get_context
Expand Down Expand Up @@ -189,7 +190,7 @@ def decompile_runbook_command(name, runbook_file, prefix="", runbook_dir=None):
if name and runbook_file:
LOG.error("Please provide either runbook file location or server runbook name")
sys.exit("Both runbook name and file location provided.")

init_decompile_context()
if name:
decompile_runbook_from_server(name=name, runbook_dir=runbook_dir, prefix=prefix)

Expand Down
22 changes: 13 additions & 9 deletions calm/dsl/decompile/decompile_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,35 @@ def generate_indents(
"""
while_tasks = special_tasks_data["while_tasks"]
output = self.output
curr_indent = base_indent
if if_needed or else_needed:
curr_indent += 1
if_block_indent = None
else_block_indent = None
if if_needed:
if_block_indent = base_indent - 1
elif else_needed:
else_block_indent = base_indent - 1

output.append(
{
"task_name": curr_task,
"while_block_indent": curr_indent,
"task_indent": curr_indent,
"while_block_indent": base_indent,
"task_indent": base_indent,
"depth": depth,
"if_block_indent": base_indent - 1 if if_needed else None,
"else_block_indent": base_indent - 1 if if_needed else None,
"if_block_indent": if_block_indent,
"else_block_indent": else_block_indent,
}
)
for task in while_tasks[curr_task]["child_tasks"]:
if task.type in special_tasks_types:
helper = IndentHelper()
output += helper.generate_indents(
special_tasks_data, task, curr_indent + 1, depth + 1, False, False
special_tasks_data, task, base_indent + 1, depth + 1, False, False
)
else:
output.append(
{
"task_name": task.name,
"while_block_indent": None,
"task_indent": curr_indent + 1,
"task_indent": base_indent + 1,
"depth": depth + 1,
"if_block_indent": None,
"else_block_indent": None,
Expand Down

0 comments on commit 9ed2adf

Please sign in to comment.