diff options
author | Enrico Scholz <enrico.scholz@sigma-chemnitz.de> | 2010-05-27 02:41:09 +0000 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-05-27 12:56:46 -0700 |
commit | 0d270547fdb047fb2bcc1f69d6ba1f440c78578a (patch) | |
tree | 24af47be13307d6267943c44a697e3f2a8aaabef /lib | |
parent | 311bed0b40aaa6298029f727d97f50c1d740a3fa (diff) |
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 <enrico.scholz@sigma-chemnitz.de>
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oe/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
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 <field> in <cfg> map and convert it to a boolean; take + <dflt> when this <field> 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)) |