diff options
| author | Steven Knight <knight@baldmt.com> | 2003-08-18 05:31:42 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2003-08-18 05:31:42 (GMT) |
| commit | e167fa6ca236dbe95f2a09a63a333436d50b3370 (patch) | |
| tree | d554fa51dad5d9266de417fc3433540da105951c /src/engine/SCons/Util.py | |
| parent | 1ad75c66814462db25110d30ca99f98b9caa6e1e (diff) | |
| download | SCons-e167fa6ca236dbe95f2a09a63a333436d50b3370.zip SCons-e167fa6ca236dbe95f2a09a63a333436d50b3370.tar.gz SCons-e167fa6ca236dbe95f2a09a63a333436d50b3370.tar.bz2 | |
Refactor DictCmdGenerator to be a subclass of Selector.
Diffstat (limited to 'src/engine/SCons/Util.py')
| -rw-r--r-- | src/engine/SCons/Util.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index cba61e5..3d3f563 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1006,3 +1006,32 @@ else: return path display = DisplayEngine() + +class Selector(UserDict.UserDict): + """A callable dictionary that maps file suffixes to dictionary + values.""" + def __call__(self, env, source): + ext = splitext(str(source[0]))[1] + try: + return self[ext] + except KeyError: + # Try to perform Environment substitution on the keys of + # emitter_dict before giving up. + s_dict = {} + for (k,v) in self.items(): + if not k is None: + s_k = env.subst(k) + if s_dict.has_key(s_k): + # We only raise an error when variables point + # to the same suffix. If one suffix is literal + # and a variable suffix contains this literal, + # the literal wins and we don't raise an error. + raise KeyError, (s_dict[s_k][0], k, s_k) + s_dict[s_k] = (k,v) + try: + return s_dict[ext][1] + except KeyError: + try: + return self[None] + except KeyError: + return None |
