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
50 __revision__ = "src/engine/SCons/Variables/ListVariable.py 5110 2010/07/25 16:14:38 bdeegan"
51
52
53
54
55 __all__ = ['ListVariable',]
56
57 import string
58 import UserList
59
60 import SCons.Util
61
62
64 - def __init__(self, initlist=[], allowedElems=[]):
65 UserList.UserList.__init__(self, filter(None, initlist))
66 self.allowedElems = allowedElems[:]
67 self.allowedElems.sort()
68
70 raise NotImplementedError
72 raise NotImplementedError
74 raise NotImplementedError
76 raise NotImplementedError
78 raise NotImplementedError
80 raise NotImplementedError
82 if len(self) == 0:
83 return 'none'
84 self.data.sort()
85 if self.data == self.allowedElems:
86 return 'all'
87 else:
88 return string.join(self, ',')
91
93 """
94 """
95 if val == 'none':
96 val = []
97 elif val == 'all':
98 val = allowedElems
99 else:
100 val = filter(None, string.split(val, ','))
101 val = map(lambda v, m=mapdict: m.get(v, v), val)
102 notAllowed = filter(lambda v, aE=allowedElems: not v in aE, val)
103 if notAllowed:
104 raise ValueError("Invalid value(s) for option: %s" %
105 string.join(notAllowed, ','))
106 return _ListVariable(val, allowedElems)
107
108
109
110
111
112
113
114
115
117 """
118 The input parameters describe a 'package list' option, thus they
119 are returned with the correct converter and validater appended. The
120 result is usable for input to opts.Add() .
121
122 A 'package list' option may either be 'all', 'none' or a list of
123 package names (separated by space).
124 """
125 names_str = 'allowed names: %s' % string.join(names, ' ')
126 if SCons.Util.is_List(default):
127 default = string.join(default, ',')
128 help = string.join(
129 (help, '(all|none|comma-separated list of names)', names_str),
130 '\n ')
131 return (key, help, default,
132 None,
133 lambda val, elems=names, m=map: _converter(val, elems, m))
134
135
136
137
138
139
140