summaryrefslogtreecommitdiff
path: root/lib/python/qmk/util.py
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2024-11-08 15:57:22 +1100
committerGitHub <noreply@github.com>2024-11-08 04:57:22 +0000
commit580d18d2e9a9cb08f11439d5dd58d8e3adffd17f (patch)
tree761d0572fc7b46ddfbe2487e4f9684a26e8abc16 /lib/python/qmk/util.py
parent4f9ef90754a79774da5685b786403c130d836ac4 (diff)
Speed improvements to `qmk find`. (#24385)
Diffstat (limited to 'lib/python/qmk/util.py')
-rw-r--r--lib/python/qmk/util.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/python/qmk/util.py b/lib/python/qmk/util.py
index b73fab89d1..8f99410e1d 100644
--- a/lib/python/qmk/util.py
+++ b/lib/python/qmk/util.py
@@ -27,6 +27,27 @@ def maybe_exit_config(should_exit: bool = True, should_reraise: bool = False):
27 maybe_exit_reraise = should_reraise 27 maybe_exit_reraise = should_reraise
28 28
29 29
30def truthy(value, value_if_unknown=False):
31 """Returns True if the value is truthy, False otherwise.
32
33 Deals with:
34 True: 1, true, t, yes, y, on
35 False: 0, false, f, no, n, off
36 """
37 if value in {False, True}:
38 return bool(value)
39
40 test_value = str(value).strip().lower()
41
42 if test_value in {"1", "true", "t", "yes", "y", "on"}:
43 return True
44
45 if test_value in {"0", "false", "f", "no", "n", "off"}:
46 return False
47
48 return value_if_unknown
49
50
30@contextlib.contextmanager 51@contextlib.contextmanager
31def parallelize(): 52def parallelize():
32 """Returns a function that can be used in place of a map() call. 53 """Returns a function that can be used in place of a map() call.