aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/utils.py
diff options
context:
space:
mode:
authorJoshua Lock <josh@linux.intel.com>2010-04-30 16:35:50 +0100
committerJoshua Lock <josh@linux.intel.com>2010-05-06 12:48:05 +0100
commitac023d775b651c9b1e28a7a725e72949fe54ad47 (patch)
treeda69e91c7d2ce4785ddf6af6b756758d1789d5a2 /meta/lib/oe/utils.py
parent14196cb03190d9dac93be309763e3076385eb831 (diff)
downloadopenembedded-core-ac023d775b651c9b1e28a7a725e72949fe54ad47.tar.gz
lib/oe: Import oe lib from OE.dev
This library moves the common Python methods into modules of an 'oe' Python package. Signed-off-by: Joshua Lock <josh@linux.intel.com>
Diffstat (limited to 'meta/lib/oe/utils.py')
-rw-r--r--meta/lib/oe/utils.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
new file mode 100644
index 0000000000..e61d663a50
--- /dev/null
+++ b/meta/lib/oe/utils.py
@@ -0,0 +1,69 @@
+def read_file(filename):
+ try:
+ f = file( filename, "r" )
+ except IOError, reason:
+ 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()
+ return None
+
+def ifelse(condition, iftrue = True, iffalse = False):
+ if condition:
+ return iftrue
+ else:
+ return iffalse
+
+def conditional(variable, checkvalue, truevalue, falsevalue, d):
+ if bb.data.getVar(variable,d,1) == checkvalue:
+ return truevalue
+ else:
+ return falsevalue
+
+def less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
+ if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
+ return truevalue
+ else:
+ return falsevalue
+
+def version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
+ result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
+ if result <= 0:
+ return truevalue
+ else:
+ return falsevalue
+
+def contains(variable, checkvalues, truevalue, falsevalue, d):
+ val = bb.data.getVar(variable,d,1)
+ if not val:
+ return falsevalue
+ matches = 0
+ if type(checkvalues).__name__ == "str":
+ checkvalues = [checkvalues]
+ for value in checkvalues:
+ if val.find(value) != -1:
+ matches = matches + 1
+ if matches == len(checkvalues):
+ return truevalue
+ return falsevalue
+
+def both_contain(variable1, variable2, checkvalue, d):
+ if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
+ return checkvalue
+ else:
+ return ""
+
+def prune_suffix(var, suffixes, d):
+ # See if var ends with any of the suffixes listed and
+ # remove it if found
+ for suffix in suffixes:
+ if var.endswith(suffix):
+ return var.replace(suffix, "")
+ return var
+
+def str_filter(f, str, d):
+ from re import match
+ return " ".join(filter(lambda x: match(f, x, 0), str.split()))
+
+def str_filter_out(f, str, d):
+ from re import match
+ return " ".join(filter(lambda x: not match(f, x, 0), str.split()))