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

Fixing colorama global init in print_result #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions nornir_utils/plugins/functions/print_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
from collections import OrderedDict
import json

from colorama import Fore, Style, init
from colorama import Fore, Style, init, deinit

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


LOCK = threading.Lock()


init(autoreset=True, strip=False)


def print_title(title: str) -> None:
"""
Helper function to print a title.
"""
init(autoreset=True, strip=False)
msg = "**** {} ".format(title)
print("{}{}{}{}".format(Style.BRIGHT, Fore.GREEN, msg, "*" * (80 - len(msg))))
deinit()


def _get_color(result: Result, failed: bool) -> str:
Expand Down Expand Up @@ -138,7 +137,9 @@ def print_result(
severity_level: Print only errors with this severity level or higher
"""
LOCK.acquire()
init(autoreset=True, strip=False)
try:
_print_result(result, vars, failed, severity_level, print_host=True)
finally:
deinit()
LOCK.release()