These two patches remove no longer used/needed files and add few lines for writing language system configuration to the installed system. This part needs one more patch for writing /etc/locale.conf, but I don't know how this file should look. Please not that these patches are not tested as I am sending them from the BaseOS team building without virtualization available. I will test them before pusing tomorrow.
Vratislav Podzimek (2): Remove lang-table and localeinfo.py Remove anaconda.instLanguage object and language module
anaconda | 3 - data/lang-table | 61 --------- pyanaconda/__init__.py | 10 -- pyanaconda/install.py | 1 + pyanaconda/installclass.py | 1 - pyanaconda/kickstart.py | 6 + pyanaconda/language.py | 216 ------------------------------ pyanaconda/localeinfo.py | 56 -------- pyanaconda/localization.py | 25 ++++ tests/pyanaconda_test/language_test.py | 237 --------------------------------- 10 files changed, 32 insertions(+), 584 deletions(-) delete mode 100644 data/lang-table delete mode 100644 pyanaconda/language.py delete mode 100644 pyanaconda/localeinfo.py delete mode 100644 tests/pyanaconda_test/language_test.py
We no longer use lang-table for anything. localeinfo.py is module for accessing data from lang-table.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- data/lang-table | 61 ------------------------------------------------ pyanaconda/localeinfo.py | 56 -------------------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 data/lang-table delete mode 100644 pyanaconda/localeinfo.py
diff --git a/data/lang-table b/data/lang-table deleted file mode 100644 index 465c3df..0000000 --- a/data/lang-table +++ /dev/null @@ -1,61 +0,0 @@ -Afrikaans af True af_ZA.UTF-8 us Africa/Johannesburg -Arabic ar False ar_SA.UTF-8 us Asia/Riyadh -Assamese as False as_IN.UTF-8 us Asia/Kolkata -Bengali bn False bn_BD.UTF-8 us Asia/Dhaka -Bengali(India) bn_IN False bn_IN.UTF-8 us Asia/Kolkata -Bulgarian bg True bg_BG.UTF-8 bg_bds-utf8 Europe/Sofia -Catalan ca True ca_ES.UTF-8 es Europe/Madrid -Chinese(Simplified) zh_CN False zh_CN.UTF-8 us Asia/Shanghai -Chinese(Traditional) zh_TW False zh_TW.UTF-8 us Asia/Taipei -Croatian hr True hr_HR.UTF-8 croat Europe/Zagreb -Czech cs True cs_CZ.UTF-8 cz-lat2 Europe/Prague -Danish da True da_DK.UTF-8 dk Europe/Copenhagen -Dutch nl True nl_NL.UTF-8 nl Europe/Amsterdam -English en True en_US.UTF-8 us America/New_York -Estonian et True et_EE.UTF-8 et Europe/Tallinn -Finnish fi True fi_FI.UTF-8 fi Europe/Helsinki -French fr True fr_FR.UTF-8 fr-latin9 Europe/Paris -German de True de_DE.UTF-8 de-latin1-nodeadkeys Europe/Berlin -Greek el False el_GR.UTF-8 gr Europe/Athens -Gujarati gu False gu_IN.UTF-8 us Asia/Kolkata -Hebrew he False he_IL.UTF-8 us Asia/Jerusalem -Hindi hi False hi_IN.UTF-8 us Asia/Kolkata -Hungarian hu True hu_HU.UTF-8 hu Europe/Budapest -Icelandic is True is_IS.UTF-8 is-latin1 Atlantic/Reykjavik -Iloko ilo True ilo_PH.UTF-8 us Asia/Manila -Indonesian id True id_ID.UTF-8 us Asia/Jakarta -Italian it True it_IT.UTF-8 it Europe/Rome -Japanese ja False ja_JP.UTF-8 jp106 Asia/Tokyo -Kannada kn False kn_IN.UTF-8 us Asia/Kolkata -Korean ko False ko_KR.UTF-8 us Asia/Seoul -Macedonian mk True mk_MK.UTF-8 mk Europe/Skopje -Maithili mai False mai_IN.UTF-8 us Asia/Kolkata -Malay ms True ms_MY.UTF-8 us Asia/Kuala_Lumpur -Malayalam ml False ml_IN.UTF-8 us Asia/Kolkata -Marathi mr False mr_IN.UTF-8 us Asia/Kolkata -Nepali ne False ne_NP.UTF-8 us Asia/Kathmandu -Norwegian(Bokmål) nb True nb_NO.UTF-8 no Europe/Oslo -Northern Sotho nso True nso_ZA.UTF-8 us Africa/Johannesburg -Oriya or False or_IN.UTF-8 us Asia/Kolkata -Persian fa False fa_IR.UTF-8 us Asia/Tehran -Polish pl True pl_PL.UTF-8 pl2 Europe/Warsaw -Portuguese pt True pt_PT.UTF-8 pt-latin1 Europe/Lisbon -Portuguese(Brazilian) pt_BR True pt_BR.UTF-8 br-abnt2 America/Sao_Paulo -Punjabi pa False pa_IN.UTF-8 us Asia/Kolkata -Romanian ro False ro_RO.UTF-8 ro Europe/Bucharest -Russian ru False ru_RU.UTF-8 ru Europe/Moscow -Serbian sr True sr_RS.UTF-8 sr-cy Europe/Belgrade -Serbian(Latin) sr@latin True sr_RS.UTF-8@latin sr-latin Europe/Belgrade -Sinhala si False si_LK.UTF-8 us Asia/Colombo -Slovak sk True sk_SK.UTF-8 sk-qwerty Europe/Bratislava -Slovenian sl True sl_SI.UTF-8 slovene Europe/Ljubljana -Spanish es True es_ES.UTF-8 es Europe/Madrid -Swedish sv True sv_SE.UTF-8 sv-latin1 Europe/Stockholm -Tajik tg False tg_TG.UTF-8 tj Asia/Dushanbe -Tamil ta False ta_IN.UTF-8 us Asia/Kolkata -Telugu te False te_IN.UTF-8 us Asia/Kolkata -Turkish tr True tr_TR.UTF-8 trq Europe/Istanbul -Ukrainian uk True uk_UA.UTF-8 ua-utf Europe/Kiev -Vietnamese vi True vi_VN.UTF-8 us Asia/Saigon -Welsh cy True cy_GB.UTF-8 uk Europe/London -Zulu zu True zu_ZA.UTF-8 us Africa/Johannesburg diff --git a/pyanaconda/localeinfo.py b/pyanaconda/localeinfo.py deleted file mode 100644 index 0bb1799..0000000 --- a/pyanaconda/localeinfo.py +++ /dev/null @@ -1,56 +0,0 @@ -# __init__.py -# Locale info used by getlangnames.py and languages.py. -# -# Copyright (C) 2011 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties 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 this program; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# - - -""" Basic locale operations useful during both Anaconda build time and run time. - - This module can be imported without importing pyanaconda/__init__.py and it - is desirable to keep it that way. -""" - -import os -import string - -def get(default): - localeInfo = {} - # nick -> (name, short name, text mode supported, keyboard, timezone) mapping - search = ('lang-table', '/tmp/updates/lang-table', '/etc/lang-table', - '/usr/share/anaconda/lang-table') - for path in search: - if os.access(path, os.R_OK): - f = open(path, "r") - for line in f.readlines(): - string.strip(line) - l = string.split(line, '\t') - - # throw out invalid lines - if len(l) < 6: - continue - - ts = l[2] == "True" - - localeInfo[l[3]] = (l[0], l[1], ts, l[4], string.strip(l[5])) - - f.close() - break - - # Hard code this to prevent errors in the build environment. - localeInfo['C'] = localeInfo[default] - return localeInfo
We no longer use lang-table for anything. localeinfo.py is module for accessing data from lang-table.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com
data/lang-table | 61 ------------------------------------------------ pyanaconda/localeinfo.py | 56 -------------------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 data/lang-table delete mode 100644 pyanaconda/localeinfo.py
Make sure to also remove references in data/Makefile.am (EXTRA_DIST and the lang-names business) too. I imagine that therefore means scripts/getlangnames.py can go away too.
Then, I yesterday added a BuildRequires on python-babel which I think can also be removed. Worth testing.
- Chris
On Thu, 2012-08-30 at 13:13 -0400, Chris Lumens wrote:
We no longer use lang-table for anything. localeinfo.py is module for accessing data from lang-table.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com
data/lang-table | 61 ------------------------------------------------ pyanaconda/localeinfo.py | 56 -------------------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 data/lang-table delete mode 100644 pyanaconda/localeinfo.py
Make sure to also remove references in data/Makefile.am (EXTRA_DIST and the lang-names business) too. I imagine that therefore means scripts/getlangnames.py can go away too.
Then, I yesterday added a BuildRequires on python-babel which I think can also be removed. Worth testing.
Thanks, I will make the suggested changes and test it. However, I have some problems with updates.img, so I'm leaving this to Monday.
On Fri, 2012-08-31 at 16:05 +0200, Vratislav Podzimek wrote:
On Thu, 2012-08-30 at 13:13 -0400, Chris Lumens wrote:
We no longer use lang-table for anything. localeinfo.py is module for accessing data from lang-table.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com
data/lang-table | 61 ------------------------------------------------ pyanaconda/localeinfo.py | 56 -------------------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 data/lang-table delete mode 100644 pyanaconda/localeinfo.py
Make sure to also remove references in data/Makefile.am (EXTRA_DIST and the lang-names business) too. I imagine that therefore means scripts/getlangnames.py can go away too.
Then, I yesterday added a BuildRequires on python-babel which I think can also be removed. Worth testing.
Thanks, I will make the suggested changes and test it. However, I have some problems with updates.img, so I'm leaving this to Monday.
Okay, I have just finished testing and I did successful scratch build without BuildRequires: python-babel. Pushing.
We now use ksdata and execute methods for storing and writing configuration.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- anaconda | 3 - pyanaconda/__init__.py | 10 -- pyanaconda/install.py | 1 + pyanaconda/installclass.py | 1 - pyanaconda/kickstart.py | 6 + pyanaconda/language.py | 216 ------------------------------ pyanaconda/localization.py | 25 ++++ tests/pyanaconda_test/language_test.py | 237 --------------------------------- 8 files changed, 32 insertions(+), 467 deletions(-) delete mode 100644 pyanaconda/language.py delete mode 100644 tests/pyanaconda_test/language_test.py
diff --git a/anaconda b/anaconda index c2b8d08..c7a2aaf 100755 --- a/anaconda +++ b/anaconda @@ -903,9 +903,6 @@ if __name__ == "__main__": if opts.lang: # this is lame, but make things match what we expect (#443408) opts.lang = opts.lang.replace(".utf8", ".UTF-8") - anaconda.instLanguage.instLang = opts.lang - anaconda.instLanguage.systemLang = opts.lang - anaconda.ksdata.timezone.timezone = anaconda.instLanguage.getDefaultTimeZone()
from pyanaconda.storage import storageInitialize from pyanaconda.packaging import payloadInitialize diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py index 4c39841..2ac97c0 100644 --- a/pyanaconda/__init__.py +++ b/pyanaconda/__init__.py @@ -56,7 +56,6 @@ class Anaconda(object): self.firewall = firewall.Firewall() self.id = None self._instClass = None - self._instLanguage = None self._intf = None self.isHeadless = False self.ksdata = None @@ -109,14 +108,6 @@ class Anaconda(object):
return self._instClass
- @property - def instLanguage(self): - if not self._instLanguage: - import language - self._instLanguage = language.Language(self.displayMode) - - return self._instLanguage - def _getInterface(self): return self._intf
@@ -240,7 +231,6 @@ class Anaconda(object): def write(self): import network self.writeXdriver() - self.instLanguage.write()
network.write_sysconfig_network() network.disableIPV6() diff --git a/pyanaconda/install.py b/pyanaconda/install.py index 0652d46..d639df3 100644 --- a/pyanaconda/install.py +++ b/pyanaconda/install.py @@ -86,6 +86,7 @@ def doInstall(storage, payload, ksdata, instClass): ksdata.services.execute(storage, ksdata, instClass) ksdata.keyboard.execute(storage, ksdata, instClass) ksdata.timezone.execute(storage, ksdata, instClass) + ksdata.lang.execute(storage, ksdata, instClass)
writeNetworkConf(storage, ksdata, instClass)
diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py index 100c072..59dfea0 100644 --- a/pyanaconda/installclass.py +++ b/pyanaconda/installclass.py @@ -25,7 +25,6 @@ from distutils.sysconfig import get_python_lib import os, sys, iutil import isys import string -import language import imputil import types
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 9d667c2..826a59a 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -50,6 +50,7 @@ from storage.devices import * from pyanaconda import keyboard from pyanaconda import ntp from pyanaconda import timezone +from pyanaconda import localization from pyanaconda.simpleconfig import SimpleConfigFile
from pykickstart.base import KickstartCommand @@ -535,6 +536,10 @@ class IscsiName(commands.iscsiname.FC6_IscsiName): storage.iscsi.iscsi().initiator = self.iscsiname return retval
+class Lang(commands.lang.FC3_Lang): + def execute(self, *args, **kwargs): + localization.write_language_configuration(self, ROOT_PATH) + class LogVol(commands.logvol.F17_LogVol): def execute(self, storage, ksdata, instClass): for l in self.lvList: @@ -1377,6 +1382,7 @@ commandMap = { "iscsi": Iscsi, "iscsiname": IscsiName, "keyboard": Keyboard, + "language": Lang, "logging": Logging, "logvol": LogVol, "multipath": MultiPath, diff --git a/pyanaconda/language.py b/pyanaconda/language.py deleted file mode 100644 index 9c37e79..0000000 --- a/pyanaconda/language.py +++ /dev/null @@ -1,216 +0,0 @@ -# -# language.py: install data component that stores information about both -# installer runtime language choice and installed system -# language support. -# -# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Red Hat, Inc. -# All rights reserved. -# -# This program 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 2 of the License, or -# (at your option) any later version. -# -# This program 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 this program. If not, see http://www.gnu.org/licenses/. -# - -import os -import string -import locale - -import gettext -from pyanaconda.constants import ROOT_PATH, DEFAULT_LANG -import localization -from simpleconfig import SimpleConfigFile - -import logging -log = logging.getLogger("anaconda") - -class Language(object): - def _setInstLang(self, value): - # Always store in its full form so we know what we're comparing with. - try: - self._instLang = self._canonLang(value) - except ValueError: - # If the language isn't listed in lang-table, we won't know what - # keyboard/etc. to use. However, we can still set the $LANG - # to that and make sure it works in the installed system. - self._instLang = value - - # If we're running in text mode, value may not be a supported language - # to display. Fall back to the default for now. - if self.displayMode == 't': - for (lang, info) in self.localeInfo.iteritems(): - if lang == self._instLang and info[2] == "False": - self._instLang = self._default - break - - # Now set some things to make sure the language setting takes effect - # right now. - os.environ["LANG"] = self._instLang - os.environ["LC_NUMERIC"] = "C" - - try: - locale.setlocale(locale.LC_ALL, "") - except locale.Error: - pass - - # XXX: oh ick. this is the sort of thing which you should never do... - # but we switch languages at runtime and thus need to invalidate - # the set of languages/mofiles which gettext knows about - gettext._translations = {} - - def _getInstLang(self): - # If we were given a language that's not in lang-table, lie and say - # we're using the default. This prevents us from having to check all - # over the place. - if self._instLang in self.localeInfo.keys(): - return self._instLang - else: - return self._default - - # The language being displayed while anaconda is running. - instLang = property(lambda s: s._getInstLang(), lambda s, v: s._setInstLang(v)) - - def _setSystemLang(self, value): - # Always store in its full form so we know what we're comparing with. - try: - self._systemLang = self._canonLang(value) - except ValueError: - # If the language isn't listed in lang-table, we won't know what - # keyboard/etc. to use. However, we can still set the $LANG - # to that and make sure it works in the installed system. - self._systemLang = value - - # Now set a bunch of other things that'll get written to - # /etc/sysconfig/i18n on the installed system. - self.info["LANG"] = self._systemLang - - if not self.localeInfo.has_key(self._systemLang): - return - - if self.localeInfo[self._systemLang][2] == "False": - self.info["SYSFONT"] = None - else: - self.info["SYSFONT"] = "latarcyrheb-sun16" - - # XXX hack - because of exceptional cases on the var - zh_CN.GB2312 - if self._systemLang == "zh_CN.GB18030": - self.info["LANGUAGE"] = "zh_CN.GB18030:zh_CN.GB2312:zh_CN" - - # The language to use on the installed system. This can differ from the - # language being used during anaconda. For instance, text installs cannot - # display all languages (CJK, Indic, etc.). - systemLang = property(lambda s: s._systemLang, lambda s, v: s._setSystemLang(v)) - - def __init__ (self, display_mode = 'g'): - self._default = DEFAULT_LANG - self.displayMode = display_mode - self.info = {} - self.nativeLangNames = {} - - # English name -> native name mapping - search = ('lang-names', '/usr/share/anaconda/lang-names') - for path in search: - if os.access(path, os.R_OK): - f = open(path, 'r') - for line in f.readlines(): - lang, native = string.split(line, '\t') - native = native.strip() - self.nativeLangNames[lang] = native - - f.close() - break - - self.localeInfo = localeinfo.get(self._default) - - # instLang must be set after localeInfo is populated, in case the - # current setting is unsupported by anaconda.. - self.instLang = os.environ.get("LANG", self._default) - self.systemLang = os.environ.get("LANG", self._default) - - def _canonLang(self, lang): - """Convert the shortened form of a language name into the full - version. If it's not found, raise ValueError. - - Example: fr -> fr_FR.UTF-8 - fr_FR -> fr_FR.UTF-8 - fr_CA -> ValueError - """ - for key in self.localeInfo.keys(): - if lang in localization.expand_langs(key): - return key - - raise ValueError - - def available(self): - return self.nativeLangNames.keys() - - def dracutSetupArgs(self): - args=set() - - for (key, val) in self.info.iteritems(): - if val != None: - args.add("%s=%s" % (key, val)) - - return args - - def getCurrentLangSearchList(self): - return localization.expand_langs(self.systemLang) + ['C'] - - def getDefaultTimeZone(self): - try: - return self.localeInfo[self.systemLang][4] - except KeyError: - # If doing an upgrade and the system language is something not - # recognized by anaconda, we should try to see if we can figure - # it out from the running system. - if os.path.exists(ROOT_PATH + "/etc/sysconfig/clock"): - cfg = SimpleConfigFile() - cfg.read(ROOT_PATH + "/etc/sysconfig/clock") - - try: - return cfg.get("ZONE") - except: - return self.localeInfo[self._default][4] - else: - return self.localeInfo[self._default][4] - - def textSupported(self, lang): - try: - l = self._canonLang(lang) - except ValueError: - l = self._default - - return self.localeInfo[l][2] - - def getLangName(self, lang): - try: - l = self._canonLang(lang) - except ValueError: - l = self._default - - return self.localeInfo[l][0] - - def getLangByName(self, name): - for (key, val) in self.localeInfo.iteritems(): - if val[0] == name: - return key - - def getNativeLangName(self, lang): - return self.nativeLangNames[lang] - - def write(self): - f = open(ROOT_PATH + "/etc/sysconfig/i18n", "w") - - for (key, val) in self.info.iteritems(): - if val != None: - f.write("%s="%s"\n" % (key, val)) - - f.close() diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py index ff02d8a..7cb8eb2 100644 --- a/pyanaconda/localization.py +++ b/pyanaconda/localization.py @@ -30,6 +30,12 @@ import babel
LOCALE_PREFERENCES = {}
+SYSCONF_I18N_FILE_PATH = "/etc/sysconfig/i18n" + +class LocalizationConfigError(Exception): + """Exception class for localization configuration related problems""" + + pass
class LocaleInfo(object):
@@ -168,6 +174,25 @@ def expand_langs(astring):
return langs
+def write_language_configuration(lang, root): + """ + Write language configuration to the /etc/sysconfig/i18n file. + + @param lang: ksdata.lang object + @param root: path to the root of the installed system + + """ + + #TODO: write/copy /etc/locale.conf here too + try: + fpath = os.path.normpath(root + SYSCONF_I18N_FILE_PATH) + with fpath as fobj: + fobj.write('LANG="%s"\n' % lang.lang) + + except IOError as ioerr: + msg = "Cannot write language configuration file: %s" % ioerr.strerror + raise LocalizationConfigError(msg) + class PreferredLocale(object):
@staticmethod diff --git a/tests/pyanaconda_test/language_test.py b/tests/pyanaconda_test/language_test.py deleted file mode 100644 index 2325a73..0000000 --- a/tests/pyanaconda_test/language_test.py +++ /dev/null @@ -1,237 +0,0 @@ -#!/usr/bin/python - -import mock - -ENVIRON_LANG = 'en_US.utf8' - -class LanguageTest(mock.TestCase): - - def setUp(self): - self.setupModules(["_isys", "block", "ConfigParser"]) - - # Mock filesystem - self.fs = mock.DiskIO() - - def fake_os_access(path, _): - return path == 'lang-names' - - self.fs.open('lang-names', 'w').write( - "Czech\tCestina\n" - "English\tEnglish\n" - "Hebrew\tHebrew") - - import pyanaconda.language - pyanaconda.language.log = mock.Mock() - pyanaconda.language.gettext = mock.Mock() - pyanaconda.language.open = self.fs.open - pyanaconda.language.os = mock.Mock() - pyanaconda.language.os.access = fake_os_access - pyanaconda.language.os.environ = {'LANG': ENVIRON_LANG} - pyanaconda.language.locale = mock.Mock() - pyanaconda.language.localeinfo.get = mock.Mock(return_value={ - 'C': ('English', 'en', 'latarcyrheb-sun16', 'us', 'America/New_York'), - 'cs_CZ.UTF-8': ('Czech', 'cs', 'latarcyrheb-sun16', 'cz-lat2', 'Europe/Prague'), - 'en_US.UTF-8': ('English', 'en', 'latarcyrheb-sun16', 'us', 'America/New_York'), - 'he_IL.UTF-8': ('Hebrew', 'he', 'none', 'us', 'Asia/Jerusalem')}) - - def tearDown(self): - self.tearDownModules() - - def set_inst_lang_g_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang._setInstLang('cs') - self.assertEqual(pyanaconda.language.os.environ.get('LANG'), 'cs_CZ.UTF-8') - self.assertEqual(pyanaconda.language.os.environ.get('LC_NUMERIC'), 'C') - self.assertTrue(pyanaconda.language.locale.setlocale.called) - self.assertTrue(isinstance(pyanaconda.language.gettext._translations, dict)) - - def set_inst_lang_t_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language('t') - lang._setInstLang('he') - self.assertEqual(pyanaconda.language.os.environ.get('LANG'), 'en_US.UTF-8') - self.assertEqual(pyanaconda.language.os.environ.get('LC_NUMERIC'), 'C') - self.assertTrue(pyanaconda.language.locale.setlocale.called) - self.assertTrue(isinstance(pyanaconda.language.gettext._translations, dict)) - - def get_inst_lang_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang._getInstLang() - self.assertEqual(ret, 'en_US.UTF-8') - - def set_get_inst_lang_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang._setInstLang('cs') - ret = lang._getInstLang() - self.assertEqual(ret, 'cs_CZ.UTF-8') - - def set_system_lang_1_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang._setSystemLang('cs') - self.assertEqual(lang.info.get('LANG'), 'cs_CZ.UTF-8') - self.assertEqual(lang.info.get('SYSFONT', ''), 'latarcyrheb-sun16') - - def set_system_lang_2_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang._setSystemLang('he') - self.assertEqual(lang.info.get('LANG'), 'he_IL.UTF-8') - self.assertEqual(lang.info.get('SYSFONT', ''), None) - - def set_system_lang_3_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang._setSystemLang('foo') - self.assertEqual(lang.info.get('LANG'), 'foo') - self.assertFalse('SYSFONT' in lang.info) - - def system_lang_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang.systemLang = 'cs' - self.assertEqual(lang.info, - {'LANG': 'cs_CZ.UTF-8', 'SYSFONT': 'latarcyrheb-sun16'}) - - def canon_lang_pass_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - self.assertEqual(lang._canonLang('cs_CZ.UTF-8'), 'cs_CZ.UTF-8') - self.assertEqual(lang._canonLang('cs'), 'cs_CZ.UTF-8') - self.assertEqual(lang._canonLang('cs_CZ'), 'cs_CZ.UTF-8') - - def canon_lang_raise_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - self.assertRaises(ValueError, lang._canonLang, 'CZ.UTF-8') - self.assertRaises(ValueError, lang._canonLang, '') - self.assertRaises(ValueError, lang._canonLang, 's_CZ') - self.assertRaises(ValueError, lang._canonLang, 'foo') - - def available_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - self.assertEqual(set(lang.available()), set(['Czech', 'English', 'Hebrew'])) - - def dracut_setup_args_default_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.dracutSetupArgs() - self.assertEqual(ret, set(['LANG=%s' % ENVIRON_LANG])) - - def dracut_setup_args_after_set_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang.systemLang = 'cs' - ret = lang.dracutSetupArgs() - self.assertEqual(ret, set(['LANG=cs_CZ.UTF-8', 'SYSFONT=latarcyrheb-sun16'])) - - def get_current_lang_search_list_default_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getCurrentLangSearchList() - self.assertEqual(set(ret), set([ENVIRON_LANG, 'en_US', 'en', 'C'])) - - def get_current_lang_search_list_after_set_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang.systemLang = 'cs' - ret = lang.getCurrentLangSearchList() - self.assertEqual(set(ret), set(['cs_CZ.UTF-8', 'cs_CZ', 'cs', 'C'])) - - def get_default_time_zone_default_test(self): - import pyanaconda.language - pyanaconda.language.os.path.exists = mock.Mock(return_value=False) - lang = pyanaconda.language.Language() - ret = lang.getDefaultTimeZone() - self.assertEqual(ret, 'America/New_York') - - def get_default_time_zone_with_cs_CZ_locale_test(self): - import pyanaconda.language - pyanaconda.language.os.environ = {'LANG': 'cs'} - pyanaconda.language.os.path.exists = mock.Mock(return_value=False) - lang = pyanaconda.language.Language() - ret = lang.getDefaultTimeZone() - self.assertEqual(ret, 'Europe/Prague') - - def get_default_time_zone_after_set_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang.systemLang = 'cs' - ret = lang.getDefaultTimeZone() - self.assertEqual(ret, 'Europe/Prague') - - def get_text_supported_1_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - self.assertTrue(lang.textSupported('cs')) - - def get_text_supported_2_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - self.assertFalse(lang.textSupported('he')) - - def get_lang_name_1_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getLangName('en') - self.assertEqual(ret, 'English') - - def get_lang_name_2_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getLangName('cs') - self.assertEqual(ret, 'Czech') - - def get_lang_name_3_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getLangName('he') - self.assertEqual(ret, 'Hebrew') - - def get_lang_name_4_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getLangName('foo') - self.assertEqual(ret, 'English') - - def get_lang_by_name_1_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getLangByName('English') - self.assertEqual(ret, 'C') - - def get_lang_by_name_2_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getLangByName('Czech') - self.assertEqual(ret, 'cs_CZ.UTF-8') - - def get_native_lang_name_1_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getNativeLangName('Czech') - self.assertEqual(ret, 'Cestina') - - def get_native_lang_name_2_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.getNativeLangName('English') - self.assertEqual(ret, 'English') - - def write_1_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - ret = lang.write() - self.assertEqual(self.fs['/mnt/sysimage/etc/sysconfig/i18n'], 'LANG="%s"\n' % ENVIRON_LANG) - - def write_2_test(self): - import pyanaconda.language - lang = pyanaconda.language.Language() - lang.systemLang = 'cs' - ret = lang.write() - self.assertEqual(self.fs['/mnt/sysimage/etc/sysconfig/i18n'], - 'LANG="cs_CZ.UTF-8"\nSYSFONT="latarcyrheb-sun16"\n')
anaconda-patches@lists.fedorahosted.org