Add bumblebee.util.asbool function

Harmonize the boolean parameter value. Now `t`, `true`, `y`, `yes`, `on`, `1` are considered truthy and
everything else falsy.
This commit is contained in:
Frederic Junod 2017-07-08 06:44:08 +02:00
parent cc6da2b70e
commit b0268a412b
6 changed files with 26 additions and 13 deletions

View file

@ -10,6 +10,15 @@ except ImportError:
# Python3 doesn't require this anymore
pass
def asbool(val):
if val is None:
return False
if isinstance(val, bool):
return val
val = str(val).strip().lower()
return val in ("t", "true", "y", "yes", "on", "1")
def execute(cmd, wait=True):
logging.info("executing command '{}'".format(cmd))
args = shlex.split(cmd)