Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/runbook watch for non interactive command #114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions calm/dsl/cli/runlog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys

from asciimatics.widgets import (
Expand Down Expand Up @@ -202,7 +203,7 @@ def displayRunLogTree(screen, root, completed_tasks, total_tasks, msg=None):

screen.print_at(
runlog_state,
screen.width - len(runlog_state) - 5,
screen.width - len(runlog_state) - 5 if hasattr(screen, "width") else 0,
0,
colour=colour,
attr=Screen.A_UNDERLINE,
Expand Down Expand Up @@ -298,7 +299,8 @@ def displayRunLog(screen, obj, pre, fill, line):
colour = 4 # blue for running state
elif state == RUNLOG.STATUS.INPUT:
colour = 6 # cyan for input state
screen.print_at("{}".format(state), len(prefix) + 1, idx(), colour=colour)
if os.isatty(sys.stdout.fileno()):
screen.print_at("{}".format(state), len(prefix) + 1, idx(), colour=colour)

if obj.children:
fill = fill + u"\u2502"
Expand Down Expand Up @@ -361,7 +363,9 @@ def is_action_complete(
if len(entities):

# catching interrupt for pause and play
interrupt = screen.get_event()
interrupt = None
if hasattr(screen, "get_event"):
interrupt = screen.get_event()

# Sort entities based on creation time
sorted_entities = sorted(
Expand Down Expand Up @@ -571,23 +575,29 @@ def is_action_complete(
state = runlog["status"]["state"]
if state in RUNLOG.FAILURE_STATES:
sleep(2)
msg = "Action failed. Exit screen? (y)"
screen.play([Scene([RerunFrame(state, screen)], -1)])
if rerun.get("rerun", False):
client.runbook.rerun(runlog_uuid)
msg = "Triggered rerun for the Runbook Runlog"
msg = "Action failed."
if os.isatty(sys.stdout.fileno()):
msg += " Exit screen?"
screen.play([Scene([RerunFrame(state, screen)], -1)])
if rerun.get("rerun", False):
client.runbook.rerun(runlog_uuid)
msg = "Triggered rerun for the Runbook Runlog"
displayRunLogTree(
screen, root, completed_tasks, total_tasks, msg=msg
)
return (False, "")
displayRunLogTree(
screen, root, completed_tasks, total_tasks, msg=msg
)
return (False, "")
displayRunLogTree(
screen, root, completed_tasks, total_tasks, msg=msg
)
return (True, msg)
return (True, msg)
else:
return (True, msg)
if state not in RUNLOG.TERMINAL_STATES:
return (False, "")

msg = "Action ran successfully. Exit screen? (y)"
msg = "Action ran successfully."
if os.isatty(sys.stdout.fileno()):
msg += " Exit screen?"
screen.print_at(msg, 0, line, colour=6)
screen.refresh()

Expand Down
2 changes: 1 addition & 1 deletion calm/dsl/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def refresh(self):
def wait_for_input(self, *args):
pass

def print_at(self, text, x, *args):
def print_at(self, text, x, *args, **kwargs):
click.echo("{}{}".format((" " * x), text))


Expand Down