aboutsummaryrefslogtreecommitdiffstats
path: root/classes/utils.bbclass
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-04-14 17:59:49 -0700
committerChris Larson <chris_larson@mentor.com>2010-04-23 14:20:42 -0700
commitbb753c4f0bc7fe463e7939a1f2685504a9a0f883 (patch)
tree8185a9128e893b44ca124e6d8a6d02e245f0efbe /classes/utils.bbclass
parent5816ec4860aba7289483b87b4aa4909eee50fae9 (diff)
downloadopenembedded-bb753c4f0bc7fe463e7939a1f2685504a9a0f883.tar.gz
Initial move of common python bits into modules of the 'oe' python package
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'classes/utils.bbclass')
-rw-r--r--classes/utils.bbclass158
1 files changed, 41 insertions, 117 deletions
diff --git a/classes/utils.bbclass b/classes/utils.bbclass
index 0252a439b0..d45adea33d 100644
--- a/classes/utils.bbclass
+++ b/classes/utils.bbclass
@@ -1,3 +1,44 @@
+# For compatibility
+def base_path_join(a, *p):
+ return oe.path.join(a, *p)
+
+def base_path_relative(src, dest):
+ return oe.path.relative(src, dest)
+
+def base_path_out(path, d):
+ return oe.path.format_display(path, d)
+
+def base_read_file(filename):
+ return oe.utils.read_file(filename)
+
+def base_ifelse(condition, iftrue = True, iffalse = False):
+ return oe.utils.ifelse(condition, iftrue, iffalse)
+
+def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
+ return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d)
+
+def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
+ return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
+
+def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
+ return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
+
+def base_contains(variable, checkvalues, truevalue, falsevalue, d):
+ return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
+
+def base_both_contain(variable1, variable2, checkvalue, d):
+ return oe.utils.both_contain(variable1, variable2, checkvalue, d)
+
+def base_prune_suffix(var, suffixes, d):
+ return oe.utils.prune_suffix(var, suffixes, d)
+
+def oe_filter(f, str, d):
+ return oe.utils.str_filter(f, str, d)
+
+def oe_filter_out(f, str, d):
+ return oe.utils.str_filter_out(f, str, d)
+
+
def subprocess_setup():
import signal
# Python installs a SIGPIPE handler by default. This is usually not what
@@ -28,53 +69,6 @@ def oe_system(d, cmd):
""" Popen based version of os.system. """
return oe_popen(d, cmd, shell=True).wait()
-# like os.path.join but doesn't treat absolute RHS specially
-def base_path_join(a, *p):
- path = a
- for b in p:
- if path == '' or path.endswith('/'):
- path += b
- else:
- path += '/' + b
- return path
-
-def base_path_relative(src, dest):
- """ Return a relative path from src to dest.
-
- >>> base_path_relative("/usr/bin", "/tmp/foo/bar")
- ../../tmp/foo/bar
-
- >>> base_path_relative("/usr/bin", "/usr/lib")
- ../lib
-
- >>> base_path_relative("/tmp", "/tmp/foo/bar")
- foo/bar
- """
- from os.path import sep, pardir, normpath, commonprefix
-
- destlist = normpath(dest).split(sep)
- srclist = normpath(src).split(sep)
-
- # Find common section of the path
- common = commonprefix([destlist, srclist])
- commonlen = len(common)
-
- # Climb back to the point where they differentiate
- relpath = [ pardir ] * (len(srclist) - commonlen)
- if commonlen < len(destlist):
- # Add remaining portion
- relpath += destlist[commonlen:]
-
- return sep.join(relpath)
-
-def base_path_out(path, d):
- """ Prepare a path for display to the user. """
- rel = base_path_relative(d.getVar("TOPDIR", 1), path)
- if len(rel) > len(path):
- return path
- else:
- return rel
-
# for MD5/SHA handling
def base_chk_load_parser(config_paths):
import ConfigParser
@@ -207,76 +201,6 @@ def base_chk_file(pn, pv, src_uri, localpath, params, data):
(expected_md5sum, expected_sha256sum) = base_get_checksums(pn, pv, src_uri, localpath, params, data)
return base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data)
-def base_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 base_ifelse(condition, iftrue = True, iffalse = False):
- if condition:
- return iftrue
- else:
- return iffalse
-
-def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
- if bb.data.getVar(variable,d,1) == checkvalue:
- return truevalue
- else:
- return falsevalue
-
-def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
- if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
- return truevalue
- else:
- return falsevalue
-
-def base_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 base_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 base_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 base_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 oe_filter(f, str, d):
- from re import match
- return " ".join(filter(lambda x: match(f, x, 0), str.split()))
-
-def oe_filter_out(f, str, d):
- from re import match
- return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
-
oedebug() {
test $# -ge 2 || {
echo "Usage: oedebug level \"message\""