2014-11-13 05:10:20 +01:00
|
|
|
#!/usr/bin/env python3
|
2015-02-18 15:06:10 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-12-20 14:39:09 +01:00
|
|
|
# === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-11-13 05:10:20 +01:00
|
|
|
#
|
|
|
|
# Copyright 2014, Anke Boersma <demm@kaosx.us>
|
2015-02-17 14:38:30 +01:00
|
|
|
# Copyright 2015, Philip Müller <philm@manjaro.org>
|
2016-07-26 17:39:32 +02:00
|
|
|
# Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
2018-06-15 11:59:11 +02:00
|
|
|
# Copyright 2018, AlmAck <gluca86@gmail.com>
|
2018-06-19 14:42:25 +02:00
|
|
|
# Copyright 2018, Adriaan de Groot <groot@kde.org>
|
2014-11-13 05:10:20 +01:00
|
|
|
#
|
|
|
|
# Calamares is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Calamares is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
import libcalamares
|
|
|
|
|
|
|
|
|
|
|
|
def run():
|
|
|
|
""" Create locale """
|
2016-08-10 12:11:48 +02:00
|
|
|
en_us_locale = 'en_US.UTF-8'
|
|
|
|
locale_conf = libcalamares.globalstorage.value("localeConf")
|
|
|
|
|
|
|
|
if not locale_conf:
|
|
|
|
locale_conf = {
|
|
|
|
'LANG': 'en_US.UTF-8',
|
|
|
|
'LC_NUMERIC': 'en_US.UTF-8',
|
|
|
|
'LC_TIME': 'en_US.UTF-8',
|
|
|
|
'LC_MONETARY': 'en_US.UTF-8',
|
|
|
|
'LC_PAPER': 'en_US.UTF-8',
|
|
|
|
'LC_NAME': 'en_US.UTF-8',
|
|
|
|
'LC_ADDRESS': 'en_US.UTF-8',
|
|
|
|
'LC_TELEPHONE': 'en_US.UTF-8',
|
|
|
|
'LC_MEASUREMENT': 'en_US.UTF-8',
|
|
|
|
'LC_IDENTIFICATION': 'en_US.UTF-8'
|
|
|
|
}
|
2014-11-13 05:10:20 +01:00
|
|
|
|
|
|
|
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
2018-06-19 14:46:50 +02:00
|
|
|
target_locale_gen = "{!s}/etc/locale.gen".format(install_path)
|
|
|
|
target_locale_gen_bak = target_locale_gen + ".bak"
|
|
|
|
target_locale_conf_path = "{!s}/etc/locale.conf".format(install_path)
|
|
|
|
target_etc_default_path = "{!s}/etc/default".format(install_path)
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2014-11-28 20:05:54 +01:00
|
|
|
# restore backup if available
|
2018-06-19 14:56:37 +02:00
|
|
|
if os.path.exists(target_locale_gen_bak):
|
|
|
|
shutil.copy2(target_locale_gen_bak, target_locale_gen)
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2018-06-19 14:56:37 +02:00
|
|
|
# run locale-gen if detected; this *will* cause an exception
|
|
|
|
# if the live system has locale.gen, but the target does not:
|
|
|
|
# in that case, fix your installation filesystem.
|
2014-11-28 20:05:54 +01:00
|
|
|
if os.path.exists('/etc/locale.gen'):
|
2014-11-13 05:10:20 +01:00
|
|
|
text = []
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2018-06-19 14:46:50 +02:00
|
|
|
with open(target_locale_gen, "r") as gen:
|
2014-11-13 05:10:20 +01:00
|
|
|
text = gen.readlines()
|
|
|
|
|
2016-08-10 12:11:48 +02:00
|
|
|
# we want unique values, so locale_values should have 1 or 2 items
|
|
|
|
locale_values = set(locale_conf.values())
|
2018-06-20 13:13:36 +02:00
|
|
|
locale_values.add(en_us_locale) # Always enable en_US as well
|
2016-08-10 12:11:48 +02:00
|
|
|
|
2018-06-19 14:46:50 +02:00
|
|
|
with open(target_locale_gen, "w") as gen:
|
2014-11-13 05:10:20 +01:00
|
|
|
for line in text:
|
2016-08-10 12:11:48 +02:00
|
|
|
for locale_value in locale_values:
|
2018-03-03 14:30:08 +01:00
|
|
|
if line.startswith("#" + locale_value):
|
2016-08-10 12:11:48 +02:00
|
|
|
# uncomment line
|
|
|
|
line = line[1:].lstrip()
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2014-11-13 05:10:20 +01:00
|
|
|
gen.write(line)
|
|
|
|
|
2015-08-06 12:13:21 +02:00
|
|
|
libcalamares.utils.target_env_call(['locale-gen'])
|
2014-11-13 05:10:20 +01:00
|
|
|
print('locale.gen done')
|
|
|
|
|
2016-05-30 16:14:26 +02:00
|
|
|
# write /etc/locale.conf
|
2018-06-19 14:46:50 +02:00
|
|
|
with open(target_locale_conf_path, "w") as lcf:
|
2016-08-10 12:11:48 +02:00
|
|
|
for k, v in locale_conf.items():
|
|
|
|
lcf.write("{!s}={!s}\n".format(k, v))
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2016-05-30 16:14:26 +02:00
|
|
|
# write /etc/default/locale if /etc/default exists and is a dir
|
2018-06-19 14:46:50 +02:00
|
|
|
if os.path.isdir(target_etc_default_path):
|
|
|
|
with open(os.path.join(target_etc_default_path, "locale"), "w") as edl:
|
2016-08-10 12:11:48 +02:00
|
|
|
for k, v in locale_conf.items():
|
|
|
|
edl.write("{!s}={!s}\n".format(k, v))
|
2016-05-30 16:14:26 +02:00
|
|
|
|
2014-11-13 05:10:20 +01:00
|
|
|
return None
|