Commit 125fdd0f authored by Antoine Catton's avatar Antoine Catton

Add escape option in order to avoid script formatting

The script is formatted with self.options dictionnary.

For example :

  [foobar]
  recipe = slapos.recipe.build
  foo = bar
  script =
    print '%(foo)s'

Produces :

  Installing foobar.
  bar

But this can mess up the python code, because there's no
escaping. For example :

  [foobar]
  recipe = slapos.recipe.build
  foo = bar's
  script =
    print '%(foo)s'

Produces :

  While:
    Installing foobar.

  An internal error occurred due to a bug in either zc.buildout or in a
  recipe being used:
  Traceback (most recent call last):
    File "<string>", line 2
      print 'bar's'
                 ^
  SyntaxError: invalid syntax

We can workaround this by using :

  [foobar]
  recipe = slapos.recipe.build
  foo = bar's
  script =
      print '%%s' %% self.options['foo']

But every percent sign has to be escaped. That's why, this
commit introduces :

  [foobar]
  recipe = slapos.recipe.build
  foo = bar's
  format = no
  script =
      print '%s' % self.options['foo']

NB: This commit doesn't remove formating for backward compatibility.
parent 38195ec2
......@@ -266,6 +266,7 @@ class Script:
# cleanup some variables
for k in ['location', 'url', 'md5sum', 'path']:
self.options[k] = self.options.get(k, '').strip()
if self.options.get('format', 'yes') in ['y', 'yes', '1', 'on']:
self.options['script'] = self.options.get('script', self.script) % \
self.options
if self.options.get('keep-on-error', '').strip().lower() in TRUE_LIST:
......
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