mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-23 04:21:29 +00:00
refactor(backups): actually accept a list of folders
This commit is contained in:
parent
08739f7ca8
commit
fa26379a68
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue