Skip to content

Commit 51516ba

Browse files
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 <[email protected]>
1 parent 7d9fe0a commit 51516ba

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/python-common/ceph/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,18 @@ def http_req(hostname: str = '',
167167
log.error(e)
168168
# handle error here if needed
169169
raise
170+
171+
172+
_TRUE_VALS = {'y', 'yes', 't', 'true', 'on', '1'}
173+
_FALSE_VALS = {'n', 'no', 'f', 'false', 'off', '0'}
174+
175+
176+
def strtobool(value: str) -> bool:
177+
"""Convert a string to a boolean value.
178+
Based on a simlilar function once available at distutils.util.strtobool.
179+
"""
180+
if value.lower() in _TRUE_VALS:
181+
return True
182+
if value.lower() in _FALSE_VALS:
183+
return False
184+
raise ValueError(f'invalid truth value {value!r}')

0 commit comments

Comments
 (0)