Document mode option for write_file + substitute file content

This commit is contained in:
Mathieu Comandon 2017-12-30 12:24:47 -08:00
parent b1d22d05cd
commit c2fc40a6a8
2 changed files with 10 additions and 3 deletions

View file

@ -269,7 +269,12 @@ Writing files
Writing text files
~~~~~~~~~~~~~~~~~~
Create or overwrite a file with the ``write_file`` directive. Use the ``file`` (an absolute path or a ``file id``) and ``content`` parameters.
Create or overwrite a file with the ``write_file`` directive. Use the ``file``
(an absolute path or a ``file id``) and ``content`` parameters.
You can also use the optional parameter ``mode`` to specify a file write mode.
Valid values for ``mode`` include ``w`` (the default, to write to a new file)
or ``a`` to append data to an existing file.
Example:
@ -486,7 +491,7 @@ Currently, the following tasks are implemented:
arch: win64
* wine / winesteam: ``winekill`` Stops processes running in Wine prefix. Parameters
are ``prefix`` (optional WINEPREFIX),
are ``prefix`` (optional WINEPREFIX),
``arch`` (optional architecture of the prefix, required when you created win64 prefix).
Example

View file

@ -384,9 +384,11 @@ class CommandsMixin(object):
os.makedirs(basedir)
mode = params.get('mode', 'w')
if not mode.startswith(('a', 'w')):
raise ScriptingError("Wrong value for write_file mode: '%s'" % mode)
with open(file, mode) as f:
f.write(params['content'])
f.write(self._substitute(params['content']))
def write_json(self, params):
"""Write data into a json file."""