[PATCHv2] Use libxklavier's new methods instead of our nasty hack

Vratislav Podzimek vpodzime at redhat.com
Mon Dec 16 13:21:21 UTC 2013


Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 anaconda.spec.in       |  5 +++--
 pyanaconda/keyboard.py | 49 +++++++++++++++----------------------------------
 2 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/anaconda.spec.in b/anaconda.spec.in
index 923a16c..3d8f710 100644
--- a/anaconda.spec.in
+++ b/anaconda.spec.in
@@ -41,6 +41,7 @@ Source0: %{name}-%{version}.tar.bz2
 %define rpmver 4.10.0
 %define libarchivever 3.0.4
 %define langtablever 0.0.18-1
+%define libxklavierver 5.4
 
 BuildRequires: audit-libs-devel
 BuildRequires: gettext >= %{gettextver}
@@ -55,7 +56,7 @@ BuildRequires: libXt-devel
 BuildRequires: libXxf86misc-devel
 BuildRequires: libgnomekbd-devel
 BuildRequires: libnl-devel >= %{libnlver}
-BuildRequires: libxklavier-devel
+BuildRequires: libxklavier-devel >= %{libxklavierver}
 BuildRequires: pango-devel
 BuildRequires: pykickstart >= %{pykickstartver}
 %if ! 0%{?rhel}
@@ -105,7 +106,7 @@ Requires: python-IPy
 Requires: python-nss
 Requires: tigervnc-server-minimal
 Requires: pytz
-Requires: libxklavier
+Requires: libxklavier >= %{libxklavierver}
 Requires: libgnomekbd
 Requires: realmd
 Requires: teamd
diff --git a/pyanaconda/keyboard.py b/pyanaconda/keyboard.py
index 21505a2..82ec405 100644
--- a/pyanaconda/keyboard.py
+++ b/pyanaconda/keyboard.py
@@ -32,11 +32,9 @@ keymaps.
 
 """
 
-import types
 import os
 import re
 import shutil
-import ctypes
 import gettext
 import threading
 
@@ -351,21 +349,6 @@ def background_XklWrapper_initialize():
 
     threadMgr.add(AnacondaThread(name=THREAD_XKL_WRAPPER_INIT, target=XklWrapper.get_instance))
 
-def item_str(s):
-    """Convert a zero-terminated byte array to a proper str"""
-
-    # depending of version of libxklavier and the tools generating introspection
-    # data the value of 's' can be either byte string or list of integers
-    if type(s) == types.StringType:
-        i = s.find(b'\x00')
-        s = s[:i]
-    elif type(s) == types.ListType:
-        # XXX: this is the wrong case that should be fixed (rhbz#920595)
-        i = s.index(0)
-        s = "".join(chr(ctypes.c_uint8(char).value) for char in s[:i])
-
-    return s.decode("utf-8") #there are some non-ascii layout descriptions
-
 class XklWrapperError(KeyboardConfigError):
     """Exception class for reporting libxklavier-related problems"""
 
@@ -442,48 +425,46 @@ class XklWrapper(object):
 
     def _get_lang_variant(self, c_reg, item, subitem, lang):
         if subitem:
-            name = item_str(item.name) + " (" + item_str(subitem.name) + ")"
-            description = item_str(subitem.description)
+            name = item.get_name() + " (" + subitem.get_name() + ")"
+            description = subitem.get_description()
         else:
-            name = item_str(item.name)
-            description = item_str(item.description)
+            name = item.get_name()
+            description = item.get_description()
 
         #if this layout has already been added for some other language,
         #do not add it again (would result in duplicates in our lists)
         if name not in self._layout_infos:
-            self._layout_infos[name] = LayoutInfo(lang.encode("utf-8"),
-                                                  description.encode("utf-8"))
+            self._layout_infos[name] = LayoutInfo(lang, description)
 
     def _get_country_variant(self, c_reg, item, subitem, country):
         if subitem:
-            name = item_str(item.name) + " (" + item_str(subitem.name) + ")"
-            description = item_str(subitem.description)
+            name = item.get_name() + " (" + subitem.get_name() + ")"
+            description = subitem.get_description()
         else:
-            name = item_str(item.name)
-            description = item_str(item.description)
+            name = item.get_name()
+            description = item.get_description()
 
         # if the layout was not added with any language, add it with a country
         if name not in self._layout_infos:
-            self._layout_infos[name] = LayoutInfo(country.encode("utf-8"),
-                                                  description.encode("utf-8"))
+            self._layout_infos[name] = LayoutInfo(country, description)
 
     def _get_language_variants(self, c_reg, item, user_data=None):
-        lang_name, lang_desc = item_str(item.name), item_str(item.description)
+        lang_name, lang_desc = item.get_name(), item.get_description()
 
         c_reg.foreach_language_variant(lang_name, self._get_lang_variant, lang_desc)
 
     def _get_country_variants(self, c_reg, item, user_data=None):
-        country_name, country_desc = item_str(item.name), item_str(item.description)
+        country_name, country_desc = item.get_name(), item.get_description()
 
         c_reg.foreach_country_variant(country_name, self._get_country_variant,
                                       country_desc)
 
     def _get_switch_option(self, c_reg, item, user_data=None):
         """Helper function storing layout switching options in foreach cycle"""
-        desc = item_str(item.description)
-        name = item_str(item.name)
+        desc = item.get_description()
+        name = item.get_name()
 
-        self._switch_opt_infos[name] = desc.encode("utf-8")
+        self._switch_opt_infos[name] = desc
 
     def get_current_layout(self):
         """
-- 
1.8.4.2



More information about the anaconda-patches mailing list