backups: YAPF formatting

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Joseph Nuthalapati 2019-05-16 17:29:11 +05:30
parent fb67c60a84
commit cbb177414f
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35

View File

@ -19,14 +19,16 @@ Forms for backups module.
""" """
import logging import logging
import paramiko import paramiko
from django import forms from django import forms
from django.core.validators import FileExtensionValidator from django.core.validators import FileExtensionValidator
from django.utils.translation import ugettext, ugettext_lazy as _ from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from plinth.utils import format_lazy from plinth.utils import format_lazy
from . import api, network_storage, ROOT_REPOSITORY_NAME from . import ROOT_REPOSITORY_NAME, api, network_storage
from .errors import BorgRepositoryDoesNotExistError from .errors import BorgRepositoryDoesNotExistError
from .repository import SshBorgRepository from .repository import SshBorgRepository
@ -86,11 +88,10 @@ class RestoreForm(forms.Form):
class UploadForm(forms.Form): class UploadForm(forms.Form):
file = forms.FileField( file = forms.FileField(
label=_('Upload File'), label=_('Upload File'), required=True, validators=[
required=True, FileExtensionValidator(
validators=[FileExtensionValidator( ['gz'], _('Backup files have to be in .tar.gz format'))
['gz'], _('Backup files have to be in .tar.gz format'))], ], help_text=_('Select the backup file you want to upload'))
help_text=_('Select the backup file you want to upload'))
class AddRepositoryForm(forms.Form): class AddRepositoryForm(forms.Form):
@ -102,27 +103,19 @@ class AddRepositoryForm(forms.Form):
label=_('SSH server password'), strip=True, label=_('SSH server password'), strip=True,
help_text=_('Password of the SSH Server.<br />' help_text=_('Password of the SSH Server.<br />'
'SSH key-based authentication is not yet possible.'), 'SSH key-based authentication is not yet possible.'),
widget=forms.PasswordInput(), widget=forms.PasswordInput(), required=False)
required=False)
encryption = forms.ChoiceField( encryption = forms.ChoiceField(
label=_('Encryption'), label=_('Encryption'), help_text=format_lazy(
help_text=format_lazy(
_('"Key in Repository" means that a ' _('"Key in Repository" means that a '
'password-protected key is stored with the backup.')), 'password-protected key is stored with the backup.')),
choices=[('repokey', 'Key in Repository'), ('none', 'None')] choices=[('repokey', 'Key in Repository'), ('none', 'None')])
)
encryption_passphrase = forms.CharField( encryption_passphrase = forms.CharField(
label=_('Passphrase'), label=_('Passphrase'),
help_text=_('Passphrase; Only needed when using encryption.'), help_text=_('Passphrase; Only needed when using encryption.'),
widget=forms.PasswordInput(), widget=forms.PasswordInput(), required=False)
required=False
)
confirm_encryption_passphrase = forms.CharField( confirm_encryption_passphrase = forms.CharField(
label=_('Confirm Passphrase'), label=_('Confirm Passphrase'), help_text=_('Repeat the passphrase.'),
help_text=_('Repeat the passphrase.'), widget=forms.PasswordInput(), required=False)
widget=forms.PasswordInput(),
required=False
)
def get_credentials(self): def get_credentials(self):
credentials = {} credentials = {}
@ -148,8 +141,7 @@ class AddRepositoryForm(forms.Form):
if passphrase != confirm_passphrase: if passphrase != confirm_passphrase:
raise forms.ValidationError( raise forms.ValidationError(
_("The entered encryption passphrases do not match") _("The entered encryption passphrases do not match"))
)
path = cleaned_data.get("repository") path = cleaned_data.get("repository")
credentials = self.get_credentials() credentials = self.get_credentials()