From fa26379a686aa0b6ecbabe3604f197c2012643dd Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 14 Apr 2023 11:58:39 +0000 Subject: [PATCH] refactor(backups): actually accept a list of folders --- selfprivacy_api/backup/restic_backuper.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/backup/restic_backuper.py b/selfprivacy_api/backup/restic_backuper.py index 2af7d44..896f68d 100644 --- a/selfprivacy_api/backup/restic_backuper.py +++ b/selfprivacy_api/backup/restic_backuper.py @@ -3,6 +3,7 @@ import json import datetime from typing import List +from collections.abc import Iterable from selfprivacy_api.backup.backuper import AbstractBackuper from selfprivacy_api.models.backup.snapshot import Snapshot @@ -54,9 +55,20 @@ class ResticBackuper(AbstractBackuper): self._password_command(), ] if args != []: - command.extend(args) + command.extend(ResticBackuper.__flatten_list(args)) return command + @staticmethod + def __flatten_list(list): + """string-aware list flattener""" + result = [] + for item in list: + if isinstance(item, Iterable) and not isinstance(item, str): + result.extend(ResticBackuper.__flatten_list(item)) + continue + result.append(item) + return result + def start_backup(self, folders: List[str], repo_name: str): """ Start backup with restic @@ -69,7 +81,7 @@ class ResticBackuper(AbstractBackuper): repo_name, "backup", "--json", - folders[0], + folders, ) with subprocess.Popen( backup_command,