Exemplo n.º 1
0
def initialize_locale(opts, text_mode):
    """Initialize locale.

    :param opts: the command line/boot options
    :param text_mode: is the locale being set up for the text mode?
    """
    from pyanaconda import localization

    locale_option = None
    localization_proxy = None

    if is_module_available(LOCALIZATION):
        localization_proxy = LOCALIZATION.get_proxy()

        # If the language was set on the command line, copy that to kickstart
        if opts.lang:
            localization_proxy.SetLanguage(opts.lang)
            localization_proxy.SetLanguageKickstarted(True)

        # Setup the locale environment
        if localization_proxy.LanguageKickstarted:
            locale_option = localization_proxy.Language

    localization.setup_locale_environment(locale_option, text_mode=text_mode)

    # Now that LANG is set, do something with it
    localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=text_mode)
Exemplo n.º 2
0
    def test_setup_locale_environment_fallback_efi_bad(self, open_mock):
        """Test setup_locale_environment() fallback to EFI vars with bad contents"""
        # failure with invalid data - too short
        open_mock.return_value = StringIO("\x00")

        localization.setup_locale_environment(None)

        self.assertEqual(DEFAULT_LANG, localization.os.environ["LANG"])
Exemplo n.º 3
0
 def _setup_locale(self):
     log.debug("setting up locale")
     # Normalize the locale environment variables
     if self.data.lang.seen:
         locale_arg = self.data.lang.lang
     else:
         locale_arg = None
     setup_locale_environment(locale_arg, prefer_environment=True)
     setup_locale(os.environ['LANG'], text_mode=not self.gui_mode)
Exemplo n.º 4
0
 def _setup_locale(self):
     log.debug("setting up locale")
     # Normalize the locale environment variables
     if self.data.lang.seen:
         locale_arg = self.data.lang.lang
     else:
         locale_arg = None
     setup_locale_environment(locale_arg, prefer_environment=True)
     setup_locale(os.environ['LANG'], text_mode=not self.gui_mode)
Exemplo n.º 5
0
    def test_setup_locale_environment_fallback_efi_ok(self, open_mock):
        """Test setup_locale_environment() fallback to EFI vars"""
        # success with valid data
        # first 4 bytes binary attributes, then language with - instead of _, minimum 10 bytes
        open_mock.return_value = StringIO("\x07\x00\x00\x00de-DE\x00")
        localization.os.environ.clear()

        localization.setup_locale_environment(None)

        self.assertTrue(open_mock.called)
        self.assertIn("de", localization.os.environ["LANG"])
Exemplo n.º 6
0
    def _setup_locale(self):
        log.debug("setting up locale")

        localization_proxy = LOCALIZATION.get_proxy()

        # Normalize the locale environment variables
        if localization_proxy.Kickstarted:
            locale_arg = localization_proxy.Language
        else:
            locale_arg = None
        setup_locale_environment(locale_arg, prefer_environment=True)
        setup_locale(os.environ['LANG'], text_mode=not self.gui_mode)
Exemplo n.º 7
0
    def test_setup_locale_environment_vars(self):
        """Test setup_locale_environment() with multiple environment variables"""
        for varname in ("LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG"):

            localization.os.environ.clear()
            localization.os.environ[varname] = "ko"

            localization.setup_locale_environment(None)

            self.assertEqual("ko_KR.UTF-8", localization.os.environ["LANG"])
            if varname != "LANG":
                self.assertNotIn(varname, localization.os.environ)
Exemplo n.º 8
0
    def test_setup_locale_environment_vars(self):
        """Test setup_locale_environment() with multiple environment variables"""
        for varname in ("LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG"):

            localization.os.environ.clear()
            localization.os.environ[varname] = "ko"

            localization.setup_locale_environment(None)

            assert "ko_KR.UTF-8" == localization.os.environ["LANG"]
            if varname != "LANG":
                assert varname not in localization.os.environ
Exemplo n.º 9
0
    def test_setup_locale_environment_param_ok(self, locales_mock):
        """Test setup_locale_environment() with parameter"""
        # success case
        locales_mock.return_value = ["fr_FR.UTF-8"]

        localization.setup_locale_environment("fr")

        self.assertEqual("fr_FR.UTF-8", localization.os.environ["LANG"])
        self.assertNotIn("LANGUAGE", localization.os.environ)
        self.assertNotIn("LC_MESSAGES", localization.os.environ)
        self.assertNotIn("LC_ALL", localization.os.environ)

        # mock a failure
        locales_mock.return_value = []
        locales_mock.side_effect = localization.InvalidLocaleSpec

        localization.setup_locale_environment("iu")

        self.assertIn(DEFAULT_LANG, localization.os.environ["LANG"])
Exemplo n.º 10
0
    def test_setup_locale_environment_param_ok(self, locales_mock):
        """Test setup_locale_environment() with parameter"""
        # success case
        locales_mock.return_value = ["fr_FR.UTF-8"]

        localization.setup_locale_environment("fr")

        assert "fr_FR.UTF-8" == localization.os.environ["LANG"]
        assert "LANGUAGE" not in localization.os.environ
        assert "LC_MESSAGES" not in localization.os.environ
        assert "LC_ALL" not in localization.os.environ

        # mock a failure
        locales_mock.return_value = []
        locales_mock.side_effect = localization.InvalidLocaleSpec

        localization.setup_locale_environment("iu")

        assert DEFAULT_LANG in localization.os.environ["LANG"]
Exemplo n.º 11
0
    def test_setup_locale_environment_vars_invalid(self):
        """Test setup_locale_environment() with invalid environment variable input"""
        localization.setup_locale_environment(None)

        self.assertEqual(DEFAULT_LANG, localization.os.environ["LANG"])
Exemplo n.º 12
0
    # Set the language before loading an interface, when it may be too late.

    from pyanaconda.modules.common.constants.services import LOCALIZATION
    localization_proxy = LOCALIZATION.get_proxy()

    # If the language was set on the command line, copy that to kickstart
    if opts.lang:
        localization_proxy.SetLanguage(opts.lang)
        localization_proxy.SetLanguageKickstarted(True)

    # Setup the locale environment
    if localization_proxy.LanguageKickstarted:
        locale_option = localization_proxy.Language
    else:
        locale_option = None
    localization.setup_locale_environment(locale_option,
                                          text_mode=anaconda.tui_mode)

    # Now that LANG is set, do something with it
    localization.setup_locale(os.environ["LANG"],
                              localization_proxy,
                              text_mode=anaconda.tui_mode)

    from pyanaconda.storage.initialization import enable_installer_mode, reset_storage
    enable_installer_mode()

    # Initialize the network now, in case the display needs it
    from pyanaconda.network import initialize_network, wait_for_connecting_NM_thread, wait_for_connected_NM

    initialize_network()
    # If required by user, wait for connection before starting the installation.
    if opts.waitfornet:
Exemplo n.º 13
0
        ksdata.selinux.selinux = flags.selinux

    from pyanaconda import localization
    # Set the language before loading an interface, when it may be too late.

    # If the language was set on the command line, copy that to kickstart
    if opts.lang:
        ksdata.lang.lang = opts.lang
        ksdata.lang.seen = True

    # Setup the locale environment
    if ksdata.lang.seen:
        locale_option = ksdata.lang.lang
    else:
        locale_option = None
    localization.setup_locale_environment(locale_option,
                                          opts.display_mode != "g")

    # Now that LANG is set, do something with it
    localization.setup_locale(os.environ["LANG"], ksdata.lang,
                              opts.display_mode != "g")

    import blivet
    blivet.enable_installer_mode()

    # Initialize the network now, in case the display needs it
    from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread

    networkInitialize(ksdata)
    threadMgr.add(
        AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM,
                       target=wait_for_connecting_NM_thread,
Exemplo n.º 14
0
        ksdata.selinux.selinux = flags.selinux

    from pyanaconda import localization
    # Set the language before loading an interface, when it may be too late.

    # If the language was set on the command line, copy that to kickstart
    if opts.lang:
        ksdata.lang.lang = opts.lang
        ksdata.lang.seen = True

    # Setup the locale environment
    if ksdata.lang.seen:
        locale_option = ksdata.lang.lang
    else:
        locale_option = None
    localization.setup_locale_environment(locale_option, opts.display_mode != "g")

    # Now that LANG is set, do something with it
    localization.setup_locale(os.environ["LANG"], ksdata.lang, opts.display_mode != "g")

    import blivet
    blivet.enable_installer_mode()

    # Initialize the network now, in case the display needs it
    from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread

    networkInitialize(ksdata)
    threadMgr.add(AnacondaThread(name=constants.THREAD_WAIT_FOR_CONNECTING_NM, target=wait_for_connecting_NM_thread, args=(ksdata,)))

    # now start the interface
    setupDisplay(anaconda, opts, addon_paths)
Exemplo n.º 15
0
    # Set the language before loading an interface, when it may be too late.

    from pyanaconda.modules.common.constants.services import LOCALIZATION
    localization_proxy = LOCALIZATION.get_proxy()

    # If the language was set on the command line, copy that to kickstart
    if opts.lang:
        localization_proxy.SetLanguage(opts.lang)
        localization_proxy.SetLanguageKickstarted(True)

    # Setup the locale environment
    if localization_proxy.LanguageKickstarted:
        locale_option = localization_proxy.Language
    else:
        locale_option = None
    localization.setup_locale_environment(locale_option, text_mode=anaconda.tui_mode)

    # Now that LANG is set, do something with it
    localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=anaconda.tui_mode)

    from pyanaconda.storage.osinstall import storage_initialize, enable_installer_mode
    enable_installer_mode()

    # Initialize the network now, in case the display needs it
    from pyanaconda.network import networkInitialize, wait_for_connecting_NM_thread, wait_for_connected_NM

    networkInitialize(ksdata)
    # If required by user, wait for connection before starting the installation.
    if opts.waitfornet:
        log.info("network: waiting for connectivity requested by inst.waitfornet=%d", opts.waitfornet)
        wait_for_connected_NM(timeout=opts.waitfornet)
Exemplo n.º 16
0
    log.info("kickstart parsing done")
except pykickstart.errors.KickstartError as kserr:
    log.exception("kickstart parsing failed: %s" % kserr)
    sys.exit(1)

if external_reconfig:
    # set the reconfig flag in kickstart so that
    # relevant spokes show up
    data.firstboot.firstboot = FIRSTBOOT_RECONFIG

# Normalize the locale environment variables
if data.lang.seen:
    locale_arg = data.lang.lang
else:
    locale_arg = None
setup_locale_environment(locale_arg, prefer_environment=True)
setup_locale(os.environ['LANG'], text_mode=mode != "gui")

if mode == "gui":
    try:
        # Try to import IS gui specifics
        log.debug("trying to import GUI")
        import initial_setup.gui
    except ImportError:
        log.exception("GUI import failed, falling back to TUI")
        mode = "tui"

if mode == "gui":
    # gui already imported (see above)

    # Add addons to search paths