From 0d270547fdb047fb2bcc1f69d6ba1f440c78578a Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 27 May 2010 02:41:09 +0000 Subject: oe.utils: added param_bool() method This new function works like dict's get() method but converts the returned value to a boolean. It is to be used to interpret e.g. 'apply=yes' parameters in SRC_URI. Moved from base.bbclass into lib/oe/utils.py -kergoth Signed-off-by: Enrico Scholz Signed-off-by: Chris Larson --- lib/oe/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/oe') diff --git a/lib/oe/utils.py b/lib/oe/utils.py index e61d663a50..3469700726 100644 --- a/lib/oe/utils.py +++ b/lib/oe/utils.py @@ -67,3 +67,14 @@ def str_filter(f, str, d): def str_filter_out(f, str, d): from re import match return " ".join(filter(lambda x: not match(f, x, 0), str.split())) + +def param_bool(cfg, field, dflt = None): + """Lookup in map and convert it to a boolean; take + when this does not exist""" + value = cfg.get(field, dflt) + strvalue = str(value).lower() + if strvalue in ('yes', 'y', 'true', 't', '1'): + return True + elif strvalue in ('no', 'n', 'false', 'f', '0'): + return False + raise ValueError("invalid value for boolean parameter '%s': '%s'" % (field, value)) -- cgit 1.2.3-korg