[virt-tools-list] [virt-install PATCH v2 05/14] osdict: Properly set language and kbd layout for install script config

Fabiano Fidêncio fidencio at redhat.com
Fri Feb 22 08:40:12 UTC 2019


Let's try to guess the language and keyboard layout from the system's
language.

In case we can't do the guess, let's just let it be and libosinfo will
use the 'en_US' default for both language and keyboard layout.

There's a big issue here, though, that quite often users will *not* have
their keyboard layout matching with the language of their systems and,
unfortunately, I don't see any easy way to detect that unless we totally
rely on GLib.Settings (which, according to my understanding, we can't).

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/osdict.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index 0408e232..c15add02 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -572,6 +572,12 @@ class _OsVariant(object):
                 return None
             return tokens[1]
 
+        def get_language():
+            names = glib.get_language_names()
+            if not names or len(names) < 2:
+                return None
+            return names[1]
+
         config = libosinfo.InstallConfig()
 
         # Set user login and name based on the one from the system
@@ -621,6 +627,22 @@ class _OsVariant(object):
                 _("'America/New_York' timezone will be used for this "
                   "unattended installation."))
 
+        # Try to guess to language and keyboard layout from the system's
+        # language.
+        #
+        # This method has flows as it's quite common to have language and
+        # keyboard layout not matching. Otherwise, there's no easy way to guess
+        # the keyboard layout without relying on a set of APIs of an specific
+        # Desktop Environment.
+        language = get_language()
+        if language:
+            config.set_l10n_language(language)
+            config.set_l10n_keyboard(language)
+        else:
+            logging.warning(
+                _("'en_US' will be used as both language and keyboard layout "
+                  "for unattended installation."))
+
         logging.debug("InstallScriptConfig created with the following params:")
         logging.debug("username: %s", config.get_user_login())
         logging.debug("realname: %s", config.get_user_realname())
@@ -630,6 +652,8 @@ class _OsVariant(object):
         logging.debug("hardware arch: %s", config.get_hardware_arch())
         logging.debug("hostname: %s", config.get_hostname())
         logging.debug("timezone: %s", config.get_l10n_timezone())
+        logging.debug("language: %s", config.get_l10n_language())
+        logging.debug("keyboard: %s", config.get_l10n_keyboard())
 
         return config
 
-- 
2.20.1




More information about the virt-tools-list mailing list