1 """engine.SCons.Variables.ListVariable
2
3 This file defines the option type for SCons implementing 'lists'.
4
5 A 'list' option may either be 'all', 'none' or a list of names
6 separated by comma. After the option has been processed, the option
7 value holds either the named list elements, all list elemens or no
8 list elements at all.
9
10 Usage example:
11
12 list_of_libs = Split('x11 gl qt ical')
13
14 opts = Variables()
15 opts.Add(ListVariable('shared',
16 'libraries to build as shared libraries',
17 'all',
18 elems = list_of_libs))
19 ...
20 for lib in list_of_libs:
21 if lib in env['shared']:
22 env.SharedObject(...)
23 else:
24 env.Object(...)
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 __revision__ = "src/engine/SCons/Variables/ListVariable.py rel_2.4.1:3453:73fefd3ea0b0 2015/11/09 03:25:05 bdbaddog"
50
51
52
53
54 __all__ = ['ListVariable',]
55
56 import collections
57
58 import SCons.Util
59
60
62 - def __init__(self, initlist=[], allowedElems=[]):
63 collections.UserList.__init__(self, [_f for _f in initlist if _f])
64 self.allowedElems = sorted(allowedElems)
65
67 raise NotImplementedError
69 raise NotImplementedError
71 raise NotImplementedError
73 raise NotImplementedError
75 raise NotImplementedError
77 raise NotImplementedError
79 if len(self) == 0:
80 return 'none'
81 self.data.sort()
82 if self.data == self.allowedElems:
83 return 'all'
84 else:
85 return ','.join(self)
88
90 """
91 """
92 if val == 'none':
93 val = []
94 elif val == 'all':
95 val = allowedElems
96 else:
97 val = [_f for _f in val.split(',') if _f]
98 val = [mapdict.get(v, v) for v in val]
99 notAllowed = [v for v in val if not v in allowedElems]
100 if notAllowed:
101 raise ValueError("Invalid value(s) for option: %s" %
102 ','.join(notAllowed))
103 return _ListVariable(val, allowedElems)
104
105
106
107
108
109
110
111
112
114 """
115 The input parameters describe a 'package list' option, thus they
116 are returned with the correct converter and validater appended. The
117 result is usable for input to opts.Add() .
118
119 A 'package list' option may either be 'all', 'none' or a list of
120 package names (separated by space).
121 """
122 names_str = 'allowed names: %s' % ' '.join(names)
123 if SCons.Util.is_List(default):
124 default = ','.join(default)
125 help = '\n '.join(
126 (help, '(all|none|comma-separated list of names)', names_str))
127 return (key, help, default,
128 None,
129 lambda val: _converter(val, names, map))
130
131
132
133
134
135
136