Mercurial > treepkg > treepkg
view treepkg/readconfig.py @ 0:f78a02e79c84
initial checkin
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 06 Mar 2007 17:37:32 +0100 |
parents | |
children | e6a9f4037f68 |
line wrap: on
line source
# Copyright (C) 2007 by Intevation GmbH # Authors: # Bernhard Herzog <bh@intevation.de> # # This program is free software under the GPL (>=v2) # Read the file COPYING coming with the software for details. """Reads the configuration file""" import sys from ConfigParser import SafeConfigParser, NoOptionError assembly_line_keys = ["name", "base_dir", "svn_url", "root_cmd", "deb_email", "deb_fullname"] defaults = dict(root_cmd="sudo") def read_config(filename): """Reads the packagemill configuration from filename. The return value is a list of (name, option) pairs, one for each assembly line of the mill. """ assembly_lines = [] parser = SafeConfigParser(defaults) parser.read([filename]) for section in parser.sections(): if section.startswith("pkg_"): pkg_defaults = dict(name=section[4:]) options = {} for key in assembly_line_keys: try: options[key] = parser.get(section, key, vars=pkg_defaults) except NoOptionError: print >>sys.stderr, "%s: Missing option %r in section %r" \ % (filename, key, section) sys.exit(1) assembly_lines.append(options) treepkg_opts = dict(check_interval=parser.getint("treepkg", "check_interval")) return treepkg_opts, assembly_lines if __name__ == "__main__": print read_config(sys.argv[1])