backups: Minor cosmetic fixes

- Remove some pylint warnings

- Add documentation strings.

- Yapf auto-formatting.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-08-28 11:09:18 -07:00 committed by James Valleroy
parent 0b0791d78f
commit e8b324eece
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 20 additions and 13 deletions

View File

@ -107,6 +107,7 @@ class BaseBorgRepository(abc.ABC):
@property @property
def name(self): def name(self):
"""Return a display name for the repository."""
return self._path return self._path
@abc.abstractmethod @abc.abstractmethod
@ -142,6 +143,7 @@ class BaseBorgRepository(abc.ABC):
self._path = storage['path'] self._path = storage['path']
def get_info(self): def get_info(self):
"""Return Borg information about a repository."""
output = self.run(['info', '--path', self.repo_path]) output = self.run(['info', '--path', self.repo_path])
return json.loads(output) return json.loads(output)
@ -165,7 +167,6 @@ class BaseBorgRepository(abc.ABC):
def remove_repository(self): def remove_repository(self):
"""Remove a borg repository""" """Remove a borg repository"""
pass
def list_archives(self): def list_archives(self):
output = self.run(['list-repo', '--path', self.repo_path]) output = self.run(['list-repo', '--path', self.repo_path])
@ -285,14 +286,17 @@ class BaseBorgRepository(abc.ABC):
} }
if self.uuid: if self.uuid:
storage['uuid'] = self.uuid storage['uuid'] = self.uuid
if store_credentials: if store_credentials:
storage['credentials'] = self.credentials storage['credentials'] = self.credentials
return storage return storage
def save(self, store_credentials=True, verified=False): def save(self, store_credentials=True, verified=False):
""" """Save the repository in store (kvstore).
Save the repository in network_storage (kvstore).
- store_credentials: Boolean whether credentials should be stored. - store_credentials: Boolean whether credentials should be stored.
""" """
storage = self._get_storage_format(store_credentials, verified) storage = self._get_storage_format(store_credentials, verified)
self.uuid = store.update_or_add(storage) self.uuid = store.update_or_add(storage)
@ -363,15 +367,18 @@ class SshBorgRepository(BaseBorgRepository):
@property @property
def mountpoint(self): def mountpoint(self):
"""Return the local mount point where repository is to be mounted."""
return os.path.join(self.SSHFS_MOUNTPOINT, self.uuid) return os.path.join(self.SSHFS_MOUNTPOINT, self.uuid)
@property @property
def is_mounted(self): def is_mounted(self):
"""Return whether remote path is mounted locally."""
output = self._run('sshfs', output = self._run('sshfs',
['is-mounted', '--mountpoint', self.mountpoint]) ['is-mounted', '--mountpoint', self.mountpoint])
return json.loads(output) return json.loads(output)
def mount(self): def mount(self):
"""Mount the remote path locally using sshfs."""
if self.is_mounted: if self.is_mounted:
return return
known_hosts_path = get_known_hosts_path() known_hosts_path = get_known_hosts_path()
@ -385,6 +392,7 @@ class SshBorgRepository(BaseBorgRepository):
self._run('sshfs', arguments, **kwargs) self._run('sshfs', arguments, **kwargs)
def umount(self): def umount(self):
"""Unmount the remote path that was mounted locally using sshfs."""
if not self.is_mounted: if not self.is_mounted:
return return

View File

@ -38,13 +38,12 @@ from django.views.generic import FormView, TemplateView, View
from plinth.errors import PlinthError from plinth.errors import PlinthError
from plinth.modules import backups, storage from plinth.modules import backups, storage
from . import (SESSION_PATH_VARIABLE, api, forms, from . import (SESSION_PATH_VARIABLE, api, forms, get_known_hosts_path,
get_known_hosts_path, is_ssh_hostkey_verified, store, is_ssh_hostkey_verified, split_path, store)
split_path)
from .decorators import delete_tmp_backup_file from .decorators import delete_tmp_backup_file
from .errors import BorgRepositoryDoesNotExistError from .errors import BorgRepositoryDoesNotExistError
from .repository import (BorgRepository, SshBorgRepository, from .repository import (BorgRepository, SshBorgRepository, create_repository,
create_repository, get_repositories) get_repositories)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -236,8 +235,9 @@ class DownloadArchiveView(View):
repository = create_repository(uuid) repository = create_repository(uuid)
filename = f'{name}.tar.gz' filename = f'{name}.tar.gz'
response = StreamingHttpResponse(repository.get_download_stream(name), response = StreamingHttpResponse(
content_type='application/gzip') repository.get_download_stream(name),
content_type='application/gzip')
response['Content-Disposition'] = 'attachment; filename="%s"' % \ response['Content-Disposition'] = 'attachment; filename="%s"' % \
filename filename
return response return response
@ -476,9 +476,8 @@ class RemoveRepositoryView(SuccessMessageMixin, TemplateView):
"""Delete the repository on confirmation.""" """Delete the repository on confirmation."""
repository = create_repository(uuid) repository = create_repository(uuid)
repository.remove_repository() repository.remove_repository()
messages.success( messages.success(request,
request, _('Repository removed. Backups were not deleted.'))
_('Repository removed. Backups were not deleted.'))
return redirect('backups:index') return redirect('backups:index')