Commit a7d3404f authored by Xavier Thompson's avatar Xavier Thompson

jinja2_template.py: open 'once' file in 'ab' mode

This is to avoid overwriting the contents of the file specified by the
'once' option, which makes it possible to use the rendered file as the
'once' file.
parent 065564b0
......@@ -555,3 +555,40 @@ Removing the canary allows template to be re-rendered::
>>> cat('foo_once')
dummy
It's also possible to use the same file for ``rendered`` and ``once``::
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = template
...
... [template]
... recipe = slapos.recipe.template:jinja2
... template = inline:initial content
... rendered = rendered
... once = ${:rendered}
... ''')
>>> run_buildout() # doctest: +ELLIPSIS
Uninstalling template.
Installing template.
The template install returned None. A path or iterable os paths should be returned.
Template was rendered::
>>> cat('rendered')
initial content
When buildout options are modified, the template will not be rendered again::
>>> with open('buildout.cfg', 'a') as f:
... f.writelines(['template = inline:something different'])
>>> run_buildout()
Uninstalling template.
Installing template.
The template install returned None. A path or iterable os paths should be returned.
Even though we used a different template, the file still contain the first template::
>>> cat('rendered')
initial content
......@@ -266,7 +266,7 @@ class Recipe(object):
finally:
os.close(fd)
if self.once:
open(self.once, 'wb').close()
open(self.once, 'ab').close()
return
return self.rendered
......
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