changeset 586:246f211c1328

0.6dev: Fixing some minor issues with Configuration: * Make option 'name' reserved in package configuration, see #422. * Configuration file only needs to include options to override, and not all options in a section.
author osimons
date Sat, 25 Jul 2009 00:16:14 +0000
parents 87de4513bfdd
children 0ac21e3343a4
files bitten/build/config.py bitten/build/tests/config.py
diffstat 2 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/build/config.py
+++ b/bitten/build/config.py
@@ -64,7 +64,7 @@
                    'family': ('os', 'family'),
                    'version': ('os', 'version')}
         for key, (section, option) in mapping.items():
-            if parser.has_section(section):
+            if parser.has_option(section, option):
                 value = parser.get(section, option)
                 if value is not None:
                     self.properties[key] = value
@@ -81,6 +81,10 @@
                 continue
             package = {}
             for option in parser.options(section):
+                if option == 'name':
+                    log.warning("Reserved configuration option 'name' used "
+                            "for package/section '%s'. Skipping." % section)
+                    continue
                 package[option] = parser.get(section, option)
             self.packages[section] = package
 
@@ -88,6 +92,10 @@
             for key, value in properties.items():
                 if '.' in key:
                     package, propname = key.split('.', 1)
+                    if propname == 'name':
+                        log.warning("Reserved configuration option 'name' "
+                                "used for property '%s'. Skipping." % key)
+                        continue
                     if package not in self.packages:
                         self.packages[package] = {}
                     self.packages[package][propname] = value
--- a/bitten/build/tests/config.py
+++ b/bitten/build/tests/config.py
@@ -68,14 +68,39 @@
         finally:
             os.remove(ininame)
 
+    def test_sysinfo_configfile_partial_override(self):
+        inifd, ininame = tempfile.mkstemp(prefix='bitten_test')
+        try:
+            os.write(inifd, """
+[machine]
+name = MACHINE
+
+[os]
+name = OS
+""")
+            os.close(inifd)
+            config = Configuration(ininame)
+
+            self.assertEqual('MACHINE', config['machine'])
+            self.assertEqual('OS', config['os'])
+            # Make sure other options are set to some default value
+            self.failUnless(config['processor'])
+            self.failUnless(config['family'])
+            self.failUnless(config['version'])
+        finally:
+            os.remove(ininame)
+
     def test_package_properties(self):
         config = Configuration(properties={
             'python.version': '2.3.5',
-            'python.path': '/usr/local/bin/python2.3'
+            'python.path': '/usr/local/bin/python2.3',
+            'python.name': 'invalid option'
         })
         self.assertEqual(True, 'python' in config.packages)
         self.assertEqual('/usr/local/bin/python2.3', config['python.path'])
         self.assertEqual('2.3.5', config['python.version'])
+        self.failIf('name' in config.packages['python'],
+                        "Invalid option 'name' should not be included...")
 
     def test_package_configfile(self):
         inifd, ininame = tempfile.mkstemp(prefix='bitten_test')
@@ -84,6 +109,7 @@
 [python]
 path = /usr/local/bin/python2.3
 version = 2.3.5
+name = invalid option
 """)
             os.close(inifd)
             config = Configuration(ininame)
@@ -91,6 +117,8 @@
             self.assertEqual(True, 'python' in config.packages)
             self.assertEqual('/usr/local/bin/python2.3', config['python.path'])
             self.assertEqual('2.3.5', config['python.version'])
+            self.failIf('name' in config.packages['python'],
+                        "Invalid option 'name' should not be included...")
         finally:
             os.remove(ininame)
 
Copyright (C) 2012-2017 Edgewall Software