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.
This commit is contained in:
Goffi 2021-06-12 15:10:49 +02:00
commit 98fb1b4091

View file

@ -548,6 +548,24 @@ class AppManager:
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 @@ class AppManager:
"""
log.info(f"starting {app_data['name']!r}")
await self._doPrepare(app_data)
await self._doCreateFiles(app_data)