Commit 64fcf006 authored by Joseph Nuthalapati's avatar Joseph Nuthalapati

backups: Make getting all apps method public

parent 498759da
...@@ -126,7 +126,7 @@ def restore_full(restore_handler): ...@@ -126,7 +126,7 @@ def restore_full(restore_handler):
def backup_apps(backup_handler, app_names=None, label=None): def backup_apps(backup_handler, app_names=None, label=None):
"""Backup data belonging to a set of applications.""" """Backup data belonging to a set of applications."""
if not app_names: if not app_names:
apps = _list_of_all_apps_for_backup() apps = get_all_apps_for_backup()
else: else:
apps = _get_apps_in_order(app_names) apps = _get_apps_in_order(app_names)
...@@ -156,7 +156,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True, ...@@ -156,7 +156,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
backup_file=None): backup_file=None):
"""Restore data belonging to a set of applications.""" """Restore data belonging to a set of applications."""
if not app_names: if not app_names:
apps = _list_of_all_apps_for_backup() apps = get_all_apps_for_backup()
else: else:
apps = _get_apps_in_order(app_names) apps = _get_apps_in_order(app_names)
...@@ -182,7 +182,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True, ...@@ -182,7 +182,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
_lockdown_apps(apps, lockdown=False) _lockdown_apps(apps, lockdown=False)
def _list_of_all_apps_for_backup(): def get_all_apps_for_backup():
"""Return a list of all applications that can be backed up.""" """Return a list of all applications that can be backed up."""
apps = [] apps = []
for module_name, module in module_loader.loaded_modules.items(): for module_name, module in module_loader.loaded_modules.items():
......
...@@ -22,8 +22,8 @@ from django import forms ...@@ -22,8 +22,8 @@ from django import forms
from django.core import validators from django.core import validators
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from . import backups as backups_api
from . import get_export_locations from . import get_export_locations
from .backups import _list_of_all_apps_for_backup
class CreateArchiveForm(forms.Form): class CreateArchiveForm(forms.Form):
...@@ -41,7 +41,7 @@ class CreateArchiveForm(forms.Form): ...@@ -41,7 +41,7 @@ class CreateArchiveForm(forms.Form):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Initialize the form with selectable apps.""" """Initialize the form with selectable apps."""
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
apps = _list_of_all_apps_for_backup() apps = backups_api.get_all_apps_for_backup()
self.fields['selected_apps'].choices = [ self.fields['selected_apps'].choices = [
(app[0], app[1].name) for app in apps] (app[0], app[1].name) for app in apps]
self.fields['selected_apps'].initial = [app[0] for app in apps] self.fields['selected_apps'].initial = [app[0] for app in apps]
......
...@@ -24,7 +24,7 @@ from unittest.mock import call, patch, MagicMock ...@@ -24,7 +24,7 @@ from unittest.mock import call, patch, MagicMock
from plinth.module_loader import load_modules from plinth.module_loader import load_modules
from ..backups import validate, Packet, backup_apps, restore_apps, \ from ..backups import validate, Packet, backup_apps, restore_apps, \
_list_of_all_apps_for_backup, _get_apps_in_order, _get_manifests, \ get_all_apps_for_backup, _get_apps_in_order, _get_manifests, \
_lockdown_apps, _shutdown_services, _restore_services _lockdown_apps, _shutdown_services, _restore_services
...@@ -76,10 +76,10 @@ class TestBackups(unittest.TestCase): ...@@ -76,10 +76,10 @@ class TestBackups(unittest.TestCase):
restore_apps(restore_handler) restore_apps(restore_handler)
restore_handler.assert_called_once() restore_handler.assert_called_once()
def test__list_of_all_apps_for_backups(self): def test_get_all_apps_for_backups(self):
"""Test that apps supporting backup are included in returned list.""" """Test that apps supporting backup are included in returned list."""
load_modules() load_modules()
apps = _list_of_all_apps_for_backup() apps = get_all_apps_for_backup()
assert isinstance(apps, list) assert isinstance(apps, list)
# apps may be empty, if no apps supporting backup are installed. # apps may be empty, if no apps supporting backup are installed.
......
...@@ -30,8 +30,9 @@ from django.views.generic import FormView, TemplateView ...@@ -30,8 +30,9 @@ from django.views.generic import FormView, TemplateView
from urllib.parse import unquote from urllib.parse import unquote
from plinth.modules import backups from plinth.modules import backups
from . import backups as backups_api
from . import find_exported_archive, get_export_apps from . import find_exported_archive, get_export_apps
from .backups import _list_of_all_apps_for_backup
from .forms import CreateArchiveForm, ExportArchiveForm, RestoreForm from .forms import CreateArchiveForm, ExportArchiveForm, RestoreForm
...@@ -47,7 +48,7 @@ class IndexView(TemplateView): ...@@ -47,7 +48,7 @@ class IndexView(TemplateView):
context['info'] = backups.get_info() context['info'] = backups.get_info()
context['archives'] = backups.list_archives() context['archives'] = backups.list_archives()
context['exports'] = backups.get_export_files() context['exports'] = backups.get_export_files()
apps = _list_of_all_apps_for_backup() apps = backups_api.get_all_apps_for_backup()
context['available_apps'] = [x[0] for x in apps] context['available_apps'] = [x[0] for x in apps]
return context return context
...@@ -139,7 +140,7 @@ class RestoreView(SuccessMessageMixin, FormView): ...@@ -139,7 +140,7 @@ class RestoreView(SuccessMessageMixin, FormView):
self.label = unquote(label) self.label = unquote(label)
self.name = unquote(name) self.name = unquote(name)
self.filename = find_exported_archive(self.label, self.name) self.filename = find_exported_archive(self.label, self.name)
self.installed_apps = _list_of_all_apps_for_backup() self.installed_apps = backups_api.get_all_apps_for_backup()
self.included_apps = get_export_apps(self.filename) self.included_apps = get_export_apps(self.filename)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment