0
|
1 # Copyright (C) 2007 by Intevation GmbH |
|
2 # Authors: |
|
3 # Bernhard Herzog <bh@intevation.de> |
|
4 # |
|
5 # This program is free software under the GPL (>=v2) |
|
6 # Read the file COPYING coming with the software for details. |
|
7 |
|
8 """Reads the configuration file""" |
|
9 |
|
10 import sys |
|
11 from ConfigParser import SafeConfigParser, NoOptionError |
|
12 |
|
13 |
|
14 assembly_line_keys = ["name", "base_dir", "svn_url", "root_cmd", |
|
15 "deb_email", "deb_fullname"] |
|
16 |
|
17 defaults = dict(root_cmd="sudo") |
|
18 |
|
19 |
|
20 |
|
21 def read_config(filename): |
|
22 """Reads the packagemill configuration from filename. |
|
23 |
|
24 The return value is a list of (name, option) pairs, one for each |
|
25 assembly line of the mill. |
|
26 """ |
|
27 assembly_lines = [] |
|
28 parser = SafeConfigParser(defaults) |
|
29 parser.read([filename]) |
|
30 for section in parser.sections(): |
|
31 if section.startswith("pkg_"): |
|
32 pkg_defaults = dict(name=section[4:]) |
|
33 options = {} |
|
34 for key in assembly_line_keys: |
|
35 try: |
|
36 options[key] = parser.get(section, key, vars=pkg_defaults) |
|
37 except NoOptionError: |
|
38 print >>sys.stderr, "%s: Missing option %r in section %r" \ |
|
39 % (filename, key, section) |
|
40 sys.exit(1) |
|
41 assembly_lines.append(options) |
|
42 |
|
43 treepkg_opts = dict(check_interval=parser.getint("treepkg", |
|
44 "check_interval")) |
|
45 |
|
46 return treepkg_opts, assembly_lines |
|
47 |
|
48 |
|
49 if __name__ == "__main__": |
|
50 print read_config(sys.argv[1]) |