annotate treepkg/readconfig.py @ 93:73c67372c7f7

Make the prefix used in the debian revision number configurable. This involves a new config file setting documented in demo.cfg, the necessary changes to the packagers and updated and new test cases
author Bernhard Herzog <bh@intevation.de>
date Wed, 07 Nov 2007 10:13:24 +0000
parents 3ed079a7174a
children 02c261e4443f
rev   line source
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2007 by Intevation GmbH
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
8 """Reads the configuration file"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
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
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
12 from ConfigParser import SafeConfigParser, NoOptionError
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
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
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16 defaults = dict(root_cmd="sudo")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
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",
93
73c67372c7f7 Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents: 91
diff changeset
21 "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
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),
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
26 "instructions_file",
2
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
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
30 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
31 if defaults is None:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
32 defaults = dict()
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
33 options = dict()
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
34 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
35 if isinstance(item, tuple):
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
36 key, converter = item
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
37 else:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
38 key = item
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
39 converter = str
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
40 try:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
41 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
42 options[key] = converter(value)
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
43 except NoOptionError:
17
6ced445aa090 filename is not available for read config error message
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
44 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
45 % (key, section)
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
46 sys.exit(1)
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
47 return options
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
48
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
49
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
50 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
51 """Reads the tree packager configuration from the file given by filename.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
52
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
53 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
54 ('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
55 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
56 configuratiin for each packager.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
57 """
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
58 parser = SafeConfigParser(defaults)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59 parser.read([filename])
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
60
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
61 # extract packager configurations
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
62 packagers = []
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
63 for section in parser.sections():
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
64 if section.startswith("pkg_"):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
65 packager_class = parser.get(section, "packager_class")
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
66 module = util.import_dotted_name(packager_class)
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 47
diff changeset
67 desc = packager_desc + module.PackageTrack.extra_config_desc
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
68 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
69 dict(name=section[4:])))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
71 # main config
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
72 treepkg = read_config_section(parser, "treepkg", treepkg_desc)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
73
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
74 return treepkg, packagers
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
75
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
76
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
77 if __name__ == "__main__":
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
78 import pprint
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
79 print pprint.pprint(read_config(sys.argv[1]))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)