From 0ce97005b2e842bba7861ed22a32f573bad2e22f Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Fri, 28 Sep 2018 11:04:21 -0700 Subject: [PATCH] backups: Rename the backups API module - Also other minor refactoring. Reviewed-by: James Valleroy --- plinth/modules/backups/__init__.py | 8 ++++---- plinth/modules/backups/{backups.py => api.py} | 0 plinth/modules/backups/forms.py | 4 ++-- plinth/modules/backups/views.py | 15 +++++++-------- plinth/modules/dynamicdns/manifest.py | 2 +- plinth/modules/ejabberd/manifest.py | 2 +- plinth/modules/ikiwiki/manifest.py | 2 +- plinth/modules/infinoted/manifest.py | 2 +- plinth/modules/matrixsynapse/manifest.py | 2 +- plinth/modules/mediawiki/manifest.py | 2 +- plinth/modules/minetest/manifest.py | 2 +- plinth/modules/radicale/manifest.py | 2 +- plinth/modules/repro/manifest.py | 2 +- 13 files changed, 22 insertions(+), 23 deletions(-) rename plinth/modules/backups/{backups.py => api.py} (100%) diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index 357aa3c7b..19ca99338 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -29,7 +29,7 @@ from plinth.errors import PlinthError from plinth.menu import main_menu from plinth.modules import storage -from .backups import backup_apps, restore_apps +from . import api version = 1 @@ -100,7 +100,7 @@ def _backup_handler(packet): def create_archive(name, app_names): - backup_apps(_backup_handler, app_names, name) + api.backup_apps(_backup_handler, app_names, name) def delete_archive(name): @@ -177,5 +177,5 @@ def _restore_handler(packet): def restore_exported(label, archive_name, apps=None): """Restore files from exported backup archive.""" filename = find_exported_archive(label, archive_name) - restore_apps(_restore_handler, app_names=apps, create_subvolume=False, - backup_file=filename) + api.restore_apps(_restore_handler, app_names=apps, create_subvolume=False, + backup_file=filename) diff --git a/plinth/modules/backups/backups.py b/plinth/modules/backups/api.py similarity index 100% rename from plinth/modules/backups/backups.py rename to plinth/modules/backups/api.py diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index f97cf8534..9dcfea0b1 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -25,7 +25,7 @@ from django.core import validators from django.core.validators import FileExtensionValidator from django.utils.translation import ugettext_lazy as _ -from . import backups as backups_api +from . import api from . import get_export_locations, get_archive_path, get_location_path @@ -44,7 +44,7 @@ class CreateArchiveForm(forms.Form): def __init__(self, *args, **kwargs): """Initialize the form with selectable apps.""" super().__init__(*args, **kwargs) - apps = backups_api.get_all_apps_for_backup() + apps = api.get_all_apps_for_backup() self.fields['selected_apps'].choices = [ (app[0], app[1].name) for app in apps] self.fields['selected_apps'].initial = [app[0] for app in apps] diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index f86ce49cb..ea1ff11b1 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -34,8 +34,7 @@ from django.views.generic import View, FormView, TemplateView from plinth.modules import backups -from . import backups as backups_api, find_exported_archive -from .forms import CreateArchiveForm, ExportArchiveForm, RestoreForm, UploadForm +from . import api, find_exported_archive, forms subsubmenu = [{ @@ -60,14 +59,14 @@ class IndexView(TemplateView): context['archives'] = backups.list_archives() context['exports'] = backups.get_export_files() context['subsubmenu'] = subsubmenu - apps = backups_api.get_all_apps_for_backup() + apps = api.get_all_apps_for_backup() context['available_apps'] = [app[0] for app in apps] return context class CreateArchiveView(SuccessMessageMixin, FormView): """View to create a new archive.""" - form_class = CreateArchiveForm + form_class = forms.CreateArchiveForm prefix = 'backups' template_name = 'backups_form.html' success_url = reverse_lazy('backups:index') @@ -134,7 +133,7 @@ class DownloadArchiveView(View): class UploadArchiveView(SuccessMessageMixin, FormView): - form_class = UploadForm + form_class = forms.UploadForm prefix = 'backups' template_name = 'backups_upload.html' success_url = reverse_lazy('backups:index') @@ -157,7 +156,7 @@ class UploadArchiveView(SuccessMessageMixin, FormView): class ExportArchiveView(SuccessMessageMixin, FormView): """View to export an archive.""" - form_class = ExportArchiveForm + form_class = forms.ExportArchiveForm prefix = 'backups' template_name = 'backups_form.html' success_url = reverse_lazy('backups:index') @@ -181,7 +180,7 @@ class ExportArchiveView(SuccessMessageMixin, FormView): class RestoreView(SuccessMessageMixin, FormView): """View to restore files from an exported archive.""" - form_class = RestoreForm + form_class = forms.RestoreForm prefix = 'backups' template_name = 'backups_restore.html' success_url = reverse_lazy('backups:index') @@ -198,7 +197,7 @@ class RestoreView(SuccessMessageMixin, FormView): """Pass additional keyword args for instantiating the form.""" kwargs = super().get_form_kwargs() included_apps = self._get_included_apps() - installed_apps = backups_api.get_all_apps_for_backup() + installed_apps = api.get_all_apps_for_backup() kwargs['apps'] = [ app for app in installed_apps if app[0] in included_apps ] diff --git a/plinth/modules/dynamicdns/manifest.py b/plinth/modules/dynamicdns/manifest.py index 94c29ef86..3843d27ff 100644 --- a/plinth/modules/dynamicdns/manifest.py +++ b/plinth/modules/dynamicdns/manifest.py @@ -15,6 +15,6 @@ # along with this program. If not, see . # -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup backup = validate_backup({'config': {'directories': ['/etc/ez-ipupdate/']}}) diff --git a/plinth/modules/ejabberd/manifest.py b/plinth/modules/ejabberd/manifest.py index 698abca1e..396489b71 100644 --- a/plinth/modules/ejabberd/manifest.py +++ b/plinth/modules/ejabberd/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import store_url, validate from plinth.modules.jsxc import manifest as jsxc_manifest diff --git a/plinth/modules/ikiwiki/manifest.py b/plinth/modules/ikiwiki/manifest.py index c44522a89..b5fcda0e7 100644 --- a/plinth/modules/ikiwiki/manifest.py +++ b/plinth/modules/ikiwiki/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import validate clients = validate([{ diff --git a/plinth/modules/infinoted/manifest.py b/plinth/modules/infinoted/manifest.py index a0dc80e4c..f37687274 100644 --- a/plinth/modules/infinoted/manifest.py +++ b/plinth/modules/infinoted/manifest.py @@ -18,7 +18,7 @@ from django.utils.translation import ugettext_lazy as _ from plinth import cfg -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import validate from plinth.utils import format_lazy diff --git a/plinth/modules/matrixsynapse/manifest.py b/plinth/modules/matrixsynapse/manifest.py index ddffec4eb..1f86c6c74 100644 --- a/plinth/modules/matrixsynapse/manifest.py +++ b/plinth/modules/matrixsynapse/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import store_url, validate _android_package_id = 'im.vector.alpha' diff --git a/plinth/modules/mediawiki/manifest.py b/plinth/modules/mediawiki/manifest.py index 62ee002e7..4c0e779a3 100644 --- a/plinth/modules/mediawiki/manifest.py +++ b/plinth/modules/mediawiki/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import validate clients = validate([{ diff --git a/plinth/modules/minetest/manifest.py b/plinth/modules/minetest/manifest.py index 9769c1f13..a80738a01 100644 --- a/plinth/modules/minetest/manifest.py +++ b/plinth/modules/minetest/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import store_url, validate clients = validate([{ diff --git a/plinth/modules/radicale/manifest.py b/plinth/modules/radicale/manifest.py index beaa71571..cd7d416b2 100644 --- a/plinth/modules/radicale/manifest.py +++ b/plinth/modules/radicale/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import store_url, validate clients = validate([{ diff --git a/plinth/modules/repro/manifest.py b/plinth/modules/repro/manifest.py index 8598c9c0f..a0087faf8 100644 --- a/plinth/modules/repro/manifest.py +++ b/plinth/modules/repro/manifest.py @@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _ -from plinth.modules.backups.backups import validate as validate_backup +from plinth.modules.backups.api import validate as validate_backup from plinth.clients import store_url, validate _jitsi_package_id = 'org.jitsi.meet'