bh@0: # Copyright (C) 2007 by Intevation GmbH bh@0: # Authors: bh@0: # Bernhard Herzog bh@0: # bh@0: # This program is free software under the GPL (>=v2) bh@0: # Read the file COPYING coming with the software for details. bh@0: bh@0: """Reads the configuration file""" bh@0: bh@0: import sys bh@0: from ConfigParser import SafeConfigParser, NoOptionError bh@0: bh@0: bh@0: assembly_line_keys = ["name", "base_dir", "svn_url", "root_cmd", bh@0: "deb_email", "deb_fullname"] bh@0: bh@0: defaults = dict(root_cmd="sudo") bh@0: bh@0: bh@0: bh@0: def read_config(filename): bh@0: """Reads the packagemill configuration from filename. bh@0: bh@0: The return value is a list of (name, option) pairs, one for each bh@0: assembly line of the mill. bh@0: """ bh@0: assembly_lines = [] bh@0: parser = SafeConfigParser(defaults) bh@0: parser.read([filename]) bh@0: for section in parser.sections(): bh@0: if section.startswith("pkg_"): bh@0: pkg_defaults = dict(name=section[4:]) bh@0: options = {} bh@0: for key in assembly_line_keys: bh@0: try: bh@0: options[key] = parser.get(section, key, vars=pkg_defaults) bh@0: except NoOptionError: bh@0: print >>sys.stderr, "%s: Missing option %r in section %r" \ bh@0: % (filename, key, section) bh@0: sys.exit(1) bh@0: assembly_lines.append(options) bh@0: bh@0: treepkg_opts = dict(check_interval=parser.getint("treepkg", bh@0: "check_interval")) bh@0: bh@0: return treepkg_opts, assembly_lines bh@0: bh@0: bh@0: if __name__ == "__main__": bh@0: print read_config(sys.argv[1])