mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-10 11:00:22 +00:00
backups: Minor styling fixes
- More descriptive iteration variables - Run yafp, isort Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
dc781b03fa
commit
670f58019e
@ -84,10 +84,10 @@ def _backup_handler(packet):
|
||||
manifest_path = MANIFESTS_FOLDER + get_valid_filename(
|
||||
packet.label) + '.json'
|
||||
manifests = [{
|
||||
'name': x[0],
|
||||
'version': x[1].version,
|
||||
'backup': x[2]
|
||||
} for x in packet.manifests]
|
||||
'name': manifest[0],
|
||||
'version': manifest[1].version,
|
||||
'backup': manifest[2]
|
||||
} for manifest in packet.manifests]
|
||||
with open(manifest_path, 'w') as manifest_file:
|
||||
json.dump(manifests, manifest_file)
|
||||
|
||||
@ -134,7 +134,7 @@ def get_export_files():
|
||||
export_files = {}
|
||||
for location in locations:
|
||||
output = actions.superuser_run(
|
||||
'backups', ['list-exports', '--location', location[0]])
|
||||
'backups', ['list-exports', '--location', location[0]])
|
||||
export_files[location[1]] = json.loads(output)
|
||||
|
||||
return export_files
|
||||
@ -157,21 +157,17 @@ def find_exported_archive(disk_label, archive_name):
|
||||
|
||||
def get_export_apps(filename):
|
||||
"""Get list of apps included in exported archive file."""
|
||||
output = actions.superuser_run(
|
||||
'backups', ['get-export-apps', '--filename', filename])
|
||||
output = actions.superuser_run('backups',
|
||||
['get-export-apps', '--filename', filename])
|
||||
return output.splitlines()
|
||||
|
||||
|
||||
def _restore_handler(packet):
|
||||
"""Perform restore operation on packet."""
|
||||
locations = {
|
||||
'directories': packet.directories,
|
||||
'files': packet.files
|
||||
}
|
||||
locations = {'directories': packet.directories, 'files': packet.files}
|
||||
locations_data = json.dumps(locations)
|
||||
actions.superuser_run(
|
||||
'backups', ['restore', '--filename', packet.label],
|
||||
input=locations_data.encode())
|
||||
actions.superuser_run('backups', ['restore', '--filename', packet.label],
|
||||
input=locations_data.encode())
|
||||
|
||||
|
||||
def restore_exported(label, name, apps=None):
|
||||
|
||||
@ -91,9 +91,9 @@ class Packet:
|
||||
"""Look at manifests and fill up the list of directories/files."""
|
||||
for manifest in self.manifests:
|
||||
backup = manifest[2]
|
||||
for x in ['config', 'data', 'secrets']:
|
||||
self.directories += backup[x]['directories']
|
||||
self.files += backup[x]['files']
|
||||
for section in ['config', 'data', 'secrets']:
|
||||
self.directories += backup[section]['directories']
|
||||
self.files += backup[section]['files']
|
||||
|
||||
|
||||
def backup_full(backup_handler, label=None):
|
||||
|
||||
@ -58,11 +58,11 @@ class TestBackups(unittest.TestCase):
|
||||
packet = Packet('backup', 'apps', '/', manifests)
|
||||
for manifest in manifests:
|
||||
backup = manifest[2]
|
||||
for x in ['config', 'data', 'secrets']:
|
||||
for d in backup[x]['directories']:
|
||||
assert d in packet.directories
|
||||
for f in backup[x]['files']:
|
||||
assert f in packet.files
|
||||
for section in ['config', 'data', 'secrets']:
|
||||
for directory in backup[section]['directories']:
|
||||
assert directory in packet.directories
|
||||
for file_path in backup[section]['files']:
|
||||
assert file_path in packet.files
|
||||
|
||||
def test_backup_apps(self):
|
||||
"""Test that backup_handler is called."""
|
||||
@ -88,7 +88,7 @@ class TestBackups(unittest.TestCase):
|
||||
load_modules()
|
||||
app_names = ['config', 'names']
|
||||
apps = _get_apps_in_order(app_names)
|
||||
ordered_app_names = [x[0] for x in apps]
|
||||
ordered_app_names = [app[0] for app in apps]
|
||||
|
||||
names_index = ordered_app_names.index('names')
|
||||
config_index = ordered_app_names.index('config')
|
||||
|
||||
@ -19,6 +19,7 @@ Views for the backups app.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from urllib.parse import unquote
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
@ -27,7 +28,6 @@ from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import FormView, TemplateView
|
||||
from urllib.parse import unquote
|
||||
|
||||
from plinth.modules import backups
|
||||
|
||||
@ -49,7 +49,7 @@ class IndexView(TemplateView):
|
||||
context['archives'] = backups.list_archives()
|
||||
context['exports'] = backups.get_export_files()
|
||||
apps = backups_api.get_all_apps_for_backup()
|
||||
context['available_apps'] = [x[0] for x in apps]
|
||||
context['available_apps'] = [app[0] for app in apps]
|
||||
return context
|
||||
|
||||
|
||||
@ -122,8 +122,7 @@ class ExportArchiveView(SuccessMessageMixin, FormView):
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Create the archive on valid form submission."""
|
||||
backups.export_archive(self.kwargs['name'],
|
||||
form.cleaned_data['disk'])
|
||||
backups.export_archive(self.kwargs['name'], form.cleaned_data['disk'])
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@ -157,7 +156,8 @@ class RestoreView(SuccessMessageMixin, FormView):
|
||||
"""Pass additional keyword args for instantiating the form."""
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['apps'] = [
|
||||
x for x in self.installed_apps if x[0] in self.included_apps]
|
||||
app for app in self.installed_apps if app[0] in self.included_apps
|
||||
]
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@ -170,7 +170,7 @@ class RestoreView(SuccessMessageMixin, FormView):
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Restore files from the archive on valid form submission."""
|
||||
backups.restore_exported(unquote(self.kwargs['label']),
|
||||
self.kwargs['name'],
|
||||
form.cleaned_data['selected_apps'])
|
||||
backups.restore_exported(
|
||||
unquote(self.kwargs['label']), self.kwargs['name'],
|
||||
form.cleaned_data['selected_apps'])
|
||||
return super().form_valid(form)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user