annotate treepkg/readconfig.py @ 234:eaa696629a91

Add a way to specify the svn URL of the repository with the debian rules subdirectory and use to checkout and update the debian directory of a PackageTrack. Update the tests.
author Bernhard Herzog <bh@intevation.de>
date Tue, 13 Jan 2009 16:18:58 +0000
parents 36004ee0b3a1
children bb98e728f25b
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
167
36004ee0b3a1 Introduce package track config option signing_key_id to specify the
Bernhard Herzog <bh@intevation.de>
parents: 129
diff changeset
25 defaults = dict(root_cmd="sudo",
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
26 signing_key_id="",
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
27 rules_svn_url="")
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
28
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
29 packager_desc = [
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
30 "name", "base_dir", "svn_url", "rules_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
31 ("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
32 "deb_email", "deb_fullname", "debrevision_prefix",
129
ce9f046058b5 Add the handle_dependencies Option for the config file. Extend the test
Bernhard Herzog <bh@intevation.de>
parents: 115
diff changeset
33 ("handle_dependencies", convert_bool),
167
36004ee0b3a1 Introduce package track config option signing_key_id to specify the
Bernhard Herzog <bh@intevation.de>
parents: 129
diff changeset
34 "signing_key_id",
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
35 ]
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
36
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
37 treepkg_desc = [
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
38 ("check_interval", int),
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
39 "instructions_file",
2
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
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
42
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
43 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
44 if defaults is None:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
45 defaults = dict()
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
46 options = dict()
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
47 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
48 if isinstance(item, tuple):
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
49 key, converter = item
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
50 else:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
51 key = item
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
52 converter = str
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
53 try:
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
54 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
55 options[key] = converter(value)
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
56 except NoOptionError:
17
6ced445aa090 filename is not available for read config error message
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
57 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
58 % (key, section)
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
59 sys.exit(1)
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
60 return options
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
61
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
62
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
63 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
64 """Reads the tree packager configuration from the file given by filename.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
65
115
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
66 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
67 dicts ('packagers'). The treepkg dict contains the main
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
68 configuration of the tree packager. The packagers list contains one
d7b53e7df961 Fix doc-string
Bernhard Herzog <bh@intevation.de>
parents: 114
diff changeset
69 dict with the configuratiin for each packager.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70 """
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
71 parser = SafeConfigParser(defaults)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
72 parser.read([filename])
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
73
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
74 # extract packager configurations
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
75 packagers = []
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
76 for section in parser.sections():
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
77 if section.startswith("pkg_"):
114
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
78 vars = dict(name=section[4:])
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
79 packager_class = parser.get(section, "packager_class", vars=vars)
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
80 module = packager.import_packager_module(packager_class)
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 47
diff changeset
81 desc = packager_desc + module.PackageTrack.extra_config_desc
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
82 packagers.append(read_config_section(parser, section, desc,
114
02c261e4443f Extend treepkg.readconfig.read_config:
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
83 defaults=vars))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
84
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
85 # main config
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
86 treepkg = read_config_section(parser, "treepkg", treepkg_desc)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
87
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
88 return treepkg, packagers
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
89
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
90
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
91 if __name__ == "__main__":
2
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
92 import pprint
e6a9f4037f68 readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
93 print pprint.pprint(read_config(sys.argv[1]))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)