From 66f7738139e393997248d75f8a9a578ea51aec6c Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 16 Oct 2023 12:10:57 +0200 Subject: [PATCH] fix: remove deprecated distutils (#572) --- ansibledoctor/utils.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ansibledoctor/utils.py b/ansibledoctor/utils.py index 8c67008..c87409e 100644 --- a/ansibledoctor/utils.py +++ b/ansibledoctor/utils.py @@ -5,7 +5,6 @@ import logging import os import sys from collections.abc import Iterable -from distutils.util import strtobool import colorama from pythonjsonlogger import jsonlogger @@ -16,6 +15,30 @@ CONSOLE_FORMAT = "{}{}[%(levelname)s]{} %(message)s" JSON_FORMAT = "%(asctime)s %(levelname)s %(message)s" +def strtobool(value): + """Convert a string representation of truth to true or false.""" + + _map = { + "y": True, + "yes": True, + "t": True, + "true": True, + "on": True, + "1": True, + "n": False, + "no": False, + "f": False, + "false": False, + "off": False, + "0": False + } + + try: + return _map[str(value).lower()] + except KeyError as err: + raise ValueError(f'"{value}" is not a valid bool value') from err + + def to_bool(string): return bool(strtobool(str(string)))