]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
python-common: add a utils function to replace distutils.util.strtobool
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 19 Sep 2024 00:44:39 +0000 (17:44 -0700)
committerPatrick Donnelly <pdonnell@ibm.com>
Mon, 17 Mar 2025 19:43:15 +0000 (15:43 -0400)
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 <jmulligan@redhat.com>
(cherry picked from commit 51516ba146e9602c0dea1de65b040d737d1dab6a)

src/python-common/ceph/utils.py

index e92a2d1de7db8613d6e678713b7c0a3cd994020c..0544e9f4173d102fb88b6f53286f0808f0bf6eee 100644 (file)
@@ -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}')