Blame stages/org.osbuild.locale
|
Packit Service |
863627 |
#!/usr/bin/python3
|
|
Packit Service |
863627 |
"""
|
|
Packit Service |
863627 |
Set system language.
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
Sets the system language to the given `language`, which must be a valid locale
|
|
Packit Service |
863627 |
identifier, like "en_US.UTF-8".
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
Removes `/etc/locale.conf` and then uses `systemd-firstboot` from the buildhost,
|
|
Packit Service |
863627 |
with the `--locale` flag, which will write a new `/etc/locale.conf` in the
|
|
Packit Service |
863627 |
target system with `LANG={language}`.
|
|
Packit Service |
863627 |
"""
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
import json
|
|
Packit Service |
863627 |
import subprocess
|
|
Packit Service |
863627 |
import sys
|
|
Packit Service |
863627 |
import os
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
SCHEMA = """
|
|
Packit Service |
863627 |
"additionalProperties": false,
|
|
Packit Service |
863627 |
"required": ["language"],
|
|
Packit Service |
863627 |
"properties": {
|
|
Packit Service |
863627 |
"language": {
|
|
Packit Service |
863627 |
"type": "string",
|
|
Packit Service |
863627 |
"description": "Locale identifier (like 'en_US.UTF-8') for system LANG"
|
|
Packit Service |
863627 |
}
|
|
Packit Service |
863627 |
}
|
|
Packit Service |
863627 |
"""
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
def main(tree, options):
|
|
Packit Service |
863627 |
language = options["language"]
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
# We need to remove the /etc/locale.conf file first, because it is created while we install RPM packages.
|
|
Packit Service |
863627 |
# systemd-firstboot expects that if /etc/locale.conf exists it is a user-defined value and does not change it, but
|
|
Packit Service |
863627 |
# the assumption is wrong, because it contains a default value from RPM package.
|
|
Packit Service |
863627 |
try:
|
|
Packit Service |
863627 |
os.remove(f"{tree}/etc/locale.conf")
|
|
Packit Service |
863627 |
print("/etc/locale.conf already exists. Replacing.")
|
|
Packit Service |
863627 |
except FileNotFoundError:
|
|
Packit Service |
863627 |
pass
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
subprocess.run(["systemd-firstboot", f"--root={tree}", f"--locale={language}"], check=True)
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
|
|
Packit Service |
863627 |
if __name__ == '__main__':
|
|
Packit Service |
863627 |
args = json.load(sys.stdin)
|
|
Packit Service |
863627 |
r = main(args["tree"], args["options"])
|
|
Packit Service |
863627 |
sys.exit(r)
|