isolate localeInfo and expandLangs() from langauges.py into a separate module.
After 0c662ebeaf4043ff2e2a1f7d09b527f4bf243047, we can not build due to
imports problem during build time (importing pyanaconda.constants tries to
import pyanaconda.__init__ which tries to import isys etc.). This change
separates the language.py bits and the bits needed during build time.
-# Converts a single language into a "language search path". For example,
-# fr_FR.utf8@euro would become "fr_FR.utf8@euro fr_FR.utf8 fr_FR fr"
-def expandLangs(astring):
- langs = [astring]
- charset = None
- base = None
-
- # remove charset ...
- if '.' in astring:
- langs.append(string.split(astring, '.')[0])
-
- if '@' in astring:
- charset = string.split(astring, '@')[1]
-
- if '_' in astring:
- base = string.split(astring, '_')[0]
-
- if charset:
- langs.append("%s@%s" % (base, charset))
-
- langs.append(base)
- else:
- langs.append(astring[:2])
-
- return langs
-
class Language(object):
def _setInstLang(self, value):
# Always store in its full form so we know what we're comparing with.
@@ -147,7 +122,6 @@ class Language(object):
self._default = "en_US.UTF-8"
self.displayMode = display_mode
self.info = {}
- self.localeInfo = {}
self.nativeLangNames = {}
# English name -> native name mapping
@@ -163,27 +137,7 @@ class Language(object):
f.close()
break
- # nick -> (name, short name, font, 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, ' ')
-
- # throw out invalid lines
- if len(l) < 6:
- continue
-
- self.localeInfo[l[3]] = (l[0], l[1], l[2], l[4], string.strip(l[5]))
-
- f.close()
- break
-
- # Hard code this to prevent errors in the build environment.
- self.localeInfo['C'] = self.localeInfo[self._default]
+ self.localeInfo = localeinfo.get(self._default)
# instLang must be set after localeInfo is populated, in case the
# current setting is unsupported by anaconda..
@@ -199,7 +153,7 @@ class Language(object):
fr_CA -> ValueError
"""
for key in self.localeInfo.keys():
- if lang in expandLangs(key):
+ if lang in localeinfo.expandLangs(key):
return key
raise ValueError
@@ -229,7 +183,7 @@ class Language(object):
return args
def getDefaultKeyboard(self):
try:
diff --git a/pyanaconda/localeinfo.py b/pyanaconda/localeinfo.py
new file mode 100644
index 0000000..f036358
--- /dev/null
+++ b/pyanaconda/localeinfo.py
@@ -0,0 +1,81 @@
+# __init__.py
+# Entry point for anaconda's storage configuration module.
+#
+# Copyright (C) 2009 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, font, 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, ' ')
+
+ # throw out invalid lines
+ if len(l) < 6:
+ continue
+
+ localeInfo[l[3]] = (l[0], l[1], l[2], 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
+
+# Converts a single language into a "language search path". For example,
+# fr_FR.utf8@euro would become "fr_FR.utf8@euro fr_FR.utf8 fr_FR fr"
+def expandLangs(astring):
+ langs = [astring]
+ charset = None
+ base = None
+
+ # remove charset ...
+ if '.' in astring:
+ langs.append(string.split(astring, '.')[0])
+
+ if '@' in astring:
+ charset = string.split(astring, '@')[1]
+
+ if '_' in astring:
+ base = string.split(astring, '_')[0]
+
+ if charset:
+ langs.append("%s@%s" % (base, charset))
+
+ langs.append(base)
+ else:
+ langs.append(astring[:2])
+
+ return langs
+
diff --git a/pyanaconda/text.py b/pyanaconda/text.py
index 6396f25..cb85bb5 100644
--- a/pyanaconda/text.py
+++ b/pyanaconda/text.py
@@ -32,7 +32,7 @@ import signal
import parted
import product
import string
-from language import expandLangs
+from localeinfo import expandLangs
from flags import flags
from textw.constants_text import *
from constants import *
diff --git a/scripts/getlangnames.py b/scripts/getlangnames.py
index bc3cced..2e579a4 100644
--- a/scripts/getlangnames.py
+++ b/scripts/getlangnames.py
@@ -19,26 +19,26 @@
import sys
sys.path.append("..")
-import language as language
+import localeinfo
import gettext
-langs = language.Language()
+localeInfo = localeinfo.get("en_US.UTF-8")
names = {}
-for k in langs.localeInfo.keys():
+for k in localeInfo.keys():
found = False
- for l in language.expandLangs(k):
+ for l in localeinfo.expandLangs(k):
try:
f = open("../po/%s.gmo" %(l,))
except (OSError, IOError):
continue
cat = gettext.GNUTranslations(f)
cat.set_output_charset("utf-8")
- names[langs.localeInfo[k][0]] = cat.lgettext(langs.localeInfo[k][0])
+ names[localeInfo[k][0]] = cat.lgettext(localeInfo[k][0])
found = True
break
if not found:
- names[langs.localeInfo[k][0]] = langs.localeInfo[k][0]
+ names[localeInfo[k][0]] = localeInfo[k][0]