Mercurial > bitten > bitten-test
annotate bitten/build/config.py @ 599:b76e6accad72
0.6dev: Added Configuration documentation. It contains all configuration information I've found in the wiki and source code.
author | osimons |
---|---|
date | Thu, 30 Jul 2009 09:47:48 +0000 |
parents | 246f211c1328 |
children | 820583ca4dc3 |
rev | line source |
---|---|
379 | 1 # -*- coding: utf-8 -*- |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
2 # |
408
933105ab516b
Update file headers and other stuff pointing to the old home.
cmlenz
parents:
392
diff
changeset
|
3 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de> |
933105ab516b
Update file headers and other stuff pointing to the old home.
cmlenz
parents:
392
diff
changeset
|
4 # Copyright (C) 2007 Edgewall Software |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
5 # All rights reserved. |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
6 # |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
7 # This software is licensed as described in the file COPYING, which |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
8 # you should have received as part of this distribution. The terms |
408
933105ab516b
Update file headers and other stuff pointing to the old home.
cmlenz
parents:
392
diff
changeset
|
9 # are also available at http://bitten.edgewall.org/wiki/License. |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
10 |
313 | 11 """Support for build slave configuration.""" |
12 | |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
13 from ConfigParser import SafeConfigParser |
240
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
14 import logging |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
15 import os |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
16 import platform |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
17 import re |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
18 |
240
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
19 log = logging.getLogger('bitten.config') |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
20 |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
21 __docformat__ = 'restructuredtext en' |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
22 |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
23 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
24 class Configuration(object): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
25 """Encapsulates the configuration of a build machine. |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
26 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
27 Configuration values can be provided through a configuration file (in INI |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
28 format) or through command-line parameters (properties). In addition to |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
29 explicitly defined properties, this class automatically collects platform |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
30 information and stores them as properties. These defaults can be |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
31 overridden (useful for cross-compilation). |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
32 """ |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
33 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
34 def __init__(self, filename=None, properties=None): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
35 """Create the configuration object. |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
36 |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
37 :param filename: the path to the configuration file, if any |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
38 :param properties: a dictionary of the configuration properties |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
39 provided on the command-line |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
40 """ |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
41 self.properties = {} |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
42 self.packages = {} |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
43 parser = SafeConfigParser() |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
44 if filename: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
45 parser.read(filename) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
46 self._merge_sysinfo(parser, properties) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
47 self._merge_packages(parser, properties) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
48 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
49 def _merge_sysinfo(self, parser, properties): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
50 """Merge the platform information properties into the configuration.""" |
463
977a6c122205
Make slave names available for use in target platform rules, and added some documentation to the admin panel. Closes #190.
cmlenz
parents:
411
diff
changeset
|
51 system, _, release, version, machine, processor = platform.uname() |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
52 system, release, version = platform.system_alias(system, release, |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
53 version) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
54 self.properties['machine'] = machine |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
55 self.properties['processor'] = processor |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
56 self.properties['os'] = system |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
57 self.properties['family'] = os.name |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
58 self.properties['version'] = release |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
59 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
60 mapping = {'machine': ('machine', 'name'), |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
61 'processor': ('machine', 'processor'), |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
62 'os': ('os', 'name'), |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
63 'family': ('os', 'family'), |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
64 'version': ('os', 'version')} |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
65 for key, (section, option) in mapping.items(): |
586
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
66 if parser.has_option(section, option): |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
67 value = parser.get(section, option) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
68 if value is not None: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
69 self.properties[key] = value |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
70 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
71 if properties: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
72 for key, value in properties.items(): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
73 if key in mapping: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
74 self.properties[key] = value |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
75 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
76 def _merge_packages(self, parser, properties): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
77 """Merge package information into the configuration.""" |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
78 for section in parser.sections(): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
79 if section in ('os', 'machine', 'maintainer'): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
80 continue |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
81 package = {} |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
82 for option in parser.options(section): |
586
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
83 if option == 'name': |
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
84 log.warning("Reserved configuration option 'name' used " |
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
85 "for package/section '%s'. Skipping." % section) |
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
86 continue |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
87 package[option] = parser.get(section, option) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
88 self.packages[section] = package |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
89 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
90 if properties: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
91 for key, value in properties.items(): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
92 if '.' in key: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
93 package, propname = key.split('.', 1) |
586
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
94 if propname == 'name': |
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
95 log.warning("Reserved configuration option 'name' " |
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
96 "used for property '%s'. Skipping." % key) |
246f211c1328
0.6dev: Fixing some minor issues with Configuration:
osimons
parents:
463
diff
changeset
|
97 continue |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
98 if package not in self.packages: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
99 self.packages[package] = {} |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
100 self.packages[package][propname] = value |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
101 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
102 def __contains__(self, key): |
313 | 103 """Return whether the configuration contains a value for the specified |
104 key. | |
105 | |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
106 :param key: name of the configuration option using dotted notation |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
107 (for example, "python.path") |
313 | 108 """ |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
109 if '.' in key: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
110 package, propname = key.split('.', 1) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
111 return propname in self.packages.get(package, {}) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
112 return key in self.properties |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
113 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
114 def __getitem__(self, key): |
313 | 115 """Return the value for the specified configuration key. |
116 | |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
117 :param key: name of the configuration option using dotted notation |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
118 (for example, "python.path") |
313 | 119 """ |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
120 if '.' in key: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
121 package, propname = key.split('.', 1) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
122 return self.packages.get(package, {}).get(propname) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
123 return self.properties.get(key) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
124 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
125 def __str__(self): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
126 return str({'properties': self.properties, 'packages': self.packages}) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
127 |
313 | 128 def get_dirpath(self, key): |
129 """Return the value of the specified configuration key, but verify that | |
130 the value refers to the path of an existing directory. | |
131 | |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
132 If the value does not exist, or is not a directory path, return `None`. |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
133 |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
134 :param key: name of the configuration option using dotted notation |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
135 (for example, "ant.home") |
313 | 136 """ |
240
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
137 dirpath = self[key] |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
138 if dirpath: |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
139 if os.path.isdir(dirpath): |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
140 return dirpath |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
141 log.warning('Invalid %s: %s is not a directory', key, dirpath) |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
142 return None |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
143 |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
144 def get_filepath(self, key): |
313 | 145 """Return the value of the specified configuration key, but verify that |
146 the value refers to the path of an existing file. | |
147 | |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
148 If the value does not exist, or is not a file path, return `None`. |
313 | 149 |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
150 :param key: name of the configuration option using dotted notation |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
151 (for example, "python.path") |
313 | 152 """ |
240
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
153 filepath = self[key] |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
154 if filepath: |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
155 if os.path.isfile(filepath): |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
156 return filepath |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
157 log.warning('Invalid %s: %s is not a file', key, filepath) |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
158 return None |
24e91cbae6e0
New recipe command `<java:ant>` for running Ant builds.
cmlenz
parents:
233
diff
changeset
|
159 |
313 | 160 _VAR_RE = re.compile(r'\$\{(?P<ref>\w[\w.]*?\w)(?:\:(?P<def>.+))?\}') |
161 | |
392 | 162 def interpolate(self, text, **vars): |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
163 """Interpolate configuration properties into a string. |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
164 |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
165 Properties can be referenced in the text using the notation |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
166 ``${property.name}``. A default value can be provided by appending it to |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
167 the property name separated by a colon, for example |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
168 ``${property.name:defaultvalue}``. This value will be used when there's |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
169 no such property in the configuration. Otherwise, if no default is |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
170 provided, the reference is not replaced at all. |
313 | 171 |
411
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
172 :param text: the string containing variable references |
a169d2e96463
Use reStructuredText as the API documentation syntax.
cmlenz
parents:
408
diff
changeset
|
173 :param vars: extra variables to use for the interpolation |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
174 """ |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
175 def _replace(m): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
176 refname = m.group('ref') |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
177 if refname in self: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
178 return self[refname] |
392 | 179 elif refname in vars: |
180 return vars[refname] | |
233
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
181 elif m.group('def'): |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
182 return m.group('def') |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
183 else: |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
184 return m.group(0) |
8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
cmlenz
parents:
diff
changeset
|
185 return self._VAR_RE.sub(_replace, text) |