Mercurial > treepkg > treepkg
annotate treepkg/readconfig.py @ 115:d7b53e7df961
Fix doc-string
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 01 Apr 2008 14:47:36 +0000 |
parents | 02c261e4443f |
children | ce9f046058b5 |
rev | line source |
---|---|
114
02c261e4443f
Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
1 # Copyright (C) 2007, 2008 by Intevation GmbH |
0 | 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 |
114
02c261e4443f
Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
15 import packager |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
16 |
0 | 17 defaults = dict(root_cmd="sudo") |
18 | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
19 packager_desc = [ |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
20 "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
|
21 ("root_cmd", shlex.split), "pbuilderrc", |
93
73c67372c7f7
Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents:
91
diff
changeset
|
22 "deb_email", "deb_fullname", "debrevision_prefix", |
2
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 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
25 treepkg_desc = [ |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
26 ("check_interval", int), |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
27 "instructions_file", |
2
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 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
30 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
31 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
|
32 if defaults is None: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
33 defaults = dict() |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
34 options = dict() |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
35 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
|
36 if isinstance(item, tuple): |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
37 key, converter = item |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
38 else: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
39 key = item |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
40 converter = str |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
41 try: |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
42 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
|
43 options[key] = converter(value) |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
44 except NoOptionError: |
17
6ced445aa090
filename is not available for read config error message
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
45 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
|
46 % (key, section) |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
47 sys.exit(1) |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
48 return options |
0 | 49 |
50 | |
51 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
|
52 """Reads the tree packager configuration from the file given by filename. |
0 | 53 |
115 | 54 The function returns a tuple with a dict ('treepkg') and a list of |
55 dicts ('packagers'). The treepkg dict contains the main | |
56 configuration of the tree packager. The packagers list contains one | |
57 dict with the configuratiin for each packager. | |
0 | 58 """ |
59 parser = SafeConfigParser(defaults) | |
60 parser.read([filename]) | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
61 |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
62 # extract packager configurations |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
63 packagers = [] |
0 | 64 for section in parser.sections(): |
65 if section.startswith("pkg_"): | |
114
02c261e4443f
Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
66 vars = dict(name=section[4:]) |
02c261e4443f
Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
67 packager_class = parser.get(section, "packager_class", vars=vars) |
02c261e4443f
Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
68 module = packager.import_packager_module(packager_class) |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
47
diff
changeset
|
69 desc = packager_desc + module.PackageTrack.extra_config_desc |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
70 packagers.append(read_config_section(parser, section, desc, |
114
02c261e4443f
Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
71 defaults=vars)) |
0 | 72 |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
73 # main config |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
74 treepkg = read_config_section(parser, "treepkg", treepkg_desc) |
0 | 75 |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
76 return treepkg, packagers |
0 | 77 |
78 | |
79 if __name__ == "__main__": | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
80 import pprint |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
81 print pprint.pprint(read_config(sys.argv[1])) |