The Console object

The console object is an interface for user interaction from within a Node. Among the input methods are choice lists, plain text input and password input.

It has output methods that take the terminal size into account, like pagination and multi-column display. It takes care of the pseudo terminal underneat.

Example:

class MyNode(Node):
    def do_something(self):
        if self.console.confirm('Should we really do this?', default=True):
            # Do it...
            pass

Note

When the script runs in a shell that was started with the --non-interactive option, the default options will always be chosen automatically.

class deployer.console.Console(pty)

Interface for user interaction from within a Node.

Parameters:ptydeployer.pseudo_terminal.Pty instance.
choice(question, options, allow_random=False, default=None)
Parameters:
  • options (list) – List of (name, value) tuples.
  • allow_random (bool) – If True, the default option becomes ‘choose random’.
confirm(question, default=None)

Print this yes/no question, and return True when the user answers ‘Yes’.

in_columns(item_iterator, margin_left=0)
Parameters:item_iterator – An iterable, which yields either basestring instances, or (colored_item, length) tuples.
input(label, is_password=False, answers=None, default=None)

Ask for plain text input. (Similar to raw_input.)

Parameters:
  • is_password (bool) – Show stars instead of the actual user input.
  • answers – A list of the accepted answers or None.
  • default – Default answer.
is_interactive

When False don’t ask for input and choose the default options when possible.

lesspipe(line_iterator)

Paginator for output. This will print one page at a time. When the user presses a key, the next page is printed. Ctrl-c or q will quit the paginator.

Parameters:line_iterator – A generator function that yields lines (without trailing newline)
progress_bar(message, expected=None, clear_on_finish=False, format_str=None)

Display a progress bar. This returns a Python context manager. Call the next() method to increase the counter.

with console.progress_bar('Looking for nodes') as p:
    for i in range(0, 1000):
        p.next()
        ...
Returns:ProgressBar instance.
Parameters:message – Text label of the progress bar.
progress_bar_with_steps(message, steps, format_str=None)

Display a progress bar with steps.

steps = ProgressBarSteps({
    1: "Resolving address",
    2: "Create transport",
    3: "Get remote key",
    4: "Authenticating" })

with console.progress_bar_with_steps('Connecting to SSH server', steps=steps) as p:
    ...
    p.set_progress(1)
    ...
    p.set_progress(2)
    ...
Parameters:
  • stepsProgressBarSteps instance.
  • message – Text label of the progress bar.
pty

The deployer.pseudo_terminal.Pty of this console.

select_node(root_node, prompt='Select a node', filter=None)

Show autocompletion for node selection.

select_node_isolation(node)

Ask for a host, from a list of hosts.

warning(text)

Print a warning.