summaryrefslogtreecommitdiff
path: root/engine/SCons/Variables
diff options
context:
space:
mode:
Diffstat (limited to 'engine/SCons/Variables')
-rw-r--r--engine/SCons/Variables/BoolVariable.py6
-rw-r--r--engine/SCons/Variables/EnumVariable.py22
-rw-r--r--engine/SCons/Variables/ListVariable.py34
-rw-r--r--engine/SCons/Variables/PackageVariable.py13
-rw-r--r--engine/SCons/Variables/PathVariable.py4
-rw-r--r--engine/SCons/Variables/__init__.py53
6 files changed, 57 insertions, 75 deletions
diff --git a/engine/SCons/Variables/BoolVariable.py b/engine/SCons/Variables/BoolVariable.py
index c002fb9..2eeda77 100644
--- a/engine/SCons/Variables/BoolVariable.py
+++ b/engine/SCons/Variables/BoolVariable.py
@@ -34,12 +34,10 @@ Usage example:
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Variables/BoolVariable.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/Variables/BoolVariable.py 5023 2010/06/14 22:05:46 scons"
__all__ = ['BoolVariable',]
-import string
-
import SCons.Errors
__true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' )
@@ -57,7 +55,7 @@ def _text2bool(val):
This is usable as 'converter' for SCons' Variables.
"""
- lval = string.lower(val)
+ lval = val.lower()
if lval in __true_strings: return True
if lval in __false_strings: return False
raise ValueError("Invalid value for boolean option: %s" % val)
diff --git a/engine/SCons/Variables/EnumVariable.py b/engine/SCons/Variables/EnumVariable.py
index 2051bf1..9ae93fb 100644
--- a/engine/SCons/Variables/EnumVariable.py
+++ b/engine/SCons/Variables/EnumVariable.py
@@ -37,11 +37,10 @@ Usage example:
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Variables/EnumVariable.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/Variables/EnumVariable.py 5023 2010/06/14 22:05:46 scons"
__all__ = ['EnumVariable',]
-import string
import SCons.Errors
@@ -80,24 +79,21 @@ def EnumVariable(key, help, default, allowed_values, map={}, ignorecase=0):
given 'map'-dictionary (unmapped input values are returned
unchanged).
"""
- help = '%s (%s)' % (help, string.join(allowed_values, '|'))
+ help = '%s (%s)' % (help, '|'.join(allowed_values))
# define validator
if ignorecase >= 1:
- validator = lambda key, val, env, vals=allowed_values: \
- _validator(key, string.lower(val), env, vals)
+ validator = lambda key, val, env: \
+ _validator(key, val.lower(), env, allowed_values)
else:
- validator = lambda key, val, env, vals=allowed_values: \
- _validator(key, val, env, vals)
+ validator = lambda key, val, env: \
+ _validator(key, val, env, allowed_values)
# define converter
if ignorecase == 2:
- converter = lambda val, map=map: \
- string.lower(map.get(string.lower(val), val))
+ converter = lambda val: map.get(val.lower(), val).lower()
elif ignorecase == 1:
- converter = lambda val, map=map: \
- map.get(string.lower(val), val)
+ converter = lambda val: map.get(val.lower(), val)
else:
- converter = lambda val, map=map: \
- map.get(val, val)
+ converter = lambda val: map.get(val, val)
return (key, help, default, validator, converter)
# Local Variables:
diff --git a/engine/SCons/Variables/ListVariable.py b/engine/SCons/Variables/ListVariable.py
index 3ed755f..dbd5f4b 100644
--- a/engine/SCons/Variables/ListVariable.py
+++ b/engine/SCons/Variables/ListVariable.py
@@ -45,26 +45,23 @@ Usage example:
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-__revision__ = "src/engine/SCons/Variables/ListVariable.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/Variables/ListVariable.py 5023 2010/06/14 22:05:46 scons"
# Know Bug: This should behave like a Set-Type, but does not really,
# since elements can occur twice.
__all__ = ['ListVariable',]
-import string
-import UserList
+import collections
import SCons.Util
-class _ListVariable(UserList.UserList):
+class _ListVariable(collections.UserList):
def __init__(self, initlist=[], allowedElems=[]):
- UserList.UserList.__init__(self, filter(None, initlist))
- self.allowedElems = allowedElems[:]
- self.allowedElems.sort()
+ collections.UserList.__init__(self, [_f for _f in initlist if _f])
+ self.allowedElems = sorted(allowedElems)
def __cmp__(self, other):
raise NotImplementedError
@@ -85,7 +82,7 @@ class _ListVariable(UserList.UserList):
if self.data == self.allowedElems:
return 'all'
else:
- return string.join(self, ',')
+ return ','.join(self)
def prepare_to_store(self):
return self.__str__()
@@ -97,12 +94,12 @@ def _converter(val, allowedElems, mapdict):
elif val == 'all':
val = allowedElems
else:
- val = filter(None, string.split(val, ','))
- val = map(lambda v, m=mapdict: m.get(v, v), val)
- notAllowed = filter(lambda v, aE=allowedElems: not v in aE, val)
+ val = [_f for _f in val.split(',') if _f]
+ val = [mapdict.get(v, v) for v in val]
+ notAllowed = [v for v in val if not v in allowedElems]
if notAllowed:
raise ValueError("Invalid value(s) for option: %s" %
- string.join(notAllowed, ','))
+ ','.join(notAllowed))
return _ListVariable(val, allowedElems)
@@ -122,15 +119,14 @@ def ListVariable(key, help, default, names, map={}):
A 'package list' option may either be 'all', 'none' or a list of
package names (separated by space).
"""
- names_str = 'allowed names: %s' % string.join(names, ' ')
+ names_str = 'allowed names: %s' % ' '.join(names)
if SCons.Util.is_List(default):
- default = string.join(default, ',')
- help = string.join(
- (help, '(all|none|comma-separated list of names)', names_str),
- '\n ')
+ default = ','.join(default)
+ help = '\n '.join(
+ (help, '(all|none|comma-separated list of names)', names_str))
return (key, help, default,
None, #_validator,
- lambda val, elems=names, m=map: _converter(val, elems, m))
+ lambda val: _converter(val, names, map))
# Local Variables:
# tab-width:4
diff --git a/engine/SCons/Variables/PackageVariable.py b/engine/SCons/Variables/PackageVariable.py
index 362f67e..d9ce2a6 100644
--- a/engine/SCons/Variables/PackageVariable.py
+++ b/engine/SCons/Variables/PackageVariable.py
@@ -50,12 +50,10 @@ Usage example:
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Variables/PackageVariable.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/Variables/PackageVariable.py 5023 2010/06/14 22:05:46 scons"
__all__ = ['PackageVariable',]
-import string
-
import SCons.Errors
__enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search')
@@ -64,7 +62,7 @@ __disable_strings = ('0', 'no', 'false', 'off', 'disable')
def _converter(val):
"""
"""
- lval = string.lower(val)
+ lval = val.lower()
if lval in __enable_strings: return True
if lval in __disable_strings: return False
#raise ValueError("Invalid value for boolean option: %s" % val)
@@ -95,11 +93,10 @@ def PackageVariable(key, help, default, searchfunc=None):
A 'package list' option may either be 'all', 'none' or a list of
package names (seperated by space).
"""
- help = string.join(
- (help, '( yes | no | /path/to/%s )' % key),
- '\n ')
+ help = '\n '.join(
+ (help, '( yes | no | /path/to/%s )' % key))
return (key, help, default,
- lambda k, v, e, f=searchfunc: _validator(k,v,e,f),
+ lambda k, v, e: _validator(k,v,e,searchfunc),
_converter)
# Local Variables:
diff --git a/engine/SCons/Variables/PathVariable.py b/engine/SCons/Variables/PathVariable.py
index 4af9fc3..445cfe2 100644
--- a/engine/SCons/Variables/PathVariable.py
+++ b/engine/SCons/Variables/PathVariable.py
@@ -68,7 +68,7 @@ Usage example:
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Variables/PathVariable.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/Variables/PathVariable.py 5023 2010/06/14 22:05:46 scons"
__all__ = ['PathVariable',]
@@ -77,7 +77,7 @@ import os.path
import SCons.Errors
-class _PathVariableClass:
+class _PathVariableClass(object):
def PathAccept(self, key, val, env):
"""Accepts any path, no checking done."""
diff --git a/engine/SCons/Variables/__init__.py b/engine/SCons/Variables/__init__.py
index 8840b97..d8562b0 100644
--- a/engine/SCons/Variables/__init__.py
+++ b/engine/SCons/Variables/__init__.py
@@ -25,12 +25,10 @@ customizable variables to an SCons build.
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-__revision__ = "src/engine/SCons/Variables/__init__.py 4720 2010/03/24 03:14:11 jars"
+__revision__ = "src/engine/SCons/Variables/__init__.py 5023 2010/06/14 22:05:46 scons"
import os.path
-import string
import sys
import SCons.Environment
@@ -45,7 +43,7 @@ from PackageVariable import PackageVariable # naja
from PathVariable import PathVariable # okay
-class Variables:
+class Variables(object):
instance=None
"""
@@ -76,7 +74,7 @@ class Variables:
Variables.instance=self
def _do_add(self, key, help="", default=None, validator=None, converter=None):
- class Variable:
+ class Variable(object):
pass
option = Variable()
@@ -84,11 +82,11 @@ class Variables:
# if we get a list or a tuple, we take the first element as the
# option key and store the remaining in aliases.
if SCons.Util.is_List(key) or SCons.Util.is_Tuple(key):
- option.key = key[0]
- option.aliases = key[1:]
+ option.key = key[0]
+ option.aliases = key[1:]
else:
- option.key = key
- option.aliases = [ key ]
+ option.key = key
+ option.aliases = [ key ]
option.help = help
option.default = default
option.validator = validator
@@ -99,16 +97,14 @@ class Variables:
# options might be added after the 'unknown' dict has been set up,
# so we remove the key and all its aliases from that dict
for alias in list(option.aliases) + [ option.key ]:
- # TODO(1.5)
- #if alias in self.unknown:
- if alias in self.unknown.keys():
- del self.unknown[alias]
+ if alias in self.unknown:
+ del self.unknown[alias]
def keys(self):
"""
Returns the keywords for the options
"""
- return map(lambda o: o.key, self.options)
+ return [o.key for o in self.options]
def Add(self, key, help="", default=None, validator=None, converter=None, **kw):
"""
@@ -123,13 +119,13 @@ class Variables:
putting it in the environment.
"""
- if SCons.Util.is_List(key) or type(key) == type(()):
- apply(self._do_add, key)
+ if SCons.Util.is_List(key) or isinstance(key, tuple):
+ self._do_add(*key)
return
if not SCons.Util.is_String(key) or \
- not SCons.Environment.is_valid_construction_var(key):
- raise SCons.Errors.UserError, "Illegal Variables.Add() key `%s'" % str(key)
+ not SCons.Environment.is_valid_construction_var(key):
+ raise SCons.Errors.UserError("Illegal Variables.Add() key `%s'" % str(key))
self._do_add(key, help, default, validator, converter)
@@ -149,7 +145,7 @@ class Variables:
)
"""
for o in optlist:
- apply(self._do_add, o)
+ self._do_add(*o)
def Update(self, env, args=None):
@@ -203,7 +199,7 @@ class Variables:
# Call the convert functions:
for option in self.options:
- if option.converter and values.has_key(option.key):
+ if option.converter and option.key in values:
value = env.subst('${%s}'%option.key)
try:
try:
@@ -211,12 +207,12 @@ class Variables:
except TypeError:
env[option.key] = option.converter(value, env)
except ValueError, x:
- raise SCons.Errors.UserError, 'Error converting option: %s\n%s'%(option.key, x)
+ raise SCons.Errors.UserError('Error converting option: %s\n%s'%(option.key, x))
# Finally validate the values:
for option in self.options:
- if option.validator and values.has_key(option.key):
+ if option.validator and option.key in values:
option.validator(option.key, env.subst('${%s}'%option.key), env)
def UnknownVariables(self):
@@ -273,7 +269,7 @@ class Variables:
fh.close()
except IOError, x:
- raise SCons.Errors.UserError, 'Error writing options to file: %s\n%s' % (filename, x)
+ raise SCons.Errors.UserError('Error writing options to file: %s\n%s' % (filename, x))
def GenerateHelpText(self, env, sort=None):
"""
@@ -284,27 +280,26 @@ class Variables:
"""
if sort:
- options = self.options[:]
- options.sort(lambda x,y,func=sort: func(x.key,y.key))
+ options = sorted(self.options, key=lambda x: x.key)
else:
options = self.options
def format(opt, self=self, env=env):
- if env.has_key(opt.key):
+ if opt.key in env:
actual = env.subst('${%s}' % opt.key)
else:
actual = None
return self.FormatVariableHelpText(env, opt.key, opt.help, opt.default, actual, opt.aliases)
- lines = filter(None, map(format, options))
+ lines = [_f for _f in map(format, options) if _f]
- return string.join(lines, '')
+ return ''.join(lines)
format = '\n%s: %s\n default: %s\n actual: %s\n'
format_ = '\n%s: %s\n default: %s\n actual: %s\n aliases: %s\n'
def FormatVariableHelpText(self, env, key, help, default, actual, aliases=[]):
# Don't display the key name itself as an alias.
- aliases = filter(lambda a, k=key: a != k, aliases)
+ aliases = [a for a in aliases if a != key]
if len(aliases)==0:
return self.format % (key, help, default, actual)
else: