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
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

View File

@ -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')