changeset 258:bb98e728f25b

Allow default values for individual options to be passed to read_config_section. The default value can now be passed as a third item in a tuple used in the section description passed to read_config_section. The predefined option descriptions have been updated to use this new mechanism and the global defaults variable is not needed anymore. Also, indivdual PackageTrack classes can now use this mechanism to specify defaults for their additional configuration options.
author Bernhard Herzog <bh@intevation.de>
date Fri, 17 Apr 2009 18:48:58 +0000
parents ab752c4d0786
children 27824d3add92
files treepkg/readconfig.py
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/readconfig.py	Thu Apr 16 17:10:41 2009 +0000
+++ b/treepkg/readconfig.py	Fri Apr 17 18:48:58 2009 +0000
@@ -22,16 +22,13 @@
         return False
     raise ValueError("cannot determine boolean value of %r" % (s,))
 
-defaults = dict(root_cmd="sudo",
-                signing_key_id="",
-                rules_svn_url="")
 
 packager_desc = [
-    "name", "base_dir", "svn_url", "rules_svn_url", "packager_class",
-    ("root_cmd", shlex.split), "pbuilderrc",
+    "name", "base_dir", "svn_url", ("rules_svn_url", str, ""), "packager_class",
+    ("root_cmd", shlex.split, "sudo"), "pbuilderrc",
     "deb_email", "deb_fullname", "debrevision_prefix",
     ("handle_dependencies", convert_bool),
-    "signing_key_id",
+    ("signing_key_id", str, ""),
     ]
 
 treepkg_desc = [
@@ -45,18 +42,25 @@
         defaults = dict()
     options = dict()
     for item in item_desc:
+        has_default_value = False
         if isinstance(item, tuple):
-            key, converter = item
+            key, converter = item[:2]
+            if len(item) == 3:
+                default_value = item[-1]
+                has_default_value = True
         else:
             key = item
             converter = str
         try:
             value = parser.get(section, key, vars=defaults)
-            options[key] = converter(value)
         except NoOptionError:
-            print >>sys.stderr, "Missing option %r in section %r" \
-                  % (key, section)
-            sys.exit(1)
+            if has_default_value:
+                value = default_value
+            else:
+                print >>sys.stderr, "Missing option %r in section %r" \
+                      % (key, section)
+                sys.exit(1)
+        options[key] = converter(value)
     return options
 
 
@@ -68,7 +72,7 @@
     configuration of the tree packager.  The packagers list contains one
     dict with the configuratiin for each packager.
     """
-    parser = SafeConfigParser(defaults)
+    parser = SafeConfigParser()
     parser.read([filename])
 
     # extract packager configurations
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)