[oe-commits] Enrico Scholz : oe.utils: added param_bool() method
git version control
git at git.openembedded.org
Sat May 29 07:34:18 UTC 2010
Module: openembedded.git
Branch: shr/testing2010
Commit: 0d270547fdb047fb2bcc1f69d6ba1f440c78578a
URL: http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=0d270547fdb047fb2bcc1f69d6ba1f440c78578a
Author: Enrico Scholz <enrico.scholz at sigma-chemnitz.de>
Date: Thu May 27 02:41:09 2010 +0000
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 at sigma-chemnitz.de>
Signed-off-by: Chris Larson <chris_larson at mentor.com>
---
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 e61d663..3469700 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))
More information about the Openembedded-commits
mailing list