Exemple #1
0
    def mount_root(self):
        """Mounts selected root and runs scripts."""
        # mount root fs
        try:
            mount_existing_system(self._storage.fsset,
                                  self.root.device,
                                  read_only=self.ro)
            log.info("System has been mounted under: %s", util.getSysroot())
        except StorageError as e:
            log.error("Mounting system under %s failed: %s", util.getSysroot(),
                      e)
            self.status = RescueModeStatus.MOUNT_FAILED
            return False

        # turn on swap
        if not flags.imageInstall or not self.ro:
            try:
                self._storage.turn_on_swap()
            except StorageError:
                log.error("Error enabling swap.")

        # turn on selinux also
        if flags.selinux:
            # we have to catch the possible exception, because we
            # support read-only mounting
            try:
                fd = open("%s/.autorelabel" % util.getSysroot(), "w+")
                fd.close()
            except IOError as e:
                log.warning("Error turning on selinux: %s", e)

        # set a libpath to use mounted fs
        libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":")
        mounted = ["/mnt/sysimage%s" % ldir for ldir in libdirs]
        util.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted))

        # do we have bash?
        try:
            if os.access("/usr/bin/bash", os.R_OK):
                os.symlink("/usr/bin/bash", "/bin/bash")
        except OSError as e:
            log.error("Error symlinking bash: %s", e)

        # make resolv.conf in chroot
        if not self.ro:
            self._storage.make_mtab()
            try:
                makeResolvConf(util.getSysroot())
            except (OSError, IOError) as e:
                log.error("Error making resolv.conf: %s", e)

        # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs
        makeFStab()

        # run %post if we've mounted everything
        if not self.ro and self._scripts:
            runPostScripts(self._scripts)

        self.status = RescueModeStatus.MOUNTED
        return True
Exemple #2
0
    def mount_root(self, root):
        """Mounts selected root and runs scripts."""
        # mount root fs
        try:
            mount_existing_system(self._storage.fsset, root.device, read_only=self.ro)
            log.info("System has been mounted under: %s", util.getSysroot())
        except StorageError as e:
            log.error("Mounting system under %s failed: %s", util.getSysroot(), e)
            self.status = RescueModeStatus.MOUNT_FAILED
            return False

        # turn on swap
        if not conf.target.is_image or not self.ro:
            try:
                self._storage.turn_on_swap()
            except StorageError:
                log.error("Error enabling swap.")

        # turn on selinux also
        if conf.security.selinux:
            # we have to catch the possible exception, because we
            # support read-only mounting
            try:
                fd = open("%s/.autorelabel" % util.getSysroot(), "w+")
                fd.close()
            except IOError as e:
                log.warning("Error turning on selinux: %s", e)

        # set a libpath to use mounted fs
        libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":")
        mounted = ["/mnt/sysimage%s" % ldir for ldir in libdirs]
        util.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted))

        # do we have bash?
        try:
            if os.access("/usr/bin/bash", os.R_OK):
                os.symlink("/usr/bin/bash", "/bin/bash")
        except OSError as e:
            log.error("Error symlinking bash: %s", e)

        # make resolv.conf in chroot
        if not self.ro:
            self._storage.make_mtab()
            try:
                makeResolvConf(util.getSysroot())
            except(OSError, IOError) as e:
                log.error("Error making resolv.conf: %s", e)

        # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs
        makeFStab()

        # run %post if we've mounted everything
        if not self.ro and self._scripts:
            runPostScripts(self._scripts)

        self.status = RescueModeStatus.MOUNTED
        return True
Exemple #3
0
    def mount_root(self, root):
        """Mounts selected root and runs scripts."""
        # mount root fs
        try:
            task_path = self._device_tree_proxy.MountExistingSystemWithTask(
                root.get_root_device(),
                self.ro
            )
            task_proxy = STORAGE.get_proxy(task_path)
            sync_run_task(task_proxy)
            log.info("System has been mounted under: %s", conf.target.system_root)
        except MountFilesystemError as e:
            log.error("Mounting system under %s failed: %s", conf.target.system_root, e)
            self.status = RescueModeStatus.MOUNT_FAILED
            self.error = e
            return False

        # turn on selinux also
        if conf.security.selinux:
            # we have to catch the possible exception, because we
            # support read-only mounting
            try:
                fd = open("%s/.autorelabel" % conf.target.system_root, "w+")
                fd.close()
            except IOError as e:
                log.warning("Error turning on selinux: %s", e)

        # set a libpath to use mounted fs
        libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":")
        mounted = ["/mnt/sysimage%s" % ldir for ldir in libdirs]
        util.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted))

        # do we have bash?
        try:
            if os.access("/usr/bin/bash", os.R_OK):
                os.symlink("/usr/bin/bash", "/bin/bash")
        except OSError as e:
            log.error("Error symlinking bash: %s", e)

        # make resolv.conf in chroot
        if not self.ro:
            try:
                makeResolvConf(conf.target.system_root)
            except(OSError, IOError) as e:
                log.error("Error making resolv.conf: %s", e)

        # create /etc/fstab in ramdisk so it's easier to work with RO mounted fs
        makeFStab()

        # run %post if we've mounted everything
        if not self.ro and self._scripts:
            runPostScripts(self._scripts)

        self.status = RescueModeStatus.MOUNTED
        return True
Exemple #4
0
    def _widgetScale(self):
        # First, check if the GDK_SCALE environment variable is already set. If so,
        # leave it alone.
        if "GDK_SCALE" in os.environ:
            log.debug("GDK_SCALE already set to %s, not scaling",
                      os.environ["GDK_SCALE"])
            return

        # Next, check if a scaling factor is already being applied via XSETTINGS,
        # such as by gnome-settings-daemon
        display = Gdk.Display.get_default()
        screen = display.get_default_screen()
        val = GObject.Value()
        val.init(GObject.TYPE_INT)
        if screen.get_setting("gdk-window-scaling-factor", val):
            log.debug("Window scale set to %s by XSETTINGS, not scaling",
                      val.get_int())
            return

        # Get the primary monitor dimensions in pixels and mm from Gdk
        primary_monitor = display.get_primary_monitor()

        # It can be None if no primary monitor is configured by the user.
        if not primary_monitor:
            return

        monitor_geometry = primary_monitor.get_geometry()
        monitor_scale = primary_monitor.get_scale_factor()
        monitor_width_mm = primary_monitor.get_width_mm()
        monitor_height_mm = primary_monitor.get_height_mm()

        # Sometimes gdk returns 0 for physical widths and heights
        if monitor_height_mm == 0 or monitor_width_mm == 0:
            return

        # Check if this monitor is high DPI, using heuristics from gnome-settings-dpi.
        # If the monitor has a height >= 1200 pixels and a resolution > 192 dpi in both
        # x and y directions, apply a scaling factor of 2 so that anaconda isn't all tiny
        monitor_width_px = monitor_geometry.width * monitor_scale
        monitor_height_px = monitor_geometry.height * monitor_scale
        monitor_dpi_x = monitor_width_px / (monitor_width_mm / 25.4)
        monitor_dpi_y = monitor_height_px / (monitor_height_mm / 25.4)

        log.debug("Detected primary monitor: %dx%d %ddpix %ddpiy",
                  monitor_width_px, monitor_height_px, monitor_dpi_x,
                  monitor_dpi_y)
        if monitor_height_px >= 1200 and monitor_dpi_x > 192 and monitor_dpi_y > 192:
            display.set_window_scale(2)
            # Export the scale so that Gtk programs launched by anaconda are also scaled
            util.setenv("GDK_SCALE", "2")
Exemple #5
0
    def set_locale(self, locale):
        """Set the locale for the module.

        This function modifies the process environment, which is not thread-safe.
        It should be called before any threads are run.

        We cannot get around setting $LANG. Python's gettext implementation
        differs from C in that consults only the environment for the current
        language and not the data set via setlocale. If we want translations
        from python modules to work, something needs to be set in the
        environment when the language changes.

        :param str locale: locale to set
        """
        os.environ["LANG"] = locale  # pylint: disable=environment-modify
        setlocale(LC_ALL, locale)
        # Set locale for child processes
        setenv("LANG", locale)
        log.debug("Locale is set to %s.", locale)
Exemple #6
0
    def _widgetScale(self):
        # First, check if the GDK_SCALE environment variable is already set. If so,
        # leave it alone.
        if "GDK_SCALE" in os.environ:
            log.debug("GDK_SCALE already set to %s, not scaling", os.environ["GDK_SCALE"])
            return

        # Next, check if a scaling factor is already being applied via XSETTINGS,
        # such as by gnome-settings-daemon
        display = Gdk.Display.get_default()
        screen = display.get_default_screen()
        val = GObject.Value()
        val.init(GObject.TYPE_INT)
        if screen.get_setting("gdk-window-scaling-factor", val):
            log.debug("Window scale set to %s by XSETTINGS, not scaling", val.get_int())
            return

        # Get the primary monitor dimensions in pixels and mm from Gdk
        primary_monitor = display.get_primary_monitor()
        monitor_geometry = primary_monitor.get_geometry()
        monitor_scale = primary_monitor.get_scale_factor()
        monitor_width_mm = primary_monitor.get_width_mm()
        monitor_height_mm = primary_monitor.get_height_mm()

        # Sometimes gdk returns 0 for physical widths and heights
        if monitor_height_mm == 0 or monitor_width_mm == 0:
            return

        # Check if this monitor is high DPI, using heuristics from gnome-settings-dpi.
        # If the monitor has a height >= 1200 pixels and a resolution > 192 dpi in both
        # x and y directions, apply a scaling factor of 2 so that anaconda isn't all tiny
        monitor_width_px = monitor_geometry.width * monitor_scale
        monitor_height_px = monitor_geometry.height * monitor_scale
        monitor_dpi_x = monitor_width_px / (monitor_width_mm / 25.4)
        monitor_dpi_y = monitor_height_px / (monitor_height_mm / 25.4)

        log.debug("Detected primary monitor: %dx%d %ddpix %ddpiy", monitor_width_px,
                monitor_height_px, monitor_dpi_x, monitor_dpi_y)
        if monitor_height_px >= 1200 and monitor_dpi_x > 192 and monitor_dpi_y > 192:
            display.set_window_scale(2)
            # Export the scale so that Gtk programs launched by anaconda are also scaled
            util.setenv("GDK_SCALE", "2")
Exemple #7
0
def setup_locale(locale, localization_proxy=None, text_mode=False):
    """
    Procedure setting the system to use the given locale and store it in to the
    localization module (if given). DOES NOT PERFORM ANY CHECKS OF THE GIVEN
    LOCALE.

    $LANG must be set by the caller in order to set the language used by gettext.
    Doing this in a thread-safe way is up to the caller.

    We also try to set a proper console font for the locale in text mode.
    If the font for the locale can't be displayed in the Linux console,
    we fall back to the English locale.

    This function returns the locale that was used in the setlocale call, which,
    depending on what the environment and interface is able to support, may be
    different from the locale requested.

    :param str locale: locale to setup
    :param localization_proxy: DBus proxy of the localization module or None
    :param bool text_mode: if the locale is being setup for text mode
    :return: the locale that was actually set
    :rtype: str

    """

    if localization_proxy:
        localization_proxy.SetLanguage(locale)

    # not all locales might be displayable in text mode
    if text_mode:
        # check if the script corresponding to the locale/language
        # can be displayed by the Linux console
        # * all scripts for the given locale/language need to be
        #   supported by the linux console
        # * otherwise users might get a screen full of white rectangles
        #   (also known as "tofu") in text mode
        # then we also need to check if we have information about what
        # font to use for correctly displaying the given language/locale

        script_supported = locale_supported_in_console(locale)
        log.debug("scripts found for locale %s: %s", locale, get_locale_scripts(locale))

        console_fonts = get_locale_console_fonts(locale)
        log.debug("console fonts found for locale %s: %s", locale, console_fonts)

        font_set = False
        if script_supported and console_fonts:
            # try to set console font
            for font in console_fonts:
                if set_console_font(font):
                    # console font set successfully, skip the rest
                    font_set = True
                    break

        if not font_set:
            log.warning("can't set console font for locale %s", locale)
            # report what exactly went wrong
            if not(script_supported):
                log.warning("script not supported by console for locale %s", locale)
            if not(console_fonts):  # no fonts known for locale
                log.warning("no console font found for locale %s", locale)
            if script_supported and console_fonts:
                log.warning("none of the suggested fonts can be set for locale %s", locale)
            log.warning("falling back to the English locale")
            locale = constants.DEFAULT_LANG
            os.environ["LANG"] = locale  # pylint: disable=environment-modify

    # set the locale to the value we have selected
    # Since glibc does not install all locales, an installable locale may not
    # actually be available right now. Give it a shot and fallback.
    log.debug("setting locale to: %s", locale)
    setenv("LANG", locale)

    try:
        locale_mod.setlocale(locale_mod.LC_ALL, locale)
    except locale_mod.Error as e:
        log.debug("setlocale failed: %s", e)
        locale = constants.DEFAULT_LANG
        setenv("LANG", locale)
        locale_mod.setlocale(locale_mod.LC_ALL, locale)

    # This part is pretty gross:
    # In python3, sys.stdout and friends are TextIOWrapper objects that translate
    # betwen str types (in python) and byte types (used to actually read from or
    # write to the console). These wrappers are configured at startup using the
    # locale at startup, which means that if anaconda starts with LANG=C or LANG
    # unset, sys.stdout.encoding will be "ascii". And if the language is then changed,
    # because anaconda read the kickstart or parsed the command line or whatever,
    # say, to Czech, text mode will crash because it's going to try to print non-ASCII
    # characters and sys.stdout doesn't know what to do with them. So, when changing
    # the locale, create new objects for the standard streams so they are created with
    # the new locale's encoding.

    # Replacing stdout is about as stable as it looks, and it seems to break when done
    # after the GUI is started. Only make the switch if the encoding actually changed.
    if locale_mod.getpreferredencoding() != sys.stdout.encoding:
        sys.stdin = io.TextIOWrapper(sys.stdin.detach())
        sys.stdout = io.TextIOWrapper(sys.stdout.detach())
        sys.stderr = io.TextIOWrapper(sys.stderr.detach())

    return locale
Exemple #8
0
    # cmdline flags override kickstart settings
    if anaconda.proxy:

        if hasattr(ksdata.method, "proxy"):
            ksdata.method.proxy = anaconda.proxy

        # Setup proxy environmental variables so that pre/post scripts use it
        # as well as libreport
        try:
            proxy = ProxyString(anaconda.proxy)
        except ProxyStringError as e:
            log.info("Failed to parse proxy \"%s\": %s", anaconda.proxy, e)
        else:
            # Set environmental variables to be used by pre/post scripts
            util.setenv("PROXY", proxy.noauth_url)
            util.setenv("PROXY_USER", proxy.username or "")
            util.setenv("PROXY_PASSWORD", proxy.password or "")

            # Variables used by curl, libreport, etc.
            util.setenv("http_proxy", proxy.url)
            util.setenv("ftp_proxy", proxy.url)
            util.setenv("HTTPS_PROXY", proxy.url)

    if not conf.payload.verify_ssl and hasattr(ksdata.method, "noverifyssl"):
        ksdata.method.noverifyssl = not conf.payload.verify_ssl
    if opts.multiLib:
        # sets dnf's multilib_policy to "all" (as opposed to "best")
        ksdata.packages.multiLib = opts.multiLib

    # set ksdata.method based on anaconda.method if it isn't already set
Exemple #9
0
def setup_locale(locale, localization_proxy=None, text_mode=False):
    """Procedure setting the system to use the given locale and store it in to the
    localization module (if given). DOES NOT PERFORM ANY CHECKS OF THE GIVEN
    LOCALE.

    $LANG must be set by the caller in order to set the language used by gettext.
    Doing this in a thread-safe way is up to the caller.

    We also try to set a proper console font for the locale in text mode.
    If the font for the locale can't be displayed in the Linux console,
    we fall back to the English locale.

    This function returns the locale that was used in the setlocale call, which,
    depending on what the environment and interface is able to support, may be
    different from the locale requested.

    :param str locale: locale to setup
    :param localization_proxy: DBus proxy of the localization module or None
    :param bool text_mode: if the locale is being setup for text mode
    :return: the locale that was actually set
    :rtype: str
    """
    if localization_proxy:
        localization_proxy.SetLanguage(locale)

    # not all locales might be displayable in text mode
    if text_mode:
        # check if the script corresponding to the locale/language
        # can be displayed by the Linux console
        # * all scripts for the given locale/language need to be
        #   supported by the linux console
        # * otherwise users might get a screen full of white rectangles
        #   (also known as "tofu") in text mode
        # then we also need to check if we have information about what
        # font to use for correctly displaying the given language/locale

        script_supported = locale_supported_in_console(locale)
        log.debug("scripts found for locale %s: %s", locale,
                  get_locale_scripts(locale))

        console_fonts = get_locale_console_fonts(locale)
        log.debug("console fonts found for locale %s: %s", locale,
                  console_fonts)

        font_set = False
        if script_supported and console_fonts:
            # try to set console font
            for font in console_fonts:
                if set_console_font(font):
                    # console font set successfully, skip the rest
                    font_set = True
                    break

        if not font_set:
            log.warning("can't set console font for locale %s", locale)
            # report what exactly went wrong
            if not script_supported:
                log.warning("script not supported by console for locale %s",
                            locale)
            if not console_fonts:  # no fonts known for locale
                log.warning("no console font found for locale %s", locale)
            if script_supported and console_fonts:
                log.warning(
                    "none of the suggested fonts can be set for locale %s",
                    locale)
            log.warning("falling back to the English locale")
            locale = constants.DEFAULT_LANG
            os.environ["LANG"] = locale  # pylint: disable=environment-modify

    # set the locale to the value we have selected
    # Since glibc does not install all locales, an installable locale may not
    # actually be available right now. Give it a shot and fallback.
    log.debug("setting locale to: %s", locale)
    setenv("LANG", locale)

    try:
        locale_mod.setlocale(locale_mod.LC_ALL, locale)
    except locale_mod.Error as e:
        log.debug("setlocale failed: %s", e)
        locale = constants.DEFAULT_LANG
        setenv("LANG", locale)
        locale_mod.setlocale(locale_mod.LC_ALL, locale)

    set_modules_locale(locale)

    return locale
def set_up_proxy_variables(proxy):
    """Set up proxy environmental variables.

    Set up proxy environmental variables so that %pre and %post
    scripts can use it as well as curl, libreport, etc.

    :param proxy: a string with the proxy URL
    """
    if not proxy:
        log.debug("Don't set up proxy variables.")
        return

    try:
        proxy = ProxyString(proxy)
    except ProxyStringError as e:
        log.info("Failed to parse proxy \"%s\": %s", proxy, e)
    else:
        # Set environmental variables to be used by pre/post scripts
        util.setenv("PROXY", proxy.noauth_url)
        util.setenv("PROXY_USER", proxy.username or "")
        util.setenv("PROXY_PASSWORD", proxy.password or "")

        # Variables used by curl, libreport, etc.
        util.setenv("http_proxy", proxy.url)
        util.setenv("ftp_proxy", proxy.url)
        util.setenv("HTTPS_PROXY", proxy.url)
Exemple #11
0
def setup_locale(locale, lang=None, text_mode=False):
    """
    Procedure setting the system to use the given locale and store it in to the
    ksdata.lang object (if given). DOES NOT PERFORM ANY CHECKS OF THE GIVEN
    LOCALE.

    $LANG must be set by the caller in order to set the language used by gettext.
    Doing this in a thread-safe way is up to the caller.

    We also try to set a proper console font for the locale in text mode.
    If the font for the locale can't be displayed in the Linux console,
    we fall back to the English locale.

    This function returns the locale that was used in the setlocale call, which,
    depending on what the environment and interface is able to support, may be
    different from the locale requested.

    :param str locale: locale to setup
    :param lang: ksdata.lang object or None
    :param bool text_mode: if the locale is being setup for text mode
    :return: the locale that was actually set
    :rtype: str

    """

    if lang:
        lang.lang = locale

    # not all locales might be displayable in text mode
    if text_mode:
        # check if the script corresponding to the locale/language
        # can be displayed by the Linux console
        # * all scripts for the given locale/language need to be
        #   supported by the linux console
        # * otherwise users might get a screen full of white rectangles
        #   (also known as "tofu") in text mode
        # then we also need to check if we have information about what
        # font to use for correctly displaying the given language/locale

        script_supported = locale_supported_in_console(locale)
        log.debug("scripts found for locale %s: %s", locale, get_locale_scripts(locale))

        console_fonts = get_locale_console_fonts(locale)
        log.debug("console fonts found for locale %s: %s", locale, console_fonts)

        font_set = False
        if script_supported and console_fonts:
            # try to set console font
            for font in console_fonts:
                if set_console_font(font):
                    # console font set successfully, skip the rest
                    font_set = True
                    break

        if not font_set:
            log.warning("can't set console font for locale %s", locale)
            # report what exactly went wrong
            if not(script_supported):
                log.warning("script not supported by console for locale %s", locale)
            if not(console_fonts):  # no fonts known for locale
                log.warning("no console font found for locale %s", locale)
            if script_supported and console_fonts:
                log.warning("none of the suggested fonts can be set for locale %s", locale)
            log.warning("falling back to the English locale")
            locale = constants.DEFAULT_LANG
            os.environ["LANG"] = locale  # pylint: disable=environment-modify

    # set the locale to the value we have selected
    # Since glibc does not install all locales, an installable locale may not
    # actually be available right now. Give it a shot and fallback.
    log.debug("setting locale to: %s", locale)
    setenv("LANG", locale)

    try:
        locale_mod.setlocale(locale_mod.LC_ALL, locale)
    except locale_mod.Error as e:
        log.debug("setlocale failed: %s", e)
        locale = constants.DEFAULT_LANG
        setenv("LANG", locale)
        locale_mod.setlocale(locale_mod.LC_ALL, locale)

    # This part is pretty gross:
    # In python3, sys.stdout and friends are TextIOWrapper objects that translate
    # betwen str types (in python) and byte types (used to actually read from or
    # write to the console). These wrappers are configured at startup using the
    # locale at startup, which means that if anaconda starts with LANG=C or LANG
    # unset, sys.stdout.encoding will be "ascii". And if the language is then changed,
    # because anaconda read the kickstart or parsed the command line or whatever,
    # say, to Czech, text mode will crash because it's going to try to print non-ASCII
    # characters and sys.stdout doesn't know what to do with them. So, when changing
    # the locale, create new objects for the standard streams so they are created with
    # the new locale's encoding.

    # Replacing stdout is about as stable as it looks, and it seems to break when done
    # after the GUI is started. Only make the switch if the encoding actually changed.
    if locale_mod.getpreferredencoding() != sys.stdout.encoding:
        sys.stdin = io.TextIOWrapper(sys.stdin.detach())
        sys.stdout = io.TextIOWrapper(sys.stdout.detach())
        sys.stderr = io.TextIOWrapper(sys.stderr.detach())

    return locale
Exemple #12
0
def setup_locale(locale, localization_proxy=None, text_mode=False):
    """
    Procedure setting the system to use the given locale and store it in to the
    localization module (if given). DOES NOT PERFORM ANY CHECKS OF THE GIVEN
    LOCALE.

    $LANG must be set by the caller in order to set the language used by gettext.
    Doing this in a thread-safe way is up to the caller.

    We also try to set a proper console font for the locale in text mode.
    If the font for the locale can't be displayed in the Linux console,
    we fall back to the English locale.

    This function returns the locale that was used in the setlocale call, which,
    depending on what the environment and interface is able to support, may be
    different from the locale requested.

    :param str locale: locale to setup
    :param localization_proxy: DBus proxy of the localization module or None
    :param bool text_mode: if the locale is being setup for text mode
    :return: the locale that was actually set
    :rtype: str

    """

    if localization_proxy:
        localization_proxy.SetLanguage(locale)

    # not all locales might be displayable in text mode
    if text_mode:
        # check if the script corresponding to the locale/language
        # can be displayed by the Linux console
        # * all scripts for the given locale/language need to be
        #   supported by the linux console
        # * otherwise users might get a screen full of white rectangles
        #   (also known as "tofu") in text mode
        # then we also need to check if we have information about what
        # font to use for correctly displaying the given language/locale

        script_supported = locale_supported_in_console(locale)
        log.debug("scripts found for locale %s: %s", locale, get_locale_scripts(locale))

        console_fonts = get_locale_console_fonts(locale)
        log.debug("console fonts found for locale %s: %s", locale, console_fonts)

        font_set = False
        if script_supported and console_fonts:
            # try to set console font
            for font in console_fonts:
                if set_console_font(font):
                    # console font set successfully, skip the rest
                    font_set = True
                    break

        if not font_set:
            log.warning("can't set console font for locale %s", locale)
            # report what exactly went wrong
            if not(script_supported):
                log.warning("script not supported by console for locale %s", locale)
            if not(console_fonts):  # no fonts known for locale
                log.warning("no console font found for locale %s", locale)
            if script_supported and console_fonts:
                log.warning("none of the suggested fonts can be set for locale %s", locale)
            log.warning("falling back to the English locale")
            locale = constants.DEFAULT_LANG
            os.environ["LANG"] = locale  # pylint: disable=environment-modify

    # set the locale to the value we have selected
    # Since glibc does not install all locales, an installable locale may not
    # actually be available right now. Give it a shot and fallback.
    log.debug("setting locale to: %s", locale)
    setenv("LANG", locale)

    try:
        locale_mod.setlocale(locale_mod.LC_ALL, locale)
    except locale_mod.Error as e:
        log.debug("setlocale failed: %s", e)
        locale = constants.DEFAULT_LANG
        setenv("LANG", locale)
        locale_mod.setlocale(locale_mod.LC_ALL, locale)

    return locale
Exemple #13
0
    # cmdline flags override kickstart settings
    if anaconda.proxy:

        if hasattr(ksdata.method, "proxy"):
            ksdata.method.proxy = anaconda.proxy

        # Setup proxy environmental variables so that pre/post scripts use it
        # as well as libreport
        try:
            proxy = ProxyString(anaconda.proxy)
        except ProxyStringError as e:
            log.info("Failed to parse proxy \"%s\": %s", anaconda.proxy, e)
        else:
            # Set environmental variables to be used by pre/post scripts
            util.setenv("PROXY", proxy.noauth_url)
            util.setenv("PROXY_USER", proxy.username or "")
            util.setenv("PROXY_PASSWORD", proxy.password or "")

            # Variables used by curl, libreport, etc.
            util.setenv("http_proxy", proxy.url)
            util.setenv("ftp_proxy", proxy.url)
            util.setenv("HTTPS_PROXY", proxy.url)

    if flags.noverifyssl and hasattr(ksdata.method, "noverifyssl"):
        ksdata.method.noverifyssl = flags.noverifyssl
    if opts.multiLib:
        # sets dnf's multilib_policy to "all" (as opposed to "best")
        ksdata.packages.multiLib = opts.multiLib

    # set ksdata.method based on anaconda.method if it isn't already set