summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/classes/obmc-phosphor-utils.bbclass
blob: baaa19d57e6f1003e51ee4061ca3dbe51821eef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Helper functions for checking feature variables.

inherit utils


def df_enabled(d, feature, truevalue, falsevalue=""):
    return base_contains("DISTRO_FEATURES", feature, truevalue, falsevalue, d)


def mf_enabled(d, feature, truevalue, falsevalue=""):
    return base_contains("MACHINE_FEATURES", feature, truevalue, falsevalue, d)


def cf_enabled(d, feature, truevalue, falsevalue=""):
    return truevalue if df_enabled(d, feature, truevalue) \
        and mf_enabled(d, feature, truevalue) \
            else falsevalue


def set_append(d, var, val, sep=' '):
    values = (d.getVar(var, True) or '').split(sep)
    if filter(bool, values):
        d.appendVar(var, '%s%s' %(sep, val))
    else:
        d.setVar(var, val)


def listvar_to_list(d, list_var, sep=' '):
    return filter(bool, (d.getVar(list_var, True) or '').split(sep))


def compose_list(d, fmtvar, *listvars, **kw):
    import itertools
    fmt = d.getVar(fmtvar, True)
    lists = [listvar_to_list(d, x) for x in listvars]
    lst = [fmt.format(*x) for x in itertools.product(*lists)]
    return (kw.get('sep') or ' ').join(lst)


def compose_list_zip(d, fmtvar, *listvars, **kw):
    fmt = d.getVar(fmtvar, True)
    lists = [listvar_to_list(d, x) for x in listvars]
    lst = [fmt.format(*x) for x in zip(*lists)]
    return (kw.get('sep') or ' ').join(lst)


def append_suffix(val, suffix):
    words = val.split(' ')
    newval = []
    for w in words:
        newval.append(w + suffix)
    return ' '.join(newval)
OpenPOWER on IntegriCloud