diff options
Diffstat (limited to 'lib/python/qmk/util.py')
| -rw-r--r-- | lib/python/qmk/util.py | 21 |
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 | ||
| 30 | def 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 |
| 31 | def parallelize(): | 52 | def 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. |
