# HG changeset patch # User Goffi # Date 1623503449 -7200 # Node ID d66a8453b02b8c0c0fdbd39267a51a91fdb3916e # Parent 2c9e95796371cf96829421cf85a83c1a074f019a plugin app manager: add a way to create files: a `files` field can now be used to create files on the fly. Its value must be a dict where key are file names, and values are an other dict with file data. For now file data can only use the `content` key. Value of content will be written to the file. If a file already exists, it is not overwritten. diff -r 2c9e95796371 -r d66a8453b02b sat/plugins/plugin_misc_app_manager.py --- a/sat/plugins/plugin_misc_app_manager.py Fri Jun 11 17:39:59 2021 +0200 +++ b/sat/plugins/plugin_misc_app_manager.py Sat Jun 12 15:10:49 2021 +0200 @@ -548,6 +548,24 @@ if prepare: raise exceptions.InternalError('"prepare" should be empty') + async def _doCreateFiles( + self, + app_data: dict, + ) -> None: + dest_path = app_data['_instance_dir_path'] + files = app_data.get('files') + if not files: + return + if not isinstance(files, dict): + raise ValueError('"files" must be a dictionary') + for filename, data in files.items(): + path = dest_path / filename + if path.is_file(): + log.info(f"{path} already exists, skipping") + with path.open("w") as f: + f.write(data.get("content", "")) + log.debug(f"{path} created") + async def startCommon(self, app_data: dict) -> None: """Method running common action when starting a manager @@ -555,3 +573,4 @@ """ log.info(f"starting {app_data['name']!r}") await self._doPrepare(app_data) + await self._doCreateFiles(app_data)