[oe-commits] Chris Larson : oe.utils: add 'inherits' function

git version control git at git.openembedded.org
Fri Apr 22 17:52:28 UTC 2011


Module: openembedded.git
Branch: shr/testing2011.1
Commit: 34f71f238c9e64aa08fb0b0d222a4faca0d71267
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=34f71f238c9e64aa08fb0b0d222a4faca0d71267

Author: Chris Larson <chris_larson at mentor.com>
Date:   Wed Dec 15 11:03:19 2010 -0700

oe.utils: add 'inherits' function

This is simply a more convenient form of bb.data.inherits_class, as it can
accept any number of classes, and will return True if it inherits any of them.
This is similar to how isinstance() behaves.

Signed-off-by: Chris Larson <chris_larson at mentor.com>
Signed-off-by: Martin Jansa <Martin.Jansa at gmail.com>

---

 lib/oe/utils.py |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/oe/utils.py b/lib/oe/utils.py
index 2169ed2..f7d2946 100644
--- a/lib/oe/utils.py
+++ b/lib/oe/utils.py
@@ -1,3 +1,5 @@
+import bb.data
+
 def uniq(iterable):
     seen = set()
     for i in iterable:
@@ -7,8 +9,8 @@ def uniq(iterable):
 
 def read_file(filename):
     try:
-        f = file( filename, "r" )
-    except IOError, reason:
+        f = file(filename, "r")
+    except IOError:
         return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
     else:
         return f.read().strip()
@@ -60,7 +62,7 @@ def both_contain(variable1, variable2, checkvalue, d):
         return ""
 
 def prune_suffix(var, suffixes, d):
-    # See if var ends with any of the suffixes listed and 
+    # See if var ends with any of the suffixes listed and
     # remove it if found
     for suffix in suffixes:
         if var.endswith(suffix):
@@ -85,3 +87,7 @@ def param_bool(cfg, field, dflt = None):
     elif strvalue in ('no', 'n', 'false', 'f', '0'):
         return False
     raise ValueError("invalid value for boolean parameter '%s': '%s'" % (field, value))
+
+def inherits(d, *classes):
+    """Return True if the metadata inherits any of the specified classes"""
+    return any(bb.data.inherits_class(cls, d) for cls in classes)





More information about the Openembedded-commits mailing list