[PR #9321/c3ed2144 backport][stable-10] callback plugins: use f-strings (#9357)

callback plugins: use f-strings (#9321)

* callback plugins: use f-strings

* add changelog frag

* manual change for few occurrences

* manual change for few occurrences

* adjustment from review

* adjustment from review

* adjustment from review

* Update plugins/callback/splunk.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* replace str templating with JSON templating

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c3ed2144e2)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2024-12-24 14:45:32 +01:00 committed by GitHub
parent a13a6d284c
commit 3c7f05c42d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 251 additions and 253 deletions

View file

@ -138,14 +138,13 @@ class CallbackModule(CallbackBase):
headers=headers)
return response.read()
except Exception as e:
self._display.warning(u'Could not submit message to Slack: %s' %
to_text(e))
self._display.warning(f'Could not submit message to Slack: {to_text(e)}')
def v2_playbook_on_start(self, playbook):
self.playbook_name = os.path.basename(playbook._file_name)
title = [
'*Playbook initiated* (_%s_)' % self.guid
f'*Playbook initiated* (_{self.guid}_)'
]
invocation_items = []
@ -156,23 +155,23 @@ class CallbackModule(CallbackBase):
subset = context.CLIARGS['subset']
inventory = [os.path.abspath(i) for i in context.CLIARGS['inventory']]
invocation_items.append('Inventory: %s' % ', '.join(inventory))
invocation_items.append(f"Inventory: {', '.join(inventory)}")
if tags and tags != ['all']:
invocation_items.append('Tags: %s' % ', '.join(tags))
invocation_items.append(f"Tags: {', '.join(tags)}")
if skip_tags:
invocation_items.append('Skip Tags: %s' % ', '.join(skip_tags))
invocation_items.append(f"Skip Tags: {', '.join(skip_tags)}")
if subset:
invocation_items.append('Limit: %s' % subset)
invocation_items.append(f'Limit: {subset}')
if extra_vars:
invocation_items.append('Extra Vars: %s' %
' '.join(extra_vars))
invocation_items.append(f"Extra Vars: {' '.join(extra_vars)}")
title.append('by *%s*' % context.CLIARGS['remote_user'])
title.append(f"by *{context.CLIARGS['remote_user']}*")
title.append('\n\n*%s*' % self.playbook_name)
title.append(f'\n\n*{self.playbook_name}*')
msg_items = [' '.join(title)]
if invocation_items:
msg_items.append('```\n%s\n```' % '\n'.join(invocation_items))
_inv_item = '\n'.join(invocation_items)
msg_items.append(f'```\n{_inv_item}\n```')
msg = '\n'.join(msg_items)
@ -192,8 +191,8 @@ class CallbackModule(CallbackBase):
def v2_playbook_on_play_start(self, play):
"""Display Play start messages"""
name = play.name or 'Play name not specified (%s)' % play._uuid
msg = '*Starting play* (_%s_)\n\n*%s*' % (self.guid, name)
name = play.name or f'Play name not specified ({play._uuid})'
msg = f'*Starting play* (_{self.guid}_)\n\n*{name}*'
attachments = [
{
'fallback': msg,
@ -228,7 +227,7 @@ class CallbackModule(CallbackBase):
attachments = []
msg_items = [
'*Playbook Complete* (_%s_)' % self.guid
f'*Playbook Complete* (_{self.guid}_)'
]
if failures or unreachable:
color = 'danger'
@ -237,7 +236,7 @@ class CallbackModule(CallbackBase):
color = 'good'
msg_items.append('\n*Success!*')
msg_items.append('```\n%s\n```' % t)
msg_items.append(f'```\n{t}\n```')
msg = '\n'.join(msg_items)