mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
backups: Introduce method for checking if a repository is usable
get_repositories method will return repositories instead of dictionaries for view content. This will make it usable in more situations. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
0df07f5cf2
commit
0b0791d78f
@ -32,7 +32,8 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from plinth.modules.storage import get_disks
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
from . import ROOT_REPOSITORY_NAME, api, split_path, store
|
||||
from . import api, split_path, store
|
||||
from .repository import get_repositories
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -53,11 +54,8 @@ def _get_app_choices(apps):
|
||||
|
||||
def _get_repository_choices():
|
||||
"""Return the list of available repositories."""
|
||||
choices = [('root', ROOT_REPOSITORY_NAME)]
|
||||
storages = store.get_storages()
|
||||
for storage in storages.values():
|
||||
if storage.get('verified'):
|
||||
choices += [(storage['uuid'], storage['path'])]
|
||||
choices = [(repository.uuid, repository.name)
|
||||
for repository in get_repositories() if repository.is_usable()]
|
||||
|
||||
return choices
|
||||
|
||||
|
||||
@ -89,6 +89,8 @@ class BaseBorgRepository(abc.ABC):
|
||||
|
||||
If only a uuid is given, load the values from kvstore.
|
||||
"""
|
||||
self.kwargs = kwargs
|
||||
|
||||
if not uuid:
|
||||
uuid = str(uuid1())
|
||||
self.uuid = uuid
|
||||
@ -112,6 +114,11 @@ class BaseBorgRepository(abc.ABC):
|
||||
"""Return the storage type of repository."""
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def is_usable():
|
||||
"""Return whether the repository is ready to be used."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def repo_path(self):
|
||||
"""Return the repository that the backups action script should use."""
|
||||
@ -340,6 +347,10 @@ class SshBorgRepository(BaseBorgRepository):
|
||||
sort_order = 30
|
||||
flags = {'removable': True, 'mountable': True}
|
||||
|
||||
def is_usable(self):
|
||||
"""Return whether repository is usable."""
|
||||
return self.kwargs.get('verified')
|
||||
|
||||
@property
|
||||
def repo_path(self):
|
||||
"""
|
||||
@ -414,10 +425,7 @@ def get_repositories():
|
||||
for uuid in store.get_storages():
|
||||
repositories.append(create_repository(uuid))
|
||||
|
||||
return [
|
||||
repository.get_view_content()
|
||||
for repository in sorted(repositories, key=lambda x: x.sort_order)
|
||||
]
|
||||
return sorted(repositories, key=lambda x: x.sort_order)
|
||||
|
||||
|
||||
def create_repository(uuid):
|
||||
|
||||
@ -60,7 +60,9 @@ class IndexView(TemplateView):
|
||||
context['title'] = backups.name
|
||||
context['description'] = backups.description
|
||||
context['manual_page'] = backups.manual_page
|
||||
context['repositories'] = get_repositories()
|
||||
context['repositories'] = [
|
||||
repository.get_view_content() for repository in get_repositories()
|
||||
]
|
||||
return context
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user