annotate treepkg/readconfig.py @ 297:4dd6ec3a1151

Make it possible to use parallel builds for packages that support it: Add a new per-track configuration option deb_build_options whose value is passed as the DEB_BUILD_OPTIONS environment variable to the pbuilder process.
author Bernhard Herzog <bh@intevation.de>
date Fri, 20 Nov 2009 20:19:51 +0000
parents faeeac2c4c71
children c32dc72ba979
rev   line source
234
eaa696629a91 Add a way to specify the svn URL of the repository with the debian rules
Bernhard Herzog <bh@intevation.de>
parents: 167
diff changeset
1 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
0
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
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
129
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
17 def convert_bool(s):
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
18 s = s.lower()
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
19 if s in ("true", "yes", "1"):
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
20 return True
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
21 if s in ("false", "no", "0"):
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
22 return False
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
23 raise ValueError("cannot determine boolean value of %r" % (s,))
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
24
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
25
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
26 packager_desc = [
258
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
27 "name", "base_dir", "svn_url", ("rules_svn_url", str, ""), "packager_class",
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
28 ("root_cmd", shlex.split, "sudo"), "pbuilderrc",
297
4dd6ec3a1151 Make it possible to use parallel builds for packages that support it:
Bernhard Herzog <bh@intevation.de>
parents: 293
diff changeset
29 "deb_email", "deb_fullname", ("deb_build_options", str, ""),
4dd6ec3a1151 Make it possible to use parallel builds for packages that support it:
Bernhard Herzog <bh@intevation.de>
parents: 293
diff changeset
30 "pkg_revision_template",
129
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
31 ("handle_dependencies", convert_bool),
258
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
32 ("signing_key_id", str, ""),
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
33 ]
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
34
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
35 treepkg_desc = [
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
36 ("check_interval", int),
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
37 "instructions_file",
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
38 ]
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
39
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
40
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
41 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
42 if defaults is None:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
43 defaults = dict()
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
44 options = dict()
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
45 for item in item_desc:
258
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
46 has_default_value = False
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
47 if isinstance(item, tuple):
258
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
48 key, converter = item[:2]
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
49 if len(item) == 3:
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
50 default_value = item[-1]
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
51 has_default_value = True
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
52 else:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
53 key = item
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
54 converter = str
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
55 try:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
56 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
57 except NoOptionError:
258
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
58 if has_default_value:
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
59 value = default_value
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
60 else:
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
61 print >>sys.stderr, "Missing option %r in section %r" \
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
62 % (key, section)
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
63 sys.exit(1)
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
64 options[key] = converter(value)
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
65 return options
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
66
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
67
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
68 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
69 """Reads the tree packager configuration from the file given by filename.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70
115
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
71 The function returns a tuple with a dict ('treepkg') and a list of
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
72 dicts ('packagers'). The treepkg dict contains the main
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
73 configuration of the tree packager. The packagers list contains one
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
74 dict with the configuratiin for each packager.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
75 """
258
bb98e728f25b Allow default values for individual options to be passed to read_config_section.
Bernhard Herzog <bh@intevation.de>
parents: 234
diff changeset
76 parser = SafeConfigParser()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
77 parser.read([filename])
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
78
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
79 # extract packager configurations
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
80 packagers = []
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
81 for section in parser.sections():
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
82 if section.startswith("pkg_"):
114
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
83 vars = dict(name=section[4:])
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
84 packager_class = parser.get(section, "packager_class", vars=vars)
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
85 module = packager.import_packager_module(packager_class)
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 47
diff changeset
86 desc = packager_desc + module.PackageTrack.extra_config_desc
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
87 packagers.append(read_config_section(parser, section, desc,
114
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
88 defaults=vars))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
89
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
90 # main config
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
91 treepkg = read_config_section(parser, "treepkg", treepkg_desc)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
92
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
93 return treepkg, packagers
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
94
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
95
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
96 if __name__ == "__main__":
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
97 import pprint
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
98 print pprint.pprint(read_config(sys.argv[1]))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)