Mercurial > treepkg > treepkg
annotate treepkg/readconfig.py @ 52:78cf5f6778ec
Rename 'packagel ine' -> 'package track'
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 03 Apr 2007 20:33:33 +0200 |
parents | 2802be410156 |
children | 3ed079a7174a |
rev | line source |
---|---|
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 | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
11 import shlex |
0 | 12 from ConfigParser import SafeConfigParser, NoOptionError |
13 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
14 import util |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
15 |
0 | 16 defaults = dict(root_cmd="sudo") |
17 | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
18 packager_desc = [ |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
19 "name", "base_dir", "svn_url", "packager_class", |
47
2802be410156
add config options pbuilderrc and use it when calling pbuilder
Bernhard Herzog <bh@intevation.de>
parents:
17
diff
changeset
|
20 ("root_cmd", shlex.split), "pbuilderrc", |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
21 "deb_email", "deb_fullname", |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
22 ] |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
23 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
24 treepkg_desc = [ |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
25 ("check_interval", int), |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
26 ] |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
27 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
28 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
29 def read_config_section(parser, section, item_desc, defaults=None): |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
30 if defaults is None: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
31 defaults = dict() |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
32 options = dict() |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
33 for item in item_desc: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
34 if isinstance(item, tuple): |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
35 key, converter = item |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
36 else: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
37 key = item |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
38 converter = str |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
39 try: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
40 value = parser.get(section, key, vars=defaults) |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
41 options[key] = converter(value) |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
42 except NoOptionError: |
17
6ced445aa090
filename is not available for read config error message
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
43 print >>sys.stderr, "Missing option %r in section %r" \ |
6ced445aa090
filename is not available for read config error message
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
44 % (key, section) |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
45 sys.exit(1) |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
46 return options |
0 | 47 |
48 | |
49 def read_config(filename): | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
50 """Reads the tree packager configuration from the file given by filename. |
0 | 51 |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
52 The function returns a tuple with a ('treepkg') and a list of dicts |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
53 ('packagers'). The treepkg dict contains the main configuration of |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
54 the tree packager. The packagers list contains one dict with the |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
55 configuratiin for each packager. |
0 | 56 """ |
57 parser = SafeConfigParser(defaults) | |
58 parser.read([filename]) | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
59 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
60 # extract packager configurations |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
61 packagers = [] |
0 | 62 for section in parser.sections(): |
63 if section.startswith("pkg_"): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
64 packager_class = parser.get(section, "packager_class") |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
65 module = util.import_dotted_name(packager_class) |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
47
diff
changeset
|
66 desc = packager_desc + module.PackageTrack.extra_config_desc |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
67 packagers.append(read_config_section(parser, section, desc, |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
68 dict(name=section[4:]))) |
0 | 69 |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
70 # main config |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
71 treepkg = read_config_section(parser, "treepkg", treepkg_desc) |
0 | 72 |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
73 return treepkg, packagers |
0 | 74 |
75 | |
76 if __name__ == "__main__": | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
77 import pprint |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
78 print pprint.pprint(read_config(sys.argv[1])) |