From: John Mulligan Date: Thu, 19 Sep 2024 00:44:39 +0000 (-0700) Subject: python-common: add a utils function to replace distutils.util.strtobool X-Git-Tag: testing/wip-khiremat-testing-20250422.120708-squid-debug~101^2~72 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=102930733bfa4c77fa8a87463a1e505eabcacc67;p=ceph-ci.git python-common: add a utils function to replace distutils.util.strtobool As distutils is removed from python 3.12 ceph can no longer use the simple conversion function once located in that module. Add our own trivial replacement function. Signed-off-by: John Mulligan (cherry picked from commit 51516ba146e9602c0dea1de65b040d737d1dab6a) --- diff --git a/src/python-common/ceph/utils.py b/src/python-common/ceph/utils.py index e92a2d1de7d..0544e9f4173 100644 --- a/src/python-common/ceph/utils.py +++ b/src/python-common/ceph/utils.py @@ -167,3 +167,18 @@ def http_req(hostname: str = '', log.error(e) # handle error here if needed raise + + +_TRUE_VALS = {'y', 'yes', 't', 'true', 'on', '1'} +_FALSE_VALS = {'n', 'no', 'f', 'false', 'off', '0'} + + +def strtobool(value: str) -> bool: + """Convert a string to a boolean value. + Based on a simlilar function once available at distutils.util.strtobool. + """ + if value.lower() in _TRUE_VALS: + return True + if value.lower() in _FALSE_VALS: + return False + raise ValueError(f'invalid truth value {value!r}')