2023-02-08 14:57:34 +00:00
|
|
|
from selfprivacy_api.utils.singleton_metaclass import SingletonMetaclass
|
2023-02-08 14:05:25 +00:00
|
|
|
|
2023-02-08 14:57:34 +00:00
|
|
|
from selfprivacy_api.services.service import Service
|
|
|
|
from selfprivacy_api.backup.providers.provider import AbstractBackupProvider
|
|
|
|
from selfprivacy_api.backup.providers import get_provider
|
|
|
|
from selfprivacy_api.graphql.queries.providers import BackupProvider
|
2023-01-23 13:43:18 +00:00
|
|
|
|
2023-02-08 14:57:34 +00:00
|
|
|
|
|
|
|
class Backups(metaclass=SingletonMetaclass):
|
2023-02-08 14:18:45 +00:00
|
|
|
"""A singleton controller for backups"""
|
|
|
|
|
2023-02-08 14:57:34 +00:00
|
|
|
provider: AbstractBackupProvider
|
2023-02-08 14:18:45 +00:00
|
|
|
|
2023-01-23 13:43:18 +00:00
|
|
|
def __init__(self):
|
2023-02-08 14:57:34 +00:00
|
|
|
self.lookup_provider()
|
|
|
|
|
|
|
|
def lookup_provider(self):
|
|
|
|
redis_provider = Backups.load_provider_redis()
|
|
|
|
if redis_provider is not None:
|
|
|
|
self.provider = redis_provider
|
|
|
|
|
|
|
|
json_provider = Backups.load_provider_json()
|
|
|
|
if json_provider is not None:
|
|
|
|
self.provider = json_provider
|
|
|
|
|
|
|
|
provider_class = get_provider(BackupProvider.MEMORY)
|
|
|
|
self.provider = provider_class(login="", key="")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load_provider_redis() -> AbstractBackupProvider:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load_provider_json() -> AbstractBackupProvider:
|
2023-02-08 14:05:25 +00:00
|
|
|
pass
|
|
|
|
|
2023-02-08 14:57:34 +00:00
|
|
|
def back_up(self, service: Service):
|
|
|
|
folder = service.get_location()
|
|
|
|
repo_name = service.get_id()
|
|
|
|
self.provider.backuper.start_backup(folder, repo_name)
|