diff options
| author | Joshua Lock <josh@linux.intel.com> | 2010-04-30 16:35:50 +0100 |
|---|---|---|
| committer | Joshua Lock <josh@linux.intel.com> | 2010-05-06 12:48:05 +0100 |
| commit | ac023d775b651c9b1e28a7a725e72949fe54ad47 (patch) | |
| tree | da69e91c7d2ce4785ddf6af6b756758d1789d5a2 /meta/lib/oe/utils.py | |
| parent | 14196cb03190d9dac93be309763e3076385eb831 (diff) | |
| download | poky-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.py | 69 |
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 @@ | |||
| 1 | def read_file(filename): | ||
| 2 | try: | ||
| 3 | f = file( filename, "r" ) | ||
| 4 | except IOError, reason: | ||
| 5 | return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M: | ||
| 6 | else: | ||
| 7 | return f.read().strip() | ||
| 8 | return None | ||
| 9 | |||
| 10 | def ifelse(condition, iftrue = True, iffalse = False): | ||
| 11 | if condition: | ||
| 12 | return iftrue | ||
| 13 | else: | ||
| 14 | return iffalse | ||
| 15 | |||
| 16 | def conditional(variable, checkvalue, truevalue, falsevalue, d): | ||
| 17 | if bb.data.getVar(variable,d,1) == checkvalue: | ||
| 18 | return truevalue | ||
| 19 | else: | ||
| 20 | return falsevalue | ||
| 21 | |||
| 22 | def less_or_equal(variable, checkvalue, truevalue, falsevalue, d): | ||
| 23 | if float(bb.data.getVar(variable,d,1)) <= float(checkvalue): | ||
| 24 | return truevalue | ||
| 25 | else: | ||
| 26 | return falsevalue | ||
| 27 | |||
| 28 | def version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d): | ||
| 29 | result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue) | ||
| 30 | if result <= 0: | ||
| 31 | return truevalue | ||
| 32 | else: | ||
| 33 | return falsevalue | ||
| 34 | |||
| 35 | def contains(variable, checkvalues, truevalue, falsevalue, d): | ||
| 36 | val = bb.data.getVar(variable,d,1) | ||
| 37 | if not val: | ||
| 38 | return falsevalue | ||
| 39 | matches = 0 | ||
| 40 | if type(checkvalues).__name__ == "str": | ||
| 41 | checkvalues = [checkvalues] | ||
| 42 | for value in checkvalues: | ||
| 43 | if val.find(value) != -1: | ||
| 44 | matches = matches + 1 | ||
| 45 | if matches == len(checkvalues): | ||
| 46 | return truevalue | ||
| 47 | return falsevalue | ||
| 48 | |||
| 49 | def both_contain(variable1, variable2, checkvalue, d): | ||
| 50 | if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1: | ||
| 51 | return checkvalue | ||
| 52 | else: | ||
| 53 | return "" | ||
| 54 | |||
| 55 | def prune_suffix(var, suffixes, d): | ||
| 56 | # See if var ends with any of the suffixes listed and | ||
| 57 | # remove it if found | ||
| 58 | for suffix in suffixes: | ||
| 59 | if var.endswith(suffix): | ||
| 60 | return var.replace(suffix, "") | ||
| 61 | return var | ||
| 62 | |||
| 63 | def str_filter(f, str, d): | ||
| 64 | from re import match | ||
| 65 | return " ".join(filter(lambda x: match(f, x, 0), str.split())) | ||
| 66 | |||
| 67 | def str_filter_out(f, str, d): | ||
| 68 | from re import match | ||
| 69 | return " ".join(filter(lambda x: not match(f, x, 0), str.split())) | ||
