Commit 2dff90e5 authored by Godefroid Chapelle's avatar Godefroid Chapelle

add a query command

for continuous integration
parent 6d4fec30
......@@ -1238,6 +1238,27 @@ class Buildout(DictMixin):
runsetup = setup # backward compat.
def query(self, args=None):
if args is None or len(args) != 1:
_error('The query command requires a single argument.')
option = args[0]
option = option.split(':')
if len(option) == 1:
option = 'buildout', option[0]
elif len(option) != 2:
_error('Invalid option:', args[0])
section, option = option
verbose = self['buildout'].get('verbosity', 0) != 0
if verbose:
print_('${%s:%s}' % (section, option))
try:
print_(self._raw[section][option])
except KeyError:
if section in self._raw:
_error('Key not found:', option)
else:
_error('Section not found:', section)
def annotate(self, args=None):
verbose = self['buildout'].get('verbosity', 0) != 0
section = None
......@@ -2020,6 +2041,10 @@ Commands:
alphabetically. For each section, all key-value pairs are displayed,
sorted alphabetically, along with the origin of the value (file name or
COMPUTED_VALUE, DEFAULT_VALUE, COMMAND_LINE_VALUE).
query section:key
Display value of given section key pair.
"""
def _help():
......@@ -2115,7 +2140,7 @@ def main(args=None):
command = args.pop(0)
if command not in (
'install', 'bootstrap', 'runsetup', 'setup', 'init',
'annotate',
'annotate', 'query',
):
_error('invalid command:', command)
else:
......
......@@ -1038,6 +1038,71 @@ You can restrict the output to some sections by passing section names as argumen
DEFAULT_VALUE
<BLANKLINE>
Query values
------------
For continuous integration, it might be useful to query the buildout config.
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... develop = .
...
... [values]
... host = buildout.org
... multiline =
... first
... second
... """)
>>> print_(system(buildout+ ' query buildout:develop'), end='')
.
>>> print_(system(buildout+ ' query values:host'), end='')
buildout.org
>>> print_(system(buildout+ ' query values:multiline'), end='')
first
second
As with assignments, if the section is ommitted, 'buildout' section is assumed.
>>> print_(system(buildout+ ' query develop'), end='')
.
When used with -v option, the query command also displays section and key.
>>> print_(system(buildout+ ' -v query develop'), end='')
${buildout:develop}
.
>>> print_(system(buildout+ ' -v query values:host'), end='')
${values:host}
buildout.org
The query commands outputs proper error messages.
>>> print_(system(buildout+ ' query versions parts'), end='')
Error: The query command requires a single argument.
>>> print_(system(buildout+ ' query'), end='')
Error: The query command requires a single argument.
>>> print_(system(buildout+ ' query invalid:section:key'), end='')
Error: Invalid option: invalid:section:key
>>> print_(system(buildout+ ' -v query values:port'), end='')
${values:port}
Error: Key not found: port
>>> print_(system(buildout+ ' -v query versionx'), end='')
${buildout:versionx}
Error: Key not found: versionx
>>> print_(system(buildout+ ' -v query specific:port'), end='')
${specific:port}
Error: Section not found: specific
Variable substitutions
----------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment