mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-05 07:49:10 -07:00
[PR #9322/d539b00d backport][stable-10] connection plugins: use f-strings (#9358)
connection plugins: use f-strings (#9322)
* connection plugins: use f-strings
* add changelog frag
(cherry picked from commit d539b00d4c
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
122086e83b
commit
a13a6d284c
11 changed files with 105 additions and 99 deletions
|
@ -82,7 +82,7 @@ class Connection(ConnectionBase):
|
|||
self._display.vvv("THIS IS A LOCAL LXC DIR", host=self.container_name)
|
||||
self.container = _lxc.Container(self.container_name)
|
||||
if self.container.state == "STOPPED":
|
||||
raise errors.AnsibleError("%s is not running" % self.container_name)
|
||||
raise errors.AnsibleError(f"{self.container_name} is not running")
|
||||
|
||||
@staticmethod
|
||||
def _communicate(pid, in_data, stdin, stdout, stderr):
|
||||
|
@ -144,10 +144,10 @@ class Connection(ConnectionBase):
|
|||
read_stdin, write_stdin = os.pipe()
|
||||
kwargs['stdin'] = self._set_nonblocking(read_stdin)
|
||||
|
||||
self._display.vvv("EXEC %s" % (local_cmd), host=self.container_name)
|
||||
self._display.vvv(f"EXEC {local_cmd}", host=self.container_name)
|
||||
pid = self.container.attach(_lxc.attach_run_command, local_cmd, **kwargs)
|
||||
if pid == -1:
|
||||
msg = "failed to attach to container %s" % self.container_name
|
||||
msg = f"failed to attach to container {self.container_name}"
|
||||
raise errors.AnsibleError(msg)
|
||||
|
||||
write_stdout = os.close(write_stdout)
|
||||
|
@ -174,18 +174,18 @@ class Connection(ConnectionBase):
|
|||
def put_file(self, in_path, out_path):
|
||||
''' transfer a file from local to lxc '''
|
||||
super(Connection, self).put_file(in_path, out_path)
|
||||
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.container_name)
|
||||
self._display.vvv(f"PUT {in_path} TO {out_path}", host=self.container_name)
|
||||
in_path = to_bytes(in_path, errors='surrogate_or_strict')
|
||||
out_path = to_bytes(out_path, errors='surrogate_or_strict')
|
||||
|
||||
if not os.path.exists(in_path):
|
||||
msg = "file or module does not exist: %s" % in_path
|
||||
msg = f"file or module does not exist: {in_path}"
|
||||
raise errors.AnsibleFileNotFound(msg)
|
||||
try:
|
||||
src_file = open(in_path, "rb")
|
||||
except IOError:
|
||||
traceback.print_exc()
|
||||
raise errors.AnsibleError("failed to open input file to %s" % in_path)
|
||||
raise errors.AnsibleError(f"failed to open input file to {in_path}")
|
||||
try:
|
||||
def write_file(args):
|
||||
with open(out_path, 'wb+') as dst_file:
|
||||
|
@ -194,7 +194,7 @@ class Connection(ConnectionBase):
|
|||
self.container.attach_wait(write_file, None)
|
||||
except IOError:
|
||||
traceback.print_exc()
|
||||
msg = "failed to transfer file to %s" % out_path
|
||||
msg = f"failed to transfer file to {out_path}"
|
||||
raise errors.AnsibleError(msg)
|
||||
finally:
|
||||
src_file.close()
|
||||
|
@ -202,7 +202,7 @@ class Connection(ConnectionBase):
|
|||
def fetch_file(self, in_path, out_path):
|
||||
''' fetch a file from lxc to local '''
|
||||
super(Connection, self).fetch_file(in_path, out_path)
|
||||
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.container_name)
|
||||
self._display.vvv(f"FETCH {in_path} TO {out_path}", host=self.container_name)
|
||||
in_path = to_bytes(in_path, errors='surrogate_or_strict')
|
||||
out_path = to_bytes(out_path, errors='surrogate_or_strict')
|
||||
|
||||
|
@ -210,7 +210,7 @@ class Connection(ConnectionBase):
|
|||
dst_file = open(out_path, "wb")
|
||||
except IOError:
|
||||
traceback.print_exc()
|
||||
msg = "failed to open output file %s" % out_path
|
||||
msg = f"failed to open output file {out_path}"
|
||||
raise errors.AnsibleError(msg)
|
||||
try:
|
||||
def write_file(args):
|
||||
|
@ -225,7 +225,7 @@ class Connection(ConnectionBase):
|
|||
self.container.attach_wait(write_file, None)
|
||||
except IOError:
|
||||
traceback.print_exc()
|
||||
msg = "failed to transfer file from %s to %s" % (in_path, out_path)
|
||||
msg = f"failed to transfer file from {in_path} to {out_path}"
|
||||
raise errors.AnsibleError(msg)
|
||||
finally:
|
||||
dst_file.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue