mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-11 18:39:30 +00:00
refactor(backups): expect one more error of restic json output parsing
This commit is contained in:
parent
7f984b678f
commit
981445d594
|
@ -4,6 +4,7 @@ import datetime
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
|
||||||
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
|
||||||
|
@ -208,6 +209,7 @@ class ResticBackuper(AbstractBackuper):
|
||||||
restore_command, stdout=subprocess.PIPE, shell=False
|
restore_command, stdout=subprocess.PIPE, shell=False
|
||||||
) as handle:
|
) as handle:
|
||||||
|
|
||||||
|
# for some reason restore does not support nice reporting of progress via json
|
||||||
output = handle.communicate()[0].decode("utf-8")
|
output = handle.communicate()[0].decode("utf-8")
|
||||||
if "restoring" not in output:
|
if "restoring" not in output:
|
||||||
raise ValueError("cannot restore a snapshot: " + output)
|
raise ValueError("cannot restore a snapshot: " + output)
|
||||||
|
@ -259,7 +261,12 @@ class ResticBackuper(AbstractBackuper):
|
||||||
truncated_output = output[starting_index:]
|
truncated_output = output[starting_index:]
|
||||||
json_messages = truncated_output.splitlines()
|
json_messages = truncated_output.splitlines()
|
||||||
if len(json_messages) == 1:
|
if len(json_messages) == 1:
|
||||||
return json.loads(truncated_output)
|
try:
|
||||||
|
return json.loads(truncated_output)
|
||||||
|
except JSONDecodeError as e:
|
||||||
|
raise ValueError(
|
||||||
|
"There is no json in the restic output : " + output
|
||||||
|
) from e
|
||||||
|
|
||||||
result_array = []
|
result_array = []
|
||||||
for message in json_messages:
|
for message in json_messages:
|
||||||
|
|
Loading…
Reference in a new issue