1 """engine.SCons.Variables.BoolVariable
2
3 This file defines the option type for SCons implementing true/false values.
4
5 Usage example:
6
7 opts = Variables()
8 opts.Add(BoolVariable('embedded', 'build for an embedded system', 0))
9 ...
10 if env['embedded'] == 1:
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 __revision__ = "src/engine/SCons/Variables/BoolVariable.py 5110 2010/07/25 16:14:38 bdeegan"
38
39 __all__ = ['BoolVariable',]
40
41 import string
42
43 import SCons.Errors
44
45 __true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' )
46 __false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
47
48
50 """
51 Converts strings to True/False depending on the 'truth' expressed by
52 the string. If the string can't be converted, the original value
53 will be returned.
54
55 See '__true_strings' and '__false_strings' for values considered
56 'true' or 'false respectivly.
57
58 This is usable as 'converter' for SCons' Variables.
59 """
60 lval = string.lower(val)
61 if lval in __true_strings: return True
62 if lval in __false_strings: return False
63 raise ValueError("Invalid value for boolean option: %s" % val)
64
65
67 """
68 Validates the given value to be either '0' or '1'.
69
70 This is usable as 'validator' for SCons' Variables.
71 """
72 if not env[key] in (True, False):
73 raise SCons.Errors.UserError(
74 'Invalid value for boolean option %s: %s' % (key, env[key]))
75
76
78 """
79 The input parameters describe a boolen option, thus they are
80 returned with the correct converter and validator appended. The
81 'help' text will by appended by '(yes|no) to show the valid
82 valued. The result is usable for input to opts.Add().
83 """
84 return (key, '%s (yes|no)' % help, default,
85 _validator, _text2bool)
86
87
88
89
90
91
92