debugging

backups-fix
Inex Code 2021-12-06 12:07:03 +03:00
parent 340b50bb0d
commit f4288dacd6
1 changed files with 10 additions and 6 deletions

View File

@ -3,6 +3,7 @@ from datetime import datetime
import json import json
import subprocess import subprocess
import os import os
from threading import Lock
from enum import Enum from enum import Enum
import portalocker import portalocker
from selfprivacy_api.utils import ReadUserData from selfprivacy_api.utils import ReadUserData
@ -35,12 +36,14 @@ class ResticController:
""" """
_instance = None _instance = None
_lock = Lock()
_initialized = False _initialized = False
def __new__(cls): def __new__(cls):
print("new is called!") print("new is called!")
if not cls._instance: if not cls._instance:
cls._instance = super(ResticController, cls).__new__(cls) with cls._lock:
cls._instance = super(ResticController, cls).__new__(cls)
return cls._instance return cls._instance
def __init__(self): def __init__(self):
@ -54,11 +57,11 @@ class ResticController:
self._repository_name = None self._repository_name = None
self.snapshot_list = [] self.snapshot_list = []
self.error_message = None self.error_message = None
self._initialized = True
print("init is called!") print("init is called!")
self.load_configuration() self.load_configuration()
self.write_rclone_config() self.write_rclone_config()
self.load_snapshots() self.load_snapshots()
self._initialized = True
def load_configuration(self): def load_configuration(self):
"""Load current configuration from user data to singleton.""" """Load current configuration from user data to singleton."""
@ -107,21 +110,22 @@ class ResticController:
or self.state == ResticStates.RESTORING or self.state == ResticStates.RESTORING
): ):
return return
print("preparing to read snapshots")
with subprocess.Popen( with subprocess.Popen(
backup_listing_command, backup_listing_command,
shell=False, shell=False,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
) as backup_listing_process_descriptor: ) as backup_listing_process_descriptor:
snapshots_list = backup_listing_process_descriptor.communicate()[0].decode( snapshots_list = backup_listing_process_descriptor.communicate()[
"utf-8" 0
) ].decode("utf-8")
try: try:
starting_index = snapshots_list.find("[") starting_index = snapshots_list.find("[")
json.loads(snapshots_list[starting_index:]) json.loads(snapshots_list[starting_index:])
self.snapshot_list = json.loads(snapshots_list[starting_index:]) self.snapshot_list = json.loads(snapshots_list[starting_index:])
self.state = ResticStates.INITIALIZED self.state = ResticStates.INITIALIZED
print(snapshots_list)
except ValueError: except ValueError:
if "Is there a repository at the following location?" in snapshots_list: if "Is there a repository at the following location?" in snapshots_list:
self.state = ResticStates.NOT_INITIALIZED self.state = ResticStates.NOT_INITIALIZED