refactor(backups): actually accept a list of folders

This commit is contained in:
Houkime 2023-04-14 11:58:39 +00:00 committed by Inex Code
parent 406d255b2c
commit 47f2f857f6

View file

@ -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,