1 """engine.SCons.Variables.ListVariable
3 This file defines the option type for SCons implementing 'lists'.
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
12 list_of_libs = Split('x11 gl qt ical')
15 opts.Add(ListVariable('shared',
16 'libraries to build as shared libraries',
18 elems = list_of_libs))
20 for lib in list_of_libs:
21 if lib in env['shared']:
28 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
30 # Permission is hereby granted, free of charge, to any person obtaining
31 # a copy of this software and associated documentation files (the
32 # "Software"), to deal in the Software without restriction, including
33 # without limitation the rights to use, copy, modify, merge, publish,
34 # distribute, sublicense, and/or sell copies of the Software, and to
35 # permit persons to whom the Software is furnished to do so, subject to
36 # the following conditions:
38 # The above copyright notice and this permission notice shall be included
39 # in all copies or substantial portions of the Software.
41 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
42 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
43 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
44 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
45 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
46 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
47 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 __revision__ = "src/engine/SCons/Variables/ListVariable.py 5023 2010/06/14 22:05:46 scons"
51 # Know Bug: This should behave like a Set-Type, but does not really,
52 # since elements can occur twice.
54 __all__ = ['ListVariable',]
61 class _ListVariable(collections.UserList):
62 def __init__(self, initlist=[], allowedElems=[]):
63 collections.UserList.__init__(self, [_f for _f in initlist if _f])
64 self.allowedElems = sorted(allowedElems)
66 def __cmp__(self, other):
67 raise NotImplementedError
68 def __eq__(self, other):
69 raise NotImplementedError
70 def __ge__(self, other):
71 raise NotImplementedError
72 def __gt__(self, other):
73 raise NotImplementedError
74 def __le__(self, other):
75 raise NotImplementedError
76 def __lt__(self, other):
77 raise NotImplementedError
82 if self.data == self.allowedElems:
86 def prepare_to_store(self):
89 def _converter(val, allowedElems, mapdict):
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]
101 raise ValueError("Invalid value(s) for option: %s" %
102 ','.join(notAllowed))
103 return _ListVariable(val, allowedElems)
106 ## def _validator(key, val, env):
109 ## # todo: write validater for pgk list
113 def ListVariable(key, help, default, names, map={}):
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() .
119 A 'package list' option may either be 'all', 'none' or a list of
120 package names (separated by space).
122 names_str = 'allowed names: %s' % ' '.join(names)
123 if SCons.Util.is_List(default):
124 default = ','.join(default)
126 (help, '(all|none|comma-separated list of names)', names_str))
127 return (key, help, default,
129 lambda val: _converter(val, names, map))
133 # indent-tabs-mode:nil
135 # vim: set expandtab tabstop=4 shiftwidth=4: