|
|
@ -77,12 +77,16 @@ def fix_case(name):
|
|
|
|
|
|
|
|
|
|
|
|
def replace_line(existing_line, new_line):
|
|
|
|
def replace_line(existing_line, new_line):
|
|
|
|
"""Replaces lines in /etc/locale.gen"""
|
|
|
|
"""Replaces lines in /etc/locale.gen"""
|
|
|
|
f = open("/etc/locale.gen", "r")
|
|
|
|
try:
|
|
|
|
lines = [line.replace(existing_line, new_line) for line in f]
|
|
|
|
f = open("/etc/locale.gen", "r")
|
|
|
|
f.close()
|
|
|
|
lines = [line.replace(existing_line, new_line) for line in f]
|
|
|
|
f = open("/etc/locale.gen", "w")
|
|
|
|
finally:
|
|
|
|
f.write("".join(lines))
|
|
|
|
f.close()
|
|
|
|
f.close()
|
|
|
|
try:
|
|
|
|
|
|
|
|
f = open("/etc/locale.gen", "w")
|
|
|
|
|
|
|
|
f.write("".join(lines))
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
def set_locale(name, enabled=True):
|
|
|
|
def set_locale(name, enabled=True):
|
|
|
|
""" Sets the state of the locale. Defaults to enabled. """
|
|
|
|
""" Sets the state of the locale. Defaults to enabled. """
|
|
|
@ -91,12 +95,16 @@ def set_locale(name, enabled=True):
|
|
|
|
new_string = '%s \g<charset>' % (name)
|
|
|
|
new_string = '%s \g<charset>' % (name)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
new_string = '# %s \g<charset>' % (name)
|
|
|
|
new_string = '# %s \g<charset>' % (name)
|
|
|
|
f = open("/etc/locale.gen", "r")
|
|
|
|
try:
|
|
|
|
lines = [re.sub(search_string, new_string, line) for line in f]
|
|
|
|
f = open("/etc/locale.gen", "r")
|
|
|
|
f.close()
|
|
|
|
lines = [re.sub(search_string, new_string, line) for line in f]
|
|
|
|
f = open("/etc/locale.gen", "w")
|
|
|
|
finally:
|
|
|
|
f.write("".join(lines))
|
|
|
|
f.close()
|
|
|
|
f.close()
|
|
|
|
try:
|
|
|
|
|
|
|
|
f = open("/etc/locale.gen", "w")
|
|
|
|
|
|
|
|
f.write("".join(lines))
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
def apply_change(targetState, name):
|
|
|
|
def apply_change(targetState, name):
|
|
|
|
"""Create or remove locale.
|
|
|
|
"""Create or remove locale.
|
|
|
@ -129,15 +137,19 @@ def apply_change_ubuntu(targetState, name):
|
|
|
|
localeGenExitValue = call(["locale-gen", name])
|
|
|
|
localeGenExitValue = call(["locale-gen", name])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Delete locale involves discarding the locale from /var/lib/locales/supported.d/local and regenerating all locales.
|
|
|
|
# Delete locale involves discarding the locale from /var/lib/locales/supported.d/local and regenerating all locales.
|
|
|
|
f = open("/var/lib/locales/supported.d/local", "r")
|
|
|
|
try:
|
|
|
|
content = f.readlines()
|
|
|
|
f = open("/var/lib/locales/supported.d/local", "r")
|
|
|
|
f.close()
|
|
|
|
content = f.readlines()
|
|
|
|
f = open("/var/lib/locales/supported.d/local", "w")
|
|
|
|
finally:
|
|
|
|
for line in content:
|
|
|
|
f.close()
|
|
|
|
locale, charset = line.split(' ')
|
|
|
|
try:
|
|
|
|
if locale != name:
|
|
|
|
f = open("/var/lib/locales/supported.d/local", "w")
|
|
|
|
f.write(line)
|
|
|
|
for line in content:
|
|
|
|
f.close()
|
|
|
|
locale, charset = line.split(' ')
|
|
|
|
|
|
|
|
if locale != name:
|
|
|
|
|
|
|
|
f.write(line)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
# Purge locales and regenerate.
|
|
|
|
# Purge locales and regenerate.
|
|
|
|
# Please provide a patch if you know how to avoid regenerating the locales to keep!
|
|
|
|
# Please provide a patch if you know how to avoid regenerating the locales to keep!
|
|
|
|
localeGenExitValue = call(["locale-gen", "--purge"])
|
|
|
|
localeGenExitValue = call(["locale-gen", "--purge"])
|
|
|
|