backups: Minor cosmetic changes

- Add documentation strings.

- Styling blank lines.

- 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 16:26:45 -07:00 committed by James Valleroy
parent 7467fa4553
commit 357e9a412a
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 9 additions and 2 deletions

View File

@ -108,8 +108,9 @@ def _backup_handler(packet, encryption_passphrase=None):
arguments = ['create-archive', '--path', packet.path, '--paths'] + paths
input_data = ''
if encryption_passphrase:
input_data = json.dumps(
{'encryption_passphrase': encryption_passphrase})
input_data = json.dumps({
'encryption_passphrase': encryption_passphrase
})
actions.superuser_run('backups', arguments, input=input_data.encode())

View File

@ -166,18 +166,21 @@ class BaseBorgRepository(abc.ABC):
"""Remove a borg repository"""
def list_archives(self):
"""Return list of archives in this repository."""
output = self.run(['list-repo', '--path', self.borg_path])
archives = json.loads(output)['archives']
return sorted(archives, key=lambda archive: archive['start'],
reverse=True)
def create_archive(self, archive_name, app_names):
"""Create a new archive in this repository with given name."""
archive_path = self._get_archive_path(archive_name)
passphrase = self.credentials.get('encryption_passphrase', None)
api.backup_apps(_backup_handler, path=archive_path,
app_names=app_names, encryption_passphrase=passphrase)
def delete_archive(self, archive_name):
"""Delete an archive with given name from this repository."""
archive_path = self._get_archive_path(archive_name)
self.run(['delete-archive', '--path', archive_path])
@ -256,9 +259,11 @@ class BaseBorgRepository(abc.ABC):
raise err
def get_archive(self, name):
"""Return a specific archive from this repository with given name."""
for archive in self.list_archives():
if archive['name'] == name:
return archive
return None
def get_archive_apps(self, archive_name):
@ -268,6 +273,7 @@ class BaseBorgRepository(abc.ABC):
return output.splitlines()
def restore_archive(self, archive_name, apps=None):
"""Restore an archive from this repository to the system."""
archive_path = self._get_archive_path(archive_name)
passphrase = self.credentials.get('encryption_passphrase', None)
api.restore_apps(restore_archive_handler, app_names=apps,