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.
273 lines
9.8 KiB
273 lines
9.8 KiB
13 years ago
|
#-*- coding: utf-8 -*-
|
||
|
|
||
11 years ago
|
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
|
||
13 years ago
|
#
|
||
|
# 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
|
||
13 years ago
|
from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable
|
||
|
from calculate.lib.variables.locale import Locale
|
||
13 years ago
|
from calculate.lib.utils.files import readLinesFile, process
|
||
|
from calculate.lib.utils.common import getValueFromCmdLine, getValueFromConfig
|
||
13 years ago
|
from pytz import timezone,country_timezones,UnknownTimeZoneError
|
||
|
from datetime import datetime
|
||
13 years ago
|
from operator import itemgetter
|
||
13 years ago
|
|
||
|
from calculate.lib.cl_lang import setLocalTranslate
|
||
13 years ago
|
setLocalTranslate('cl_install3',sys.modules[__name__])
|
||
13 years ago
|
|
||
13 years ago
|
class LocaleVariable(ReadonlyVariable,Locale):
|
||
|
"""
|
||
|
Locale variables not using for flash installation
|
||
|
"""
|
||
|
def uncompatible(self):
|
||
|
"""
|
||
|
Network setting up unavailable for flash installation
|
||
|
"""
|
||
|
if self.Get('os_install_root_type') == 'flash':
|
||
|
return \
|
||
12 years ago
|
_("Locale configuration unavailable for Flash install")
|
||
13 years ago
|
return ""
|
||
13 years ago
|
|
||
13 years ago
|
class VariableOsInstallLinguas(LocaleVariable):
|
||
|
"""
|
||
|
Current LINGUAS value
|
||
|
"""
|
||
|
mode = "w"
|
||
13 years ago
|
|
||
13 years ago
|
def get(self):
|
||
13 years ago
|
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
|
||
|
|
||
13 years ago
|
class VariableOsInstallLocaleConsolefont(LocaleVariable):
|
||
|
"""
|
||
|
Consolefont for locale
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
return self.getFieldByKeymap("consolefont",
|
||
|
self.Get('os_install_locale_keymap'))
|
||
|
|
||
13 years ago
|
class VariableOsInstallLocaleKeymap(LocaleVariable):
|
||
|
"""
|
||
|
Keymap of locale (used for /etc/conf.d/keymaps)
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
# 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
|
||
12 years ago
|
# Temporary comment get keymap from config file
|
||
|
#keymap = getValueFromConfig(keymapConfd,'KEYMAP')
|
||
|
#if keymap:
|
||
|
# return keymap
|
||
13 years ago
|
return self.getFieldByLang("keymap",
|
||
|
self.Get("os_install_locale_lang"))
|
||
|
|
||
13 years ago
|
class VariableOsInstallLocaleDumpkeys(LocaleVariable):
|
||
|
"""
|
||
|
Dumpkeys_charset for keymap
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
# 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'))
|
||
|
|
||
13 years ago
|
class VariableOsInstallLocaleLocale(LocaleVariable):
|
||
|
"""
|
||
|
Locale (at example: ru_RU.UTF-8)
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
"""locale (example: ru_RU.UTF-8)"""
|
||
13 years ago
|
return self.getFieldByLang("locale",
|
||
|
self.Get('os_install_locale_lang'))
|
||
13 years ago
|
|
||
13 years ago
|
class VariableOsInstallLocaleLang(LocaleVariable):
|
||
|
"""
|
||
|
Full language (at example: ru_RU)
|
||
|
"""
|
||
|
mode = 'w'
|
||
13 years ago
|
metavalue = "LANG"
|
||
13 years ago
|
type = 'choice'
|
||
|
opt = ["--lang","-l"]
|
||
|
|
||
13 years ago
|
def init(self):
|
||
|
self.label = _("Language")
|
||
13 years ago
|
self.help = _("set the language")
|
||
13 years ago
|
|
||
13 years ago
|
def get(self):
|
||
13 years ago
|
"""lang (example: ru_RU)"""
|
||
13 years ago
|
return self.Get('os_locale_lang')
|
||
13 years ago
|
|
||
13 years ago
|
def choice(self):
|
||
13 years ago
|
return sorted(zip(self.Get('os_lang'),
|
||
|
map(str,self.Get('os_lang',humanreadable=True))),key=itemgetter(1))
|
||
13 years ago
|
|
||
|
class VariableOsInstallLocaleLanguage(LocaleVariable):
|
||
|
"""
|
||
|
Short language (at example ru)
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
return self.getFieldByLang("language",
|
||
|
self.Get('os_install_locale_lang'))
|
||
|
|
||
13 years ago
|
class VariableOsInstallLocaleXkb(LocaleVariable):
|
||
|
"""
|
||
|
Keyboard layout for X server
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
return self.getFieldByLang("xkblayout",
|
||
|
self.Get('os_install_locale_lang'))
|
||
|
|
||
13 years ago
|
class VariableOsInstallLocaleXkbname(LocaleVariable):
|
||
|
"""
|
||
|
Keyboard layout name for X server
|
||
|
"""
|
||
|
def get(self):
|
||
13 years ago
|
localeXkb = self.Get("os_install_locale_xkb")
|
||
|
if localeXkb:
|
||
|
return localeXkb.split("(")[0]
|
||
|
return ""
|
||
13 years ago
|
|
||
13 years ago
|
|
||
13 years ago
|
class VariableOsInstallClockTimezone(LocaleVariable):
|
||
13 years ago
|
"""
|
||
|
Installation timezone for clock
|
||
|
"""
|
||
|
mode = 'w'
|
||
|
type = 'choiceedit'
|
||
|
metavalue = "TIMEZONE"
|
||
|
opt = ["--timezone"]
|
||
|
|
||
13 years ago
|
def init(self):
|
||
|
self.label = _("Timezone")
|
||
13 years ago
|
self.help = _("set the timezone")
|
||
13 years ago
|
|
||
13 years ago
|
def get(self):
|
||
|
return self.Get('os_clock_timezone')
|
||
|
|
||
|
def check(self,value):
|
||
|
if not value or not path.isfile(path.join(
|
||
|
"/usr/share/zoneinfo",value)):
|
||
12 years ago
|
raise VariableError(_("Wrong timezone %s")%value)
|
||
13 years ago
|
|
||
13 years ago
|
def generateComments(self,tzs):
|
||
|
"""
|
||
|
Generate comments by timezone names
|
||
|
"""
|
||
|
for tzname in tzs:
|
||
|
# add separator
|
||
|
if tzname == "---":
|
||
|
yield ("---","---")
|
||
|
continue
|
||
|
try:
|
||
|
tz = timezone(tzname)
|
||
|
strinfo = tz.localize(datetime.now()).strftime('%z')
|
||
|
yield (tzname,"%s (%s:%s)"%(tzname,strinfo[:3],strinfo[-2:]))
|
||
|
except UnknownTimeZoneError:
|
||
|
pass
|
||
|
|
||
13 years ago
|
def choice(self):
|
||
13 years ago
|
source = ["Etc/GMT-12", "Pacific/Midway", "Pacific/Honolulu",
|
||
13 years ago
|
"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",
|
||
12 years ago
|
"Asia/Amman", "Europe/Istanbul", "Asia/Beirut",
|
||
|
"Europe/Helsinki", "Europe/Kiev",
|
||
13 years ago
|
"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"]
|
||
12 years ago
|
def sortkey(s):
|
||
|
tz = timezone(s)
|
||
|
strinfo = tz.localize(datetime.now()).strftime('%z')
|
||
|
return (int(strinfo[:3]),int("%s%s"%(strinfo[0],strinfo[-2:])))
|
||
13 years ago
|
try:
|
||
|
lang = self.Get('os_install_locale_lang').split('_')[1]
|
||
|
nativeTZ = map(lambda x:x.encode('utf-8'),
|
||
|
country_timezones[lang])
|
||
12 years ago
|
source = nativeTZ + ["---"] + \
|
||
|
sorted(filter(lambda x:not x in nativeTZ,source),
|
||
12 years ago
|
key=sortkey)
|
||
13 years ago
|
except (KeyError,IndexError) as e:
|
||
|
pass
|
||
|
return list(self.generateComments(source))
|
||
13 years ago
|
|
||
13 years ago
|
class VariableOsInstallClockType(Variable):
|
||
|
"""
|
||
|
Type of clock (UTC or local)
|
||
|
"""
|
||
|
mode = 'w'
|
||
|
type = 'choice'
|
||
|
opt = ["--clocktype"]
|
||
|
metavalue = "CLOCKTYPE"
|
||
|
|
||
13 years ago
|
def init(self):
|
||
|
self.label = _("Clock type")
|
||
|
|
||
13 years ago
|
def get(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"
|
||
13 years ago
|
|
||
13 years ago
|
def choice(self):
|
||
|
return ["local","UTC"]
|