blob: b0f1fafc008e82ab5d4ba180f097d29216815e99 [file] [log] [blame]
Patrick Williams12fc9392021-08-06 09:16:53 -05001def set_doappend(d, var, val, sep=' '):
Brad Bishop9dc56712016-07-07 15:56:02 -04002 values = (d.getVar(var, True) or '').split(sep)
3 if filter(bool, values):
4 d.appendVar(var, '%s%s' %(sep, val))
5 else:
6 d.setVar(var, val)
7
8
9def listvar_to_list(d, list_var, sep=' '):
Saqib Khandc2090d2017-03-07 07:05:56 -060010 return list(filter(bool, (d.getVar(list_var, True) or '').split(sep)))
Brad Bishop167aaae2016-08-24 14:08:35 -040011
12
13def compose_list(d, fmtvar, *listvars, **kw):
14 import itertools
15 fmt = d.getVar(fmtvar, True)
16 lists = [listvar_to_list(d, x) for x in listvars]
17 lst = [fmt.format(*x) for x in itertools.product(*lists)]
18 return (kw.get('sep') or ' ').join(lst)
19
20
21def compose_list_zip(d, fmtvar, *listvars, **kw):
22 fmt = d.getVar(fmtvar, True)
23 lists = [listvar_to_list(d, x) for x in listvars]
24 lst = [fmt.format(*x) for x in zip(*lists)]
25 return (kw.get('sep') or ' ').join(lst)