Skip to content

Commit

Permalink
Merge 389be2e into 21a6859
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Jul 12, 2018
2 parents 21a6859 + 389be2e commit 90c1908
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions nornir/plugins/functions/text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import logging
import pprint
import threading

from colorama import Fore, Style, init

from nornir.core.task import AggregatedResult, MultiResult, Result

from colorama import Fore, Style, init

LOCK = threading.Lock()


init(autoreset=True, convert=False, strip=False)
Expand Down Expand Up @@ -53,22 +57,9 @@ def _print_individual_result(
print(x)


def print_result(
def _print_result(
result, host=None, vars=None, failed=None, severity_level=logging.INFO
):
"""
Prints the :obj:`nornir.core.task.Result` from a previous task to screen
Arguments:
result (:obj:`nornir.core.task.Result`): from a previous task
vars (list of str): Which attributes you want to print
failed (``bool``): if ``True`` assume the task failed
severity_level (int): Print only errors with this severity level or higher
Returns:
:obj:`nornir.core.task.Result`:
"""

vars = vars or ["diff", "result", "stdout"]
if isinstance(vars, str):
vars = [vars]
Expand All @@ -84,15 +75,37 @@ def print_result(
print(
"{}{}{}{}".format(Style.BRIGHT, Fore.BLUE, msg, "*" * (80 - len(msg)))
)
print_result(host_data, host, vars, failed, severity_level)
_print_result(host_data, host, vars, failed, severity_level)
elif isinstance(result, MultiResult):
_print_individual_result(
result[0], host, vars, failed, severity_level, task_group=True
)
for r in result[1:]:
print_result(r, host, vars, failed, severity_level)
_print_result(r, host, vars, failed, severity_level)
color = _get_color(result[0], failed)
msg = "^^^^ END {} ".format(result[0].name)
print("{}{}{}{}".format(Style.BRIGHT, color, msg, "^" * (80 - len(msg))))
elif isinstance(result, Result):
_print_individual_result(result, host, vars, failed, severity_level)


def print_result(
result, host=None, vars=None, failed=None, severity_level=logging.INFO
):
"""
Prints the :obj:`nornir.core.task.Result` from a previous task to screen
Arguments:
result (:obj:`nornir.core.task.Result`): from a previous task
vars (list of str): Which attributes you want to print
failed (``bool``): if ``True`` assume the task failed
severity_level (int): Print only errors with this severity level or higher
Returns:
:obj:`nornir.core.task.Result`:
"""
LOCK.acquire()
try:
_print_result(result, host, vars, failed, severity_level)
finally:
LOCK.release()

0 comments on commit 90c1908

Please sign in to comment.