1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-30 15:38:53 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -105,7 +105,7 @@ class LocaleGen(StateModuleHelper):
module = dict(
argument_spec=dict(
name=dict(type="list", elements="str", required=True),
state=dict(type='str', default='present', choices=['absent', 'present']),
state=dict(type="str", default="present", choices=["absent", "present"]),
),
supports_check_mode=True,
)
@ -132,7 +132,8 @@ class LocaleGen(StateModuleHelper):
"On this machine mechanism=ubuntu_legacy is used. This mechanism is deprecated and will be removed from"
" in community.general 13.0.0. If you see this message on a modern Debian or Ubuntu version,"
" please create an issue in the community.general repository",
version="13.0.0", collection_name="community.general"
version="13.0.0",
collection_name="community.general",
)
else:
self.do_raise(f'{VAR_LIB_LOCALES} and {ETC_LOCALE_GEN} are missing. Is the package "locales" installed?')
@ -155,11 +156,11 @@ class LocaleGen(StateModuleHelper):
checking either :
* if the locale is present in /etc/locales.gen
* or if the locale is present in /usr/share/i18n/SUPPORTED"""
regexp = r'^\s*#?\s*(?P<locale>\S+[\._\S]+) (?P<charset>\S+)\s*$'
regexp = r"^\s*#?\s*(?P<locale>\S+[\._\S]+) (?P<charset>\S+)\s*$"
locales_available = self.MECHANISMS[self.vars.mechanism]["available"]
re_compiled = re.compile(regexp)
with open(locales_available, 'r') as fd:
with open(locales_available, "r") as fd:
lines = fd.readlines()
res = [re_compiled.match(line) for line in lines]
self.vars.set("available_lines", lines, verbosity=4)
@ -174,7 +175,9 @@ class LocaleGen(StateModuleHelper):
locales_not_found = self.locale_get_not_present(locales_not_found)
if locales_not_found:
self.do_raise(f"The following locales you have entered are not available on your system: {', '.join(locales_not_found)}")
self.do_raise(
f"The following locales you have entered are not available on your system: {', '.join(locales_not_found)}"
)
def is_present(self):
return not self.locale_get_not_present(self.vars.name)
@ -201,18 +204,18 @@ class LocaleGen(StateModuleHelper):
return name
def set_locale_glibc(self, names, enabled=True):
""" Sets the state of the locale. Defaults to enabled. """
with open(ETC_LOCALE_GEN, 'r') as fr:
"""Sets the state of the locale. Defaults to enabled."""
with open(ETC_LOCALE_GEN, "r") as fr:
lines = fr.readlines()
locale_regexes = []
for name in names:
search_string = rf'^#?\s*{re.escape(name)} (?P<charset>.+)'
search_string = rf"^#?\s*{re.escape(name)} (?P<charset>.+)"
if enabled:
new_string = rf'{name} \g<charset>'
new_string = rf"{name} \g<charset>"
else:
new_string = rf'# {name} \g<charset>'
new_string = rf"# {name} \g<charset>"
re_search = re.compile(search_string)
locale_regexes.append([re_search, new_string])
@ -221,7 +224,7 @@ class LocaleGen(StateModuleHelper):
lines[i] = search.sub(replace, lines[i])
# Write the modified content back to the file
with open(ETC_LOCALE_GEN, 'w') as fw:
with open(ETC_LOCALE_GEN, "w") as fw:
fw.writelines(lines)
def apply_change_glibc(self, targetState, names):
@ -258,7 +261,7 @@ class LocaleGen(StateModuleHelper):
content = fr.readlines()
with open(VAR_LIB_LOCALES_LOCAL, "w") as fw:
for line in content:
locale, charset = line.split(' ')
locale, charset = line.split(" ")
if locale not in names:
fw.write(line)
# Purge locales and regenerate.
@ -277,5 +280,5 @@ def main():
LocaleGen.execute()
if __name__ == '__main__':
if __name__ == "__main__":
main()