Make env['FOO'] by shorthand for env.Dictionary()['FOO'] (Anthony Roach)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 22 Mar 2002 17:21:00 +0000 (17:21 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 22 Mar 2002 17:21:00 +0000 (17:21 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@302 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py

index 5d8a0a5ae3aa2d0b5bb5116c488bb9c216ccaf7e..16c5e6b4819dd591ae589962a8c1c087203f7d28 100644 (file)
@@ -994,6 +994,12 @@ dict = env.Dictionary()
 dict["CC"] = "cc"
 .EE
 
+or using the [] operator:
+
+.ES
+env["CC"] = "cc"
+.EE
+
 Construction variables can also be passed to the construction environment
 constructor:
 
index d997d6f5a2fd2d404fa26ef3ad67cbea863bda10..65af179e5632faf37a158ff68568c12e3c4c07b2 100644 (file)
@@ -227,6 +227,15 @@ class Environment:
            dlist = dlist[0]
        return dlist
 
+    def __setitem__(self, key, value):
+        self._dict[key] = value
+
+    def __getitem__(self, key):
+        return self._dict[key]
+
+    def __delitem__(self, key):
+        del self._dict[key]
+
     def Command(self, target, source, action):
         """Builds the supplied target files from the supplied
         source files using the supplied action.  Action may
index 86f179a511712673787323c8c8f96c361253d15e..654d432f09c7ab90483f08e6fe901dcf39632070 100644 (file)
@@ -195,6 +195,12 @@ class EnvironmentTestCase(unittest.TestCase):
        assert env.Dictionary().has_key('CCFLAGS')
        assert env.Dictionary().has_key('ENV')
 
+       assert env['XXX'] == 'x'
+       env['XXX'] = 'foo'
+       assert env.Dictionary('XXX') == 'foo'
+       del env['XXX']
+       assert not env.Dictionary().has_key('XXX')
+
     def test_ENV(self):
        """Test setting the external ENV in Environments
        """