From 580d18d2e9a9cb08f11439d5dd58d8e3adffd17f Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 8 Nov 2024 15:57:22 +1100 Subject: Speed improvements to `qmk find`. (#24385) --- lib/python/qmk/util.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/python/qmk/util.py') 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): maybe_exit_reraise = should_reraise +def truthy(value, value_if_unknown=False): + """Returns True if the value is truthy, False otherwise. + + Deals with: + True: 1, true, t, yes, y, on + False: 0, false, f, no, n, off + """ + if value in {False, True}: + return bool(value) + + test_value = str(value).strip().lower() + + if test_value in {"1", "true", "t", "yes", "y", "on"}: + return True + + if test_value in {"0", "false", "f", "no", "n", "off"}: + return False + + return value_if_unknown + + @contextlib.contextmanager def parallelize(): """Returns a function that can be used in place of a map() call. -- cgit v1.2.3