[PATCH 1/2 v2] Move expandLangs to localization module
Vratislav Podzimek
vpodzime at redhat.com
Tue Aug 28 14:15:43 UTC 2012
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
pyanaconda/language.py | 6 +++---
pyanaconda/localeinfo.py | 27 ---------------------------
pyanaconda/localization.py | 29 +++++++++++++++++++++++++++++
pyanaconda/ui/gui/hubs/progress.py | 4 ++--
scripts/getlangnames.py | 3 ++-
tests/pyanaconda_test/localeinfo_test.py | 5 -----
6 files changed, 36 insertions(+), 38 deletions(-)
diff --git a/pyanaconda/language.py b/pyanaconda/language.py
index fb8d35e..9c37e79 100644
--- a/pyanaconda/language.py
+++ b/pyanaconda/language.py
@@ -26,7 +26,7 @@ import locale
import gettext
from pyanaconda.constants import ROOT_PATH, DEFAULT_LANG
-import localeinfo
+import localization
from simpleconfig import SimpleConfigFile
import logging
@@ -144,7 +144,7 @@ class Language(object):
fr_CA -> ValueError
"""
for key in self.localeInfo.keys():
- if lang in localeinfo.expandLangs(key):
+ if lang in localization.expand_langs(key):
return key
raise ValueError
@@ -162,7 +162,7 @@ class Language(object):
return args
def getCurrentLangSearchList(self):
- return localeinfo.expandLangs(self.systemLang) + ['C']
+ return localization.expand_langs(self.systemLang) + ['C']
def getDefaultTimeZone(self):
try:
diff --git a/pyanaconda/localeinfo.py b/pyanaconda/localeinfo.py
index 334cadf..0bb1799 100644
--- a/pyanaconda/localeinfo.py
+++ b/pyanaconda/localeinfo.py
@@ -54,30 +54,3 @@ def get(default):
# 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 at euro would become "fr_FR.utf8 at 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/localization.py b/pyanaconda/localization.py
index 74e68b9..ff02d8a 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -138,6 +138,35 @@ def get_available_translations(domain=None, localedir=None):
yield LocaleInfo(localedata)
+def expand_langs(astring):
+ """
+ Converts a single language into a "language search path". For example,
+ fr_FR.utf8 at euro would become "fr_FR.utf8 at euro fr_FR.utf8 fr_FR fr"
+
+ """
+
+ langs = [astring]
+ charset = None
+ base = None
+
+ # remove charset ...
+ if '.' in astring:
+ langs.append(astring.split('.')[0])
+
+ if '@' in astring:
+ charset = astring.split('@')[1]
+
+ if '_' in astring:
+ base = astring.split('_')[0]
+
+ if charset:
+ langs.append("%s@%s" % (base, charset))
+
+ langs.append(base)
+ else:
+ langs.append(astring[:2])
+
+ return langs
class PreferredLocale(object):
diff --git a/pyanaconda/ui/gui/hubs/progress.py b/pyanaconda/ui/gui/hubs/progress.py
index b1c1e93..13d1811 100644
--- a/pyanaconda/ui/gui/hubs/progress.py
+++ b/pyanaconda/ui/gui/hubs/progress.py
@@ -29,7 +29,7 @@ from gi.repository import GLib
import itertools
import os
-from pyanaconda.localeinfo import expandLangs
+from pyanaconda.localization import expand_langs
from pyanaconda.product import productName
from pyanaconda.flags import flags
from pykickstart.constants import KS_WAIT, KS_SHUTDOWN, KS_REBOOT
@@ -99,7 +99,7 @@ class ProgressHub(Hub):
# We first look for rnotes in paths containing the language, then in
# directories without the language component. You know, just in case.
- langs = expandLangs(os.environ["LANG"]) + [""]
+ langs = expand_langs(os.environ["LANG"]) + [""]
paths = ["/tmp/updates/pixmaps/rnotes/%s/*.png",
"/tmp/product/pixmaps/rnotes/%s/*.png",
"/usr/share/anaconda/pixmaps/rnotes/%s/*.png"]
diff --git a/scripts/getlangnames.py b/scripts/getlangnames.py
index 2e579a4..5e0f96d 100644
--- a/scripts/getlangnames.py
+++ b/scripts/getlangnames.py
@@ -20,6 +20,7 @@
import sys
sys.path.append("..")
import localeinfo
+import localization
import gettext
@@ -27,7 +28,7 @@ localeInfo = localeinfo.get("en_US.UTF-8")
names = {}
for k in localeInfo.keys():
found = False
- for l in localeinfo.expandLangs(k):
+ for l in localization.expand_langs(k):
try:
f = open("../po/%s.gmo" %(l,))
except (OSError, IOError):
diff --git a/tests/pyanaconda_test/localeinfo_test.py b/tests/pyanaconda_test/localeinfo_test.py
index 32f0916..4586a34 100644
--- a/tests/pyanaconda_test/localeinfo_test.py
+++ b/tests/pyanaconda_test/localeinfo_test.py
@@ -11,11 +11,6 @@ class LocaleinfoTest(mock.TestCase):
def tearDown(self):
self.tearDownModules()
- def expandLangs_test(self):
- from pyanaconda import localeinfo
- exp = localeinfo.expandLangs("fr_FR.utf8 at euro")
- self.assertEqual(exp, ['fr_FR.utf8 at euro', 'fr_FR', 'fr at euro', 'fr'])
-
def get_test(self):
from pyanaconda import localeinfo
--
1.7.11.4
More information about the anaconda-patches
mailing list