From e867939a7129c9226c7864cca2397cdb599e5c45 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 16 Oct 2023 12:11:09 +0200 Subject: [PATCH] fix: remove deprecated distutils (#279) --- dockerautotag/utils.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dockerautotag/utils.py b/dockerautotag/utils.py index 0283ac4..c8d8442 100644 --- a/dockerautotag/utils.py +++ b/dockerautotag/utils.py @@ -1,7 +1,6 @@ """Global utility methods and classes.""" import os -from distutils.util import strtobool def normalize_path(path): @@ -11,6 +10,30 @@ def normalize_path(path): return None +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)))