Allow ListOption to take a Python list of values asa default, not just a comma-separa...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 20 Sep 2004 19:33:34 +0000 (19:33 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 20 Sep 2004 19:33:34 +0000 (19:33 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1088 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Options/ListOption.py
src/engine/SCons/Options/ListOptionTests.py
test/OptionsTypes.py

index c63a23a777b70ca303a7f8dbcde6391d5c726f1a..6399568fb43a9b8884c25538c5af4754c2e40b38 100644 (file)
@@ -7158,6 +7158,9 @@ or the values in the
 list.
 More than one value may be specified,
 with all values separated by commas.
+The default may be a string of
+comma-separated default values,
+or a list of the default values.
 
 .TP
 .RI PackageOption( key ", " help ", " default )
index 1d015109432eb20d52b75ff74e41449be12ccb6f..3fc014f3fce5dd192c5cd3ada0e9c83a64e35f2a 100644 (file)
@@ -57,6 +57,9 @@ RELEASE 0.97 - XXX
     so it prints a meaningful string, not the binary representation of
     the function contents.
 
+  - Allow a ListOption's default value(s) to be a Python list of specified
+    values, not just a string containing a comma-separated list of names.
+
   From Elliot Murphy:
 
   - Enhance the tests to guarantee persistence of ListOption
index 8a9403709f760036c9617c3b8b1d4ff1f1c5b847..903d52b180455d63bcd58942d50c033cf1df659b 100644 (file)
@@ -57,6 +57,8 @@ __all__ = ('ListOption',)
 import string
 import UserList
 
+import SCons.Util
+
 
 class _ListOption(UserList.UserList):
     def __init__(self, initlist=[], allowedElems=[]):
@@ -123,6 +125,8 @@ def ListOption(key, help, default, names):
     package names (separated by space).
     """
     names_str = 'allowed names: %s' % string.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    ')
index ec339630a7d1c61fe1719390e1aefedd0b275ddb..ec604f8123b45053fdc79d354422001429488e31 100644 (file)
@@ -44,6 +44,14 @@ class ListOptionTestCase(unittest.TestCase):
         assert o.validator is None, o.validator
         assert not o.converter is None, o.converter
 
+        opts = SCons.Options.Options()
+        opts.Add(SCons.Options.ListOption('test2', 'test2 help',
+                                          ['one', 'three'],
+                                          ['one', 'two', 'three']))
+
+        o = opts.options[0]
+        assert o.default == 'one,three'
+
     def test_converter(self):
         """Test the ListOption converter"""
         opts = SCons.Options.Options()
index 5fef2579be79557d9db46d901000376c0aca843c..41829053b774e170c2a22c197ae435c8d054ee41 100644 (file)
@@ -201,6 +201,27 @@ Invalid value(s) for option: foo,bar
 File "SConstruct", line 14, in ?
 """, status=2)
 
+test.write('SConstruct', """
+from SCons.Options import ListOption
+
+opts = Options(args=ARGUMENTS)
+opts.AddOptions(
+    ListOption('gpib',
+               'comment',
+               ['ENET', 'GPIB'],
+               names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']),
+    )
+
+env = Environment(options=opts)
+Help(opts.GenerateHelpText(env))
+
+print env['gpib']
+Default(env.Alias('dummy', None))
+""")
+
+test.run(stdout=test.wrap_stdout(read_str="ENET,GPIB\n", build_str="""\
+scons: Nothing to be done for `dummy'.
+"""))
 
 #### test PackageOption ####