mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 03:46:55 +00:00
Python code modernization, 5/n (#1165)
* Address raise-missing-from. * Address simplifiable-if-expression. * Address unnecessary-dunder-call. * Address unnecessary-pass. * Address use-list-literal. * Address unused-variable. * Address use-dict-literal.
This commit is contained in:
@@ -158,15 +158,15 @@ class Connection(ConnectionBase):
|
||||
if not_found_can_be_resource:
|
||||
raise AnsibleConnectionFailure(
|
||||
f'Could not find container "{remote_addr}" or resource in it ({e})'
|
||||
)
|
||||
) from e
|
||||
raise AnsibleConnectionFailure(
|
||||
f'Could not find container "{remote_addr}" ({e})'
|
||||
)
|
||||
) from e
|
||||
except APIError as e:
|
||||
if e.response is not None and e.response.status_code == 409:
|
||||
raise AnsibleConnectionFailure(
|
||||
f'The container "{remote_addr}" has been paused ({e})'
|
||||
)
|
||||
) from e
|
||||
self.client.fail(
|
||||
f'An unexpected Docker error occurred for container "{remote_addr}": {e}'
|
||||
)
|
||||
@@ -183,7 +183,7 @@ class Connection(ConnectionBase):
|
||||
super().__init__(play_context, new_stdin, *args, **kwargs)
|
||||
|
||||
self.client = None
|
||||
self.ids = dict()
|
||||
self.ids = {}
|
||||
|
||||
# Windows uses Powershell modules
|
||||
if getattr(self._shell, "_IS_WINDOWS", False):
|
||||
@@ -239,7 +239,7 @@ class Connection(ConnectionBase):
|
||||
host=self.get_option("remote_addr"),
|
||||
)
|
||||
|
||||
need_stdin = True if (in_data is not None) or do_become else False
|
||||
need_stdin = bool((in_data is not None) or do_become)
|
||||
|
||||
data = {
|
||||
"Container": self.get_option("remote_addr"),
|
||||
@@ -393,7 +393,7 @@ class Connection(ConnectionBase):
|
||||
except Exception as e:
|
||||
raise AnsibleConnectionFailure(
|
||||
f'Error while determining user and group ID of current user in container "{remote_addr}": {e}\nGot value: {ids!r}'
|
||||
)
|
||||
) from e
|
||||
|
||||
user_id, group_id = self.ids[self.actual_user]
|
||||
try:
|
||||
@@ -411,9 +411,9 @@ class Connection(ConnectionBase):
|
||||
not_found_can_be_resource=True,
|
||||
)
|
||||
except DockerFileNotFound as exc:
|
||||
raise AnsibleFileNotFound(to_native(exc))
|
||||
raise AnsibleFileNotFound(to_native(exc)) from exc
|
||||
except DockerFileCopyError as exc:
|
||||
raise AnsibleConnectionFailure(to_native(exc))
|
||||
raise AnsibleConnectionFailure(to_native(exc)) from exc
|
||||
|
||||
def fetch_file(self, in_path, out_path):
|
||||
"""Fetch a file from container to local."""
|
||||
@@ -439,9 +439,9 @@ class Connection(ConnectionBase):
|
||||
not_found_can_be_resource=True,
|
||||
)
|
||||
except DockerFileNotFound as exc:
|
||||
raise AnsibleFileNotFound(to_native(exc))
|
||||
raise AnsibleFileNotFound(to_native(exc)) from exc
|
||||
except DockerFileCopyError as exc:
|
||||
raise AnsibleConnectionFailure(to_native(exc))
|
||||
raise AnsibleConnectionFailure(to_native(exc)) from exc
|
||||
|
||||
def close(self):
|
||||
"""Terminate the connection. Nothing to do for Docker"""
|
||||
|
||||
Reference in New Issue
Block a user