You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
209 lines
8.7 KiB
209 lines
8.7 KiB
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 2008-2012 Calculate Ltd. http://www.calculate-linux.org
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import os
|
|
import sys
|
|
from os import path
|
|
from calculate.lib.cl_datavars import Variables, VariableError
|
|
from calculate.lib.variables import Locale
|
|
from calculate.lib.utils.files import readLinesFile, process
|
|
from calculate.lib.utils.common import getValueFromCmdLine, getValueFromConfig
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
setLocalTranslate('cl_install',sys.modules[__name__])
|
|
|
|
class InstallLocale(Locale):
|
|
vars = ["os_install_linguas", "os_install_locale_consolefont",
|
|
"os_install_locale_keymap", "os_install_locale_dumpkeys",
|
|
"os_install_locale_locale", "os_install_locale_lang",
|
|
"os_install_locale_language", "os_install_locale_xkb",
|
|
"os_install_locale_xkbname", "os_install_clock_timezone",
|
|
"os_install_clock_type"]
|
|
|
|
# LINGUAS value
|
|
os_install_linguas = {'mode':'w'}
|
|
|
|
# consolefont
|
|
os_install_locale_consolefont = {}
|
|
|
|
# keymap of locale (used for /etc/conf.d/keymaps)
|
|
os_install_locale_keymap = {}
|
|
|
|
# dumpkeys_charset for keymap
|
|
os_install_locale_dumpkeys = {}
|
|
|
|
# locale (at example: ru_RU.UTF-8)
|
|
os_install_locale_locale = {}
|
|
|
|
# full language (at example: ru_RU)
|
|
os_install_locale_lang = {'mode':'w',
|
|
'type':'choice',
|
|
'label':_("Language"),
|
|
'opt':["--lang","-l"]}
|
|
|
|
# short language (at example ru)
|
|
os_install_locale_language = {}
|
|
|
|
# keyboard layout for X server
|
|
os_install_locale_xkb = {}
|
|
|
|
# keyboard layout name for X server
|
|
os_install_locale_xkbname = {}
|
|
|
|
# timezone for clock
|
|
os_install_clock_timezone = {'mode':'w',
|
|
'type':'choiceedit',
|
|
'label':_("Timezone"),
|
|
'metavalue':"TIMEZONE",
|
|
'opt':["--timezone"]}
|
|
|
|
# type of clock (UTC or local)
|
|
os_install_clock_type = {'mode':'w'}
|
|
|
|
def get_os_install_linguas(self):
|
|
"""Current linguas"""
|
|
def get_linguas(lines):
|
|
linguas = map(lambda x:x.strip().rpartition('=')[-1].strip('"\''),
|
|
filter(lambda x: x.startswith("LINGUAS="),
|
|
lines))
|
|
return linguas[-1] if linguas else ""
|
|
makeconf = '/etc/make.conf'
|
|
infocommand = ['emerge','--info']
|
|
defaultLinguas = "bg en de es fr it pl pt_BR ru uk"
|
|
# get linguas from make.conf, emerge --info or default
|
|
curlanguage = self.Get('os_install_locale_language')
|
|
return get_linguas(readLinesFile(makeconf)) or \
|
|
" ".join(filter(lambda x:x=="en" or x==curlanguage,
|
|
get_linguas(
|
|
process(*infocommand).readlines() or "").split())) or \
|
|
defaultLinguas
|
|
|
|
def get_os_install_clock_timezone(self):
|
|
"""Timezone for clock"""
|
|
return self.Get('os_clock_timezone')
|
|
|
|
def check_os_install_clock_timezone(self,value):
|
|
"""Check timezone"""
|
|
if not value or not path.isfile(path.join(
|
|
"/usr/share/zoneinfo",value)):
|
|
raise VariableError(_("%s timezone is wrong")%value)
|
|
|
|
def get_os_install_clock_type(self):
|
|
"""type of clock (UTC or local)"""
|
|
clockTypeFile = ['/etc/conf.d/clock','/etc/conf.d/hwclock']
|
|
for f in clockTypeFile:
|
|
clock = getValueFromConfig(f,"clock")
|
|
if clock:
|
|
if clock.upper() == 'UTC':
|
|
return clock.upper()
|
|
elif clock.lower() == 'local':
|
|
return clock.lower()
|
|
return "local"
|
|
|
|
def choice_os_install_clock_type(self):
|
|
return ["local","UTC"]
|
|
|
|
def get_os_install_locale_consolefont(self):
|
|
"""consolefont"""
|
|
return self.getFieldByKeymap("consolefont",
|
|
self.Get('os_install_locale_keymap'))
|
|
|
|
def get_os_install_locale_keymap(self):
|
|
"""keymap of locale (used for /etc/conf.d/keymaps)"""
|
|
# get keymap from boot calculate param (keymap specified
|
|
# by lang)
|
|
keymapConfd = '/etc/conf.d/keymaps'
|
|
keymap = getValueFromCmdLine("calculate",1)
|
|
if self.isLangExists(keymap):
|
|
return self.getFieldByLang('keymap',keymap)
|
|
# get keymap by os_install_locale_lang
|
|
keymap = getValueFromConfig(keymapConfd,'KEYMAP')
|
|
if keymap:
|
|
return keymap
|
|
return self.getFieldByLang("keymap",
|
|
self.Get("os_install_locale_lang"))
|
|
|
|
def get_os_install_locale_dumpkeys(self):
|
|
"""dumpkeys charset for keymap"""
|
|
# is specified keymap support by locale hash
|
|
if self.Get('os_install_locale_keymap') in self.getFields('keymap'):
|
|
return self.getFieldByKeymap("dumpkeys_charset",
|
|
self.Get('os_install_locale_keymap'))
|
|
else:
|
|
return self.getFieldByLang("dumpkeys_charset",
|
|
self.Get('os_install_locale_lang'))
|
|
|
|
def get_os_install_locale_locale(self):
|
|
"""locale (example: ru_RU.UTF-8)"""
|
|
return self.Get('os_locale_locale')
|
|
|
|
def get_os_install_locale_lang(self):
|
|
"""lang (example: ru_RU)"""
|
|
return self.getLangByField("locale",
|
|
self.Get('os_install_locale_locale'))
|
|
|
|
def get_os_install_locale_language(self):
|
|
"""language (example: ru)"""
|
|
return self.getFieldByLang("language",
|
|
self.Get('os_install_locale_lang'))
|
|
|
|
def get_os_install_locale_xkb(self):
|
|
"""xkb layouts (example: en,ru)"""
|
|
return self.getFieldByLang("xkblayout",
|
|
self.Get('os_install_locale_lang'))
|
|
|
|
def get_os_install_locale_xkbname(self):
|
|
"""названия используемых раскладок клавиатуры для X"""
|
|
localeXkb = self.Get("os_install_locale_xkb")
|
|
if localeXkb:
|
|
return localeXkb.split("(")[0]
|
|
return ""
|
|
|
|
def choice_os_install_locale_lang(self):
|
|
"""Choice of language"""
|
|
return self.Get('os_lang')
|
|
|
|
def choice_os_install_clock_timezone(self):
|
|
return ["Etc/GMT-12", "Pacific/Midway", "Pacific/Honolulu",
|
|
"America/Anchorage", "Canada/Pacific", "America/Tijuana",
|
|
"America/Phoenix", "America/Denver", "America/Mazatlan",
|
|
"America/Mazatlan", "America/Monterrey", "America/Monterrey",
|
|
"America/Regina", "America/Mexico_City", "Canada/Central",
|
|
"America/Bogota", "America/New_York",
|
|
"America/Indiana/Indianapolis", "America/Halifax",
|
|
"America/Caracas", "America/Manaus", "America/Santiago",
|
|
"America/St_Johns", "America/Sao_Paulo",
|
|
"America/Argentina/Buenos_Aires", "Etc/GMT+3",
|
|
"America/Montevideo", "Atlantic/South_Georgia",
|
|
"Atlantic/Azores", "Atlantic/Cape_Verde", "UTC",
|
|
"Africa/Casablanca", "Europe/Amsterdam", "Europe/Belgrade",
|
|
"Europe/Brussels", "Europe/Zagreb", "Africa/Tunis",
|
|
"Asia/Amman", "Europe/Istanbul", "Asia/Beirut", "Europe/Kiev",
|
|
"Africa/Windhoek", "Asia/Jerusalem", "Africa/Cairo",
|
|
"Europe/Minsk", "Africa/Harare", "Asia/Baghdad", "Asia/Kuwait",
|
|
"Europe/Moscow", "Africa/Nairobi", "Asia/Tbilisi",
|
|
"Asia/Tehran", "Asia/Muscat", "Asia/Baku", "Asia/Yerevan",
|
|
"Asia/Kabul", "Asia/Yekaterinburg", "Asia/Karachi",
|
|
"Asia/Calcutta", "Asia/Jayapura", "Asia/Katmandu",
|
|
"Asia/Almaty", "Asia/Dhaka", "Asia/Omsk", "Asia/Rangoon",
|
|
"Asia/Bangkok", "Asia/Krasnoyarsk", "Asia/Hong_Kong",
|
|
"Asia/Irkutsk", "Asia/Singapore", "Australia/Perth",
|
|
"Asia/Taipei", "Asia/Tokyo", "Asia/Seoul", "Asia/Yakutsk",
|
|
"Australia/Adelaide", "Australia/Darwin", "Australia/Brisbane",
|
|
"Asia/Vladivostok", "Pacific/Guam", "Australia/Melbourne",
|
|
"Australia/Hobart", "Asia/Magadan", "Asia/Kamchatka",
|
|
"Pacific/Auckland", "Etc/GMT-13"]
|