From e8b324eecef6ac0305216e9f99e7856f7bf6cad1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 28 Aug 2019 11:09:18 -0700 Subject: [PATCH] backups: Minor cosmetic fixes - Remove some pylint warnings - Add documentation strings. - Yapf auto-formatting. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/backups/repository.py | 14 +++++++++++--- plinth/modules/backups/views.py | 19 +++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/plinth/modules/backups/repository.py b/plinth/modules/backups/repository.py index e8dd925e8..819bde4e1 100644 --- a/plinth/modules/backups/repository.py +++ b/plinth/modules/backups/repository.py @@ -107,6 +107,7 @@ class BaseBorgRepository(abc.ABC): @property def name(self): + """Return a display name for the repository.""" return self._path @abc.abstractmethod @@ -142,6 +143,7 @@ class BaseBorgRepository(abc.ABC): self._path = storage['path'] def get_info(self): + """Return Borg information about a repository.""" output = self.run(['info', '--path', self.repo_path]) return json.loads(output) @@ -165,7 +167,6 @@ class BaseBorgRepository(abc.ABC): def remove_repository(self): """Remove a borg repository""" - pass def list_archives(self): output = self.run(['list-repo', '--path', self.repo_path]) @@ -285,14 +286,17 @@ class BaseBorgRepository(abc.ABC): } if self.uuid: storage['uuid'] = self.uuid + if store_credentials: storage['credentials'] = self.credentials + return storage def save(self, store_credentials=True, verified=False): - """ - Save the repository in network_storage (kvstore). + """Save the repository in store (kvstore). + - store_credentials: Boolean whether credentials should be stored. + """ storage = self._get_storage_format(store_credentials, verified) self.uuid = store.update_or_add(storage) @@ -363,15 +367,18 @@ class SshBorgRepository(BaseBorgRepository): @property def mountpoint(self): + """Return the local mount point where repository is to be mounted.""" return os.path.join(self.SSHFS_MOUNTPOINT, self.uuid) @property def is_mounted(self): + """Return whether remote path is mounted locally.""" output = self._run('sshfs', ['is-mounted', '--mountpoint', self.mountpoint]) return json.loads(output) def mount(self): + """Mount the remote path locally using sshfs.""" if self.is_mounted: return known_hosts_path = get_known_hosts_path() @@ -385,6 +392,7 @@ class SshBorgRepository(BaseBorgRepository): self._run('sshfs', arguments, **kwargs) def umount(self): + """Unmount the remote path that was mounted locally using sshfs.""" if not self.is_mounted: return diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index 63da39b4d..7165504b5 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -38,13 +38,12 @@ from django.views.generic import FormView, TemplateView, View from plinth.errors import PlinthError from plinth.modules import backups, storage -from . import (SESSION_PATH_VARIABLE, api, forms, - get_known_hosts_path, is_ssh_hostkey_verified, store, - split_path) +from . import (SESSION_PATH_VARIABLE, api, forms, get_known_hosts_path, + is_ssh_hostkey_verified, split_path, store) from .decorators import delete_tmp_backup_file from .errors import BorgRepositoryDoesNotExistError -from .repository import (BorgRepository, SshBorgRepository, - create_repository, get_repositories) +from .repository import (BorgRepository, SshBorgRepository, create_repository, + get_repositories) logger = logging.getLogger(__name__) @@ -236,8 +235,9 @@ class DownloadArchiveView(View): repository = create_repository(uuid) filename = f'{name}.tar.gz' - response = StreamingHttpResponse(repository.get_download_stream(name), - content_type='application/gzip') + response = StreamingHttpResponse( + repository.get_download_stream(name), + content_type='application/gzip') response['Content-Disposition'] = 'attachment; filename="%s"' % \ filename return response @@ -476,9 +476,8 @@ class RemoveRepositoryView(SuccessMessageMixin, TemplateView): """Delete the repository on confirmation.""" repository = create_repository(uuid) repository.remove_repository() - messages.success( - request, - _('Repository removed. Backups were not deleted.')) + messages.success(request, + _('Repository removed. Backups were not deleted.')) return redirect('backups:index')