views:

153

answers:

1

Is there a simple way of escaping the magic characters used for variable substitution in a buildout configuration, such that the string is left alone. In other words, where I say:

[part]
attribute = ${variable}

I don't actually want it to expand ${variable} but leave it as the literal value.

In practice the specific problem I am encountering is not in the buildout configuration file itself, but in a template file processed by the recipe 'collective.recipe.template'. This uses the same variable substitution engine from buildout that is used in the configuration files. Problem is that the file I want to use as a template already uses '${variable}' syntax for its own purposes in conjunction with the application configuration system which ultimately consumes the file.

The only way I have found to get around the problem is to use something like:

[server-xml]
recipe = collective.recipe.template
input = templates/server.xml.in
output = ${product:build-directory}/conf/server.xml
dollar = $

In the template input file then have:

${dollar}{variable}

instead of:

${variable}

that it already had.

What this is doing is cause a lookup of 'dollar' attribute against the section using the template and replace it with '$'.

Rather than have to do that, was sort of hoping that one could do:

\${variable}

or perhaps even:

$${variable}

and eliminate the need to have to have a dummy attribute to trick it into doing what I want.

Looking at the source code for buildout, the way it matches variable substitution doesn't seem to provide an escape mechanism.

If there is indeed no way, then perhaps someone knows of an alternate templating recipe for buildout that can do variable expansion, but provides an escape mechanism for whatever way it indicates variables, such that one can avoid problems where there may be a clash between the templating systems expansion mechanism and literal data in the file being templated.

+2  A: 

I am afraid your analysis of the buildout variable substitution code (which collective.recipe.template relies on) is correct. There is no syntax for escaping a ${section:variable} variable substitution and your solution of providing a ${dollar} substitution is the best workaround I can think of.

You could of course also propose a patch to the zc.buildout team to add support for escaping the variable substitution syntax. :-)

Martijn Pieters