Skip to content

Commit 3ab7a89

Browse files
authored
replace concatenations with f-string in plugins (#10285)
* replace concatenations with f-string in plugins * add changelog frag
1 parent d4f2b2f commit 3ab7a89

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
minor_changes:
2+
- dense callback plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
3+
- mail callback plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
4+
- wsl connection plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
5+
- jc filter plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
6+
- iocage inventory plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
7+
- xen_orchestra inventory plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).

plugins/callback/dense.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,8 @@ def _display_progress(self, result=None):
263263
sys.stdout.write(colors[self.hosts[name]['state']] + name + vt100.reset)
264264
sys.stdout.flush()
265265

266-
# if result._result.get('diff', False):
267-
# sys.stdout.write('\n' + vt100.linewrap)
268266
sys.stdout.write(vt100.linewrap)
269267

270-
# self.keep = True
271-
272268
def _display_task_banner(self):
273269
if not self.shown_title:
274270
self.shown_title = True
@@ -312,12 +308,12 @@ def _display_results(self, result, status):
312308

313309
delegated_vars = result._result.get('_ansible_delegated_vars', None)
314310
if delegated_vars:
315-
sys.stdout.write(f"{vt100.reset + result._host.get_name()}>{colors[status]}{delegated_vars['ansible_host']}")
311+
sys.stdout.write(f"{vt100.reset}{result._host.get_name()}>{colors[status]}{delegated_vars['ansible_host']}")
316312
else:
317313
sys.stdout.write(result._host.get_name())
318314

319315
sys.stdout.write(f": {dump}\n")
320-
sys.stdout.write(vt100.reset + vt100.save + vt100.clearline)
316+
sys.stdout.write(f"{vt100.reset}{vt100.save}{vt100.clearline}")
321317
sys.stdout.flush()
322318

323319
if status == 'changed':

plugins/callback/mail.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def mail_result(self, result, failtype):
212212
if self.itembody:
213213
body += self.itembody
214214
elif result._result.get('failed_when_result') is True:
215-
fail_cond = self.indent('failed_when:\n- ' + '\n- '.join(result._task.failed_when))
215+
fail_cond_list = '\n- '.join(result._task.failed_when)
216+
fail_cond = self.indent(f"failed_when:\n- {fail_cond_list}")
216217
body += f"due to the following condition:\n\n{fail_cond}\n\n"
217218
elif result._result.get('msg'):
218219
body += self.body_blob(result._result['msg'], 'message')

plugins/connection/wsl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,10 @@ def _connect(self) -> Connection:
522522
if u'PID check failed' in msg:
523523
raise AnsibleError('paramiko version issue, please upgrade paramiko on the machine running ansible')
524524
elif u'Private key file is encrypted' in msg:
525-
msg = f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : ' + \
525+
msg = (
526+
f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : '
526527
f'{msg}\nTo connect as a different user, use -u <username>.'
528+
)
527529
raise AnsibleConnectionFailure(msg)
528530
else:
529531
raise AnsibleConnectionFailure(msg)
@@ -656,7 +658,7 @@ def exec_command(self, cmd: str, in_data: bytes | None = None, sudoable: bool =
656658
chan.shutdown_write()
657659

658660
except socket.timeout:
659-
raise AnsibleError('ssh timed out waiting for privilege escalation.\n' + to_text(become_output))
661+
raise AnsibleError(f'ssh timed out waiting for privilege escalation.\n{to_text(become_output)}')
660662

661663
stdout = b''.join(chan.makefile('rb', bufsize))
662664
stderr = b''.join(chan.makefile_stderr('rb', bufsize))

plugins/filter/jc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ def jc_filter(data, parser, quiet=True, raw=False):
143143

144144
# old API (jc v1.17.7 and lower)
145145
else:
146-
jc_parser = importlib.import_module('jc.parsers.' + parser)
146+
jc_parser = importlib.import_module(f'jc.parsers.{parser}')
147147
return jc_parser.parse(data, quiet=quiet, raw=raw)
148148

149149
except Exception as e:
150-
raise AnsibleFilterError('Error in jc filter plugin: %s' % e)
150+
raise AnsibleFilterError(f'Error in jc filter plugin: {e}')
151151

152152

153153
class FilterModule(object):

plugins/inventory/iocage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def get_inventory(self, path):
350350
for hostname, host_vars in results['_meta']['hostvars'].items():
351351
iocage_hooks = []
352352
for hook in hooks_results:
353-
path = "/" + iocage_pool + "/iocage/jails/" + hostname + "/root" + hook
353+
path = f"/{iocage_pool}/iocage/jails/{hostname}/root{hook}"
354354
cmd_cat_hook = cmd.copy()
355355
cmd_cat_hook.append('cat')
356356
cmd_cat_hook.append(path)

plugins/inventory/xen_orchestra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _add_vms(self, vms, hosts, pools):
224224
vm_name_list.append(vm['name_label'])
225225
else:
226226
vm_duplicate_count = vm_name_list.count(vm['name_label'])
227-
entry_name = vm['name_label'] + "_" + str(vm_duplicate_count)
227+
entry_name = f"{vm['name_label']}_{vm_duplicate_count}"
228228
vm_name_list.append(vm['name_label'])
229229
else:
230230
entry_name = uuid
@@ -284,7 +284,7 @@ def _add_hosts(self, hosts, pools):
284284
host_name_list.append(host['name_label'])
285285
else:
286286
host_duplicate_count = host_name_list.count(host['name_label'])
287-
entry_name = host['name_label'] + "_" + str(host_duplicate_count)
287+
entry_name = f"{host['name_label']}_{host_duplicate_count}"
288288
host_name_list.append(host['name_label'])
289289
else:
290290
entry_name = host['uuid']

0 commit comments

Comments
 (0)