1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

modules [jk]*: use f-strings (#10970)

* modules [jk]*: use f-strings

* add changelog frag

* Apply suggestions from code review

* typing insanity
This commit is contained in:
Alexei Znamensky 2025-10-26 19:54:15 +13:00 committed by GitHub
parent 8120e9347e
commit 4a6a449fbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 363 additions and 408 deletions

View file

@ -65,7 +65,7 @@ class Blacklist(StateModuleHelper):
)
def __init_module__(self):
self.pattern = re.compile(r'^blacklist\s+{0}$'.format(re.escape(self.vars.name)))
self.pattern = re.compile(rf'^blacklist\s+{re.escape(self.vars.name)}$')
self.vars.filename = self.vars.blacklist_file
self.vars.set('file_exists', os.path.exists(self.vars.filename), output=False, change=True)
if not self.vars.file_exists:
@ -97,13 +97,13 @@ class Blacklist(StateModuleHelper):
if self.vars.is_blacklisted:
return
self.vars.is_blacklisted = True
self.vars.lines = self.vars.lines + ['blacklist %s' % self.vars.name]
self.vars.lines = self.vars.lines + [f'blacklist {self.vars.name}']
def __quit_module__(self):
if self.has_changed() and not self.module.check_mode:
bkp = self.module.backup_local(self.vars.filename)
with open(self.vars.filename, "w") as fd:
fd.writelines(["{0}\n".format(x) for x in self.vars.lines])
fd.writelines([f"{x}\n" for x in self.vars.lines])
self.module.add_cleanup_file(bkp)