diff --git a/plinth/modules/backups/repository.py b/plinth/modules/backups/repository.py index 79167223f..82a541411 100644 --- a/plinth/modules/backups/repository.py +++ b/plinth/modules/backups/repository.py @@ -18,11 +18,11 @@ Remote and local Borg backup repositories """ +import abc import io import json import logging import os -from abc import ABC from uuid import uuid1 from django.utils.translation import ugettext_lazy as _ @@ -78,9 +78,10 @@ KNOWN_ERRORS = [{ }] -class BaseBorgRepository(ABC): +class BaseBorgRepository(abc.ABC): """Base class for all kinds of Borg repositories.""" uuid = None + flags = {} is_mounted = True def __init__(self, uuid=None, path=None, credentials=None, **kwargs): @@ -107,6 +108,11 @@ class BaseBorgRepository(ABC): def name(self): return self._path + @abc.abstractmethod + def storage_type(self): + """Return the storage type of repository.""" + raise NotImplementedError + @property def repo_path(self): """Return the repository that the backups action script should use.""" @@ -137,17 +143,17 @@ class BaseBorgRepository(ABC): """Get archives with additional information as needed by the view""" repository = { 'name': self.name, - 'type': self.storage_type, - 'error': '' + 'storage_type': self.storage_type, + 'flags': self.flags, + 'error': None, } try: - error = '' repository['mounted'] = self.is_mounted if repository['mounted']: repository['archives'] = self.list_archives() except (BorgError, ActionError) as err: - error = str(err) - repository['error'] = error + repository['error'] = str(err) + return repository def remove_repository(self): @@ -308,6 +314,7 @@ class BorgRepository(BaseBorgRepository): """General Borg repository implementation.""" KNOWN_CREDENTIALS = ['encryption_passphrase'] storage_type = 'disk' + flags = {'removable': True} @property def name(self): @@ -327,6 +334,7 @@ class SshBorgRepository(BaseBorgRepository): 'ssh_keyfile', 'ssh_password', 'encryption_passphrase' ] storage_type = 'ssh' + flags = {'removable': True, 'mountable': True} @property def repo_path(self): diff --git a/plinth/modules/backups/templates/backups.html b/plinth/modules/backups/templates/backups.html index c499fb85c..fe98d864d 100644 --- a/plinth/modules/backups/templates/backups.html +++ b/plinth/modules/backups/templates/backups.html @@ -60,14 +60,14 @@