Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 1 | # Helper functions for checking feature variables. |
| 2 | |
| 3 | inherit utils |
| 4 | |
Brad Bishop | 6ba6a51 | 2016-07-10 19:44:42 -0400 | [diff] [blame] | 5 | |
Brad Bishop | 961df76 | 2017-01-31 10:37:13 -0500 | [diff] [blame] | 6 | def df_enabled(d, feature, truevalue, falsevalue=""): |
| 7 | return base_contains("DISTRO_FEATURES", feature, truevalue, falsevalue, d) |
Brad Bishop | 6ba6a51 | 2016-07-10 19:44:42 -0400 | [diff] [blame] | 8 | |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 9 | |
Brad Bishop | 961df76 | 2017-01-31 10:37:13 -0500 | [diff] [blame] | 10 | def mf_enabled(d, feature, truevalue, falsevalue=""): |
| 11 | return base_contains("MACHINE_FEATURES", feature, truevalue, falsevalue, d) |
Brad Bishop | 6ba6a51 | 2016-07-10 19:44:42 -0400 | [diff] [blame] | 12 | |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 13 | |
Brad Bishop | 961df76 | 2017-01-31 10:37:13 -0500 | [diff] [blame] | 14 | def cf_enabled(d, feature, truevalue, falsevalue=""): |
| 15 | return truevalue if df_enabled(d, feature, truevalue) \ |
| 16 | and mf_enabled(d, feature, truevalue) \ |
| 17 | else falsevalue |
Brad Bishop | 9dc5671 | 2016-07-07 15:56:02 -0400 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def set_append(d, var, val, sep=' '): |
| 21 | values = (d.getVar(var, True) or '').split(sep) |
| 22 | if filter(bool, values): |
| 23 | d.appendVar(var, '%s%s' %(sep, val)) |
| 24 | else: |
| 25 | d.setVar(var, val) |
| 26 | |
| 27 | |
| 28 | def listvar_to_list(d, list_var, sep=' '): |
Saqib Khan | dc2090d | 2017-03-07 07:05:56 -0600 | [diff] [blame] | 29 | return list(filter(bool, (d.getVar(list_var, True) or '').split(sep))) |
Brad Bishop | 167aaae | 2016-08-24 14:08:35 -0400 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def compose_list(d, fmtvar, *listvars, **kw): |
| 33 | import itertools |
| 34 | fmt = d.getVar(fmtvar, True) |
| 35 | lists = [listvar_to_list(d, x) for x in listvars] |
| 36 | lst = [fmt.format(*x) for x in itertools.product(*lists)] |
| 37 | return (kw.get('sep') or ' ').join(lst) |
| 38 | |
| 39 | |
| 40 | def compose_list_zip(d, fmtvar, *listvars, **kw): |
| 41 | fmt = d.getVar(fmtvar, True) |
| 42 | lists = [listvar_to_list(d, x) for x in listvars] |
| 43 | lst = [fmt.format(*x) for x in zip(*lists)] |
| 44 | return (kw.get('sep') or ' ').join(lst) |
Tom Joseph | 1562bbc | 2017-02-20 12:01:43 +0530 | [diff] [blame] | 45 | |
| 46 | |
| 47 | def append_suffix(val, suffix): |
| 48 | words = val.split(' ') |
| 49 | newval = [] |
| 50 | for w in words: |
| 51 | newval.append(w + suffix) |
Saqib Khan | dc2090d | 2017-03-07 07:05:56 -0600 | [diff] [blame] | 52 | return ' '.join(newval) |