refactor(backups): actually accept a list of folders

restic-rewrite-api
Houkime 2023-04-14 11:58:39 +00:00
parent 08739f7ca8
commit fa26379a68
1 changed files with 14 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import json
import datetime import datetime
from typing import List from typing import List
from collections.abc import Iterable
from selfprivacy_api.backup.backuper import AbstractBackuper from selfprivacy_api.backup.backuper import AbstractBackuper
from selfprivacy_api.models.backup.snapshot import Snapshot from selfprivacy_api.models.backup.snapshot import Snapshot
@ -54,9 +55,20 @@ class ResticBackuper(AbstractBackuper):
self._password_command(), self._password_command(),
] ]
if args != []: if args != []:
command.extend(args) command.extend(ResticBackuper.__flatten_list(args))
return command 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): def start_backup(self, folders: List[str], repo_name: str):
""" """
Start backup with restic Start backup with restic
@ -69,7 +81,7 @@ class ResticBackuper(AbstractBackuper):
repo_name, repo_name,
"backup", "backup",
"--json", "--json",
folders[0], folders,
) )
with subprocess.Popen( with subprocess.Popen(
backup_command, backup_command,