[Treepkg-commits] r184 - trunk/treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Apr 17 20:48:59 CEST 2009
Author: bh
Date: 2009-04-17 20:48:58 +0200 (Fri, 17 Apr 2009)
New Revision: 184
Modified:
trunk/treepkg/readconfig.py
Log:
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.
Modified: trunk/treepkg/readconfig.py
===================================================================
--- trunk/treepkg/readconfig.py 2009-04-16 17:10:41 UTC (rev 183)
+++ trunk/treepkg/readconfig.py 2009-04-17 18:48:58 UTC (rev 184)
@@ -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
More information about the Treepkg-commits
mailing list