From c2fc40a6a8a0de69c1d2ebb642ba57eaaea71d07 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Sat, 30 Dec 2017 12:24:47 -0800 Subject: [PATCH] Document mode option for write_file + substitute file content --- docs/installers.rst | 9 +++++++-- lutris/installer/commands.py | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/installers.rst b/docs/installers.rst index 4bd312f39..58ea29cfe 100644 --- a/docs/installers.rst +++ b/docs/installers.rst @@ -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 diff --git a/lutris/installer/commands.py b/lutris/installer/commands.py index 150f5bebf..5c07892a0 100644 --- a/lutris/installer/commands.py +++ b/lutris/installer/commands.py @@ -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."""