[PATCH 3/3] Use langtable to get default layout instead of our magic (#485137)

Vratislav Podzimek vpodzime at redhat.com
Fri Jul 12 11:01:38 UTC 2013


langtable has the right data and if not, it can be easily fixed by the people
who are experts in the area.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pyanaconda/keyboard.py              | 60 ++-----------------------------------
 pyanaconda/ui/gui/spokes/welcome.py | 25 ++++++++--------
 2 files changed, 15 insertions(+), 70 deletions(-)

diff --git a/pyanaconda/keyboard.py b/pyanaconda/keyboard.py
index a3f0044..adaf5c6 100755
--- a/pyanaconda/keyboard.py
+++ b/pyanaconda/keyboard.py
@@ -35,9 +35,11 @@ keymaps.
 import types
 import os
 import shutil
+import langtable
 
 from pyanaconda import iutil
 from pyanaconda import flags
+from pyanaconda import localization
 from pyanaconda.safe_dbus import dbus_call_safe_sync, dbus_get_property_safe_sync
 from pyanaconda.safe_dbus import DBUS_SYSTEM_BUS_ADDR, DBusPropertyError
 
@@ -478,64 +480,6 @@ class XklWrapper(object):
 
         return self._switching_options
 
-    def get_default_language_layout(self, language):
-        """Get the default layout for a given language."""
-
-        layouts = self.get_language_layouts(language)
-        if layouts:
-            #first layout (should exist for every language)
-            return layouts[0].name
-        else:
-            return None
-
-    def get_language_layouts(self, language):
-        """Get layouts for a given language."""
-
-        language_layouts = self._language_keyboard_variants.get(language, None)
-
-        if language_layouts:
-            return language_layouts
-
-        #else try some magic and if everything fails, return None
-        for (lang, layouts) in self._language_keyboard_variants.iteritems():
-            #XXX: some languages are returned in a weird form from the
-            #     libxklavier iterations (e.g. "Greek, Modern (1453-)")
-            if lang.startswith(language):
-                return layouts
-
-        return None
-
-    def get_default_lang_country_layout(self, language, country):
-        """
-        Get default layout matching both language and country. If none such
-        layout is found, get default layout for language. If no layout for
-        the given language is found but there is layout for the given country,
-        return the one for the country.
-
-        """
-
-        language_layouts = self.get_language_layouts(language)
-        country_layouts = self._country_keyboard_variants.get(country, None)
-        if not language_layouts and not country_layouts:
-            return None
-
-        if not country_layouts:
-            return language_layouts[0].name
-
-        if not language_layouts:
-            return country_layouts[0].name
-
-        matches_both = (layout for layout in language_layouts
-                                if layout in country_layouts)
-
-        try:
-            return matches_both.next().name
-        except StopIteration:
-            if country_layouts:
-                return country_layouts[0].name
-            else:
-                return language_layouts[0].name
-
     def activate_default_layout(self):
         """
         Activates default layout (the first one in the list of configured
diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py
index 15d7a04..d0834e6 100644
--- a/pyanaconda/ui/gui/spokes/welcome.py
+++ b/pyanaconda/ui/gui/spokes/welcome.py
@@ -78,14 +78,18 @@ class WelcomeLanguageSpoke(StandaloneSpoke):
             # current language
             self.data.timezone.timezone = loc_timezones[0]
 
-        lang_country = localization.get_locale_territory(self.data.lang.lang)
-        self._set_keyboard_defaults(store[itr][1], lang_country)
+        self._set_keyboard_defaults(self.data.lang.lang)
 
-    def _set_keyboard_defaults(self, lang_name, country):
+    def _set_keyboard_defaults(self, locale):
         """
         Set default keyboard settings (layouts, layout switching).
 
-        :param lang_name: name of the selected language (e.g. "Czech")
+        :param locale: locale string (see localization.LANGCODE_RE)
+        :type locale: str
+        :return: list of preferred keyboard layouts
+        :rtype: list of strings
+        :raise InvalidLocaleSpec: if an invalid locale is given (see
+                                  localization.LANGCODE_RE)
 
         """
 
@@ -101,14 +105,10 @@ class WelcomeLanguageSpoke(StandaloneSpoke):
             #do not add layouts if there are any specified in the kickstart
             return
 
-        #get language name without any additional specifications
-        #e.g. 'English (United States)' -> 'English'
-        lang_name = lang_name.split()[0]
-
-        default_layout = self._xklwrapper.get_default_lang_country_layout(lang_name,
-                                                                          country)
-        if default_layout:
-            new_layouts = [default_layout]
+        layouts = localization.get_locale_keyboards(locale)
+        if layouts:
+            # take the first locale (with highest rank) from the list
+            new_layouts = [layouts[0]]
         else:
             new_layouts = ["us"]
 
@@ -210,6 +210,7 @@ class WelcomeLanguageSpoke(StandaloneSpoke):
             self._origStrings[welcomeLabel] = welcomeLabel.get_label()
 
         before = self._origStrings[welcomeLabel]
+        # pylint: disable-msg=E1103
         xlated = _(before) % (productName.upper(), productVersion)
         welcomeLabel.set_label(xlated)
 
-- 
1.7.11.7



More information about the anaconda-patches mailing list