mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
backups: Remove unnecessary context manager for paramiko SFTPClient
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
9f71c5867e
commit
795ed9d735
@ -410,7 +410,7 @@ def _validate_remote_repository(path, credentials, uuid=None):
|
|||||||
password = credentials['ssh_password']
|
password = credentials['ssh_password']
|
||||||
repository = None
|
repository = None
|
||||||
with _ssh_connection(hostname, username, password) as ssh_client:
|
with _ssh_connection(hostname, username, password) as ssh_client:
|
||||||
with _sftp_client(ssh_client) as sftp_client:
|
with ssh_client.open_sftp() as sftp_client:
|
||||||
dir_contents = None
|
dir_contents = None
|
||||||
try:
|
try:
|
||||||
dir_contents = sftp_client.listdir(dir_path)
|
dir_contents = sftp_client.listdir(dir_path)
|
||||||
@ -454,16 +454,6 @@ def _ssh_connection(hostname, username, password):
|
|||||||
ssh_client.close()
|
ssh_client.close()
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def _sftp_client(ssh_client):
|
|
||||||
"""Context manager to create and close an SFTP client."""
|
|
||||||
sftp_client = ssh_client.open_sftp()
|
|
||||||
try:
|
|
||||||
yield sftp_client
|
|
||||||
finally:
|
|
||||||
sftp_client.close()
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveRepositoryView(SuccessMessageMixin, TemplateView):
|
class RemoveRepositoryView(SuccessMessageMixin, TemplateView):
|
||||||
"""View to delete a repository."""
|
"""View to delete a repository."""
|
||||||
template_name = 'backups_repository_remove.html'
|
template_name = 'backups_repository_remove.html'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user