def setup_display(anaconda, options, addon_paths=None): """Setup the display for the installation environment. :param anaconda: instance of the Anaconda class :param options: command line/boot options :param addon_paths: Anaconda addon paths """ vnc_server = vnc.VncServer() # The vnc Server object. vnc_server.anaconda = anaconda anaconda.display_mode = options.display_mode anaconda.interactive_mode = not options.noninteractive anaconda.isHeadless = blivet.arch.is_s390() if options.vnc: flags.usevnc = True if not anaconda.gui_mode: log.info( "VNC requested via boot/CLI option, switching Anaconda to GUI mode." ) anaconda.display_mode = constants.DisplayModes.GUI vnc_server.password = options.vncpassword # Only consider vncconnect when vnc is a param if options.vncconnect: cargs = options.vncconnect.split(":") vnc_server.vncconnecthost = cargs[0] if len(cargs) > 1 and len(cargs[1]) > 0: if len(cargs[1]) > 0: vnc_server.vncconnectport = cargs[1] if options.xdriver: anaconda.xdriver = options.xdriver anaconda.writeXdriver(root="/") if flags.rescue_mode: return if anaconda.ksdata.vnc.enabled: flags.usevnc = True if not anaconda.gui_mode: log.info( "VNC requested via kickstart, switching Anaconda to GUI mode.") anaconda.display_mode = constants.DisplayModes.GUI if vnc_server.password == "": vnc_server.password = anaconda.ksdata.vnc.password if vnc_server.vncconnecthost == "": vnc_server.vncconnecthost = anaconda.ksdata.vnc.host if vnc_server.vncconnectport == "": vnc_server.vncconnectport = anaconda.ksdata.vnc.port if anaconda.gui_mode: mods = (tup[1] for tup in pkgutil.iter_modules(pyanaconda.ui.__path__, "pyanaconda.ui.")) if "pyanaconda.ui.gui" not in mods: stdout_log.warning( "Graphical user interface not available, falling back to text mode" ) anaconda.display_mode = constants.DisplayModes.TUI flags.usevnc = False flags.vncquestion = False # check if VNC can be started vnc_can_be_started, vnc_error_messages = check_vnc_can_be_started(anaconda) if not vnc_can_be_started: # VNC can't be started - disable the VNC question and log # all the errors that prevented VNC from being started flags.vncquestion = False for error_message in vnc_error_messages: stdout_log.warning(error_message) # Should we try to start Xorg? want_x = anaconda.gui_mode and not (flags.preexisting_x11 or flags.usevnc) # X on a headless (e.g. s390) system? Nonsense! if want_x and anaconda.isHeadless: stdout_log.warning(_("DISPLAY variable not set. Starting text mode.")) anaconda.display_mode = constants.DisplayModes.TUI anaconda.gui_startup_failed = True time.sleep(2) want_x = False # Is Xorg is actually available? if want_x and not os.access("/usr/bin/Xorg", os.X_OK): stdout_log.warning( _("Graphical installation is not available. " "Starting text mode.")) time.sleep(2) anaconda.display_mode = constants.DisplayModes.TUI want_x = False if anaconda.tui_mode and flags.vncquestion: #we prefer vnc over text mode, so ask about that message = _("Text mode provides a limited set of installation " "options. It does not offer custom partitioning for " "full control over the disk layout. Would you like " "to use VNC mode instead?") ask_vnc_question(anaconda, vnc_server, message) if not anaconda.ksdata.vnc.enabled: # user has explicitly specified text mode flags.vncquestion = False display_mode_name = anaconda.display_mode.value if display_mode_name: log.info("Display mode = %s", anaconda.display_mode) elif anaconda.display_mode: log.error("Unknown display mode: %s", anaconda.display_mode) else: log.error("Display mode not set!") startup_utils.check_memory(anaconda, options) # check_memory may have changed the display mode want_x = want_x and (anaconda.gui_mode) if want_x: try: start_x11() do_startup_x11_actions() except (OSError, RuntimeError) as e: log.warning("X startup failed: %s", e) stdout_log.warning("X startup failed, falling back to text mode") anaconda.display_mode = constants.DisplayModes.TUI anaconda.gui_startup_failed = True time.sleep(2) if not anaconda.gui_startup_failed: do_extra_x11_actions(options.runres, gui_mode=anaconda.gui_mode) if anaconda.tui_mode and anaconda.gui_startup_failed and flags.vncquestion and not anaconda.ksdata.vnc.enabled: message = _( "X was unable to start on your machine. Would you like to start VNC to connect to " "this computer from another computer and perform a graphical installation or continue " "with a text mode installation?") ask_vnc_question(anaconda, vnc_server, message) # if they want us to use VNC do that now if anaconda.gui_mode and flags.usevnc: vnc_server.startServer() do_startup_x11_actions() # with X running we can initialize the UI interface anaconda.initInterface(addon_paths=addon_paths) # and the install class anaconda.instClass.configure(anaconda)
def setup_display(anaconda, options): """Setup the display for the installation environment. :param anaconda: instance of the Anaconda class :param options: command line/boot options """ try: xtimeout = int(options.xtimeout) except ValueError: log.warning("invalid inst.xtimeout option value: %s", options.xtimeout) xtimeout = constants.X_TIMEOUT vnc_server = vnc.VncServer() # The vnc Server object. vnc_server.anaconda = anaconda vnc_server.timeout = xtimeout anaconda.display_mode = options.display_mode anaconda.interactive_mode = not options.noninteractive if options.vnc: flags.usevnc = True if not anaconda.gui_mode: log.info( "VNC requested via boot/CLI option, switching Anaconda to GUI mode." ) anaconda.display_mode = constants.DisplayModes.GUI vnc_server.password = options.vncpassword # Only consider vncconnect when vnc is a param if options.vncconnect: cargs = options.vncconnect.split(":") vnc_server.vncconnecthost = cargs[0] if len(cargs) > 1 and len(cargs[1]) > 0: if len(cargs[1]) > 0: vnc_server.vncconnectport = cargs[1] if options.xdriver: write_xdriver(options.xdriver, root="/") if flags.rescue_mode: return if anaconda.ksdata.vnc.enabled: flags.usevnc = True if not anaconda.gui_mode: log.info( "VNC requested via kickstart, switching Anaconda to GUI mode.") anaconda.display_mode = constants.DisplayModes.GUI if vnc_server.password == "": vnc_server.password = anaconda.ksdata.vnc.password if vnc_server.vncconnecthost == "": vnc_server.vncconnecthost = anaconda.ksdata.vnc.host if vnc_server.vncconnectport == "": vnc_server.vncconnectport = anaconda.ksdata.vnc.port if anaconda.gui_mode: mods = (tup[1] for tup in pkgutil.iter_modules(pyanaconda.ui.__path__, "pyanaconda.ui.")) if "pyanaconda.ui.gui" not in mods: stdout_log.warning( "Graphical user interface not available, falling back to text mode" ) anaconda.display_mode = constants.DisplayModes.TUI flags.usevnc = False flags.vncquestion = False # check if VNC can be started vnc_can_be_started, vnc_error_messages = check_vnc_can_be_started(anaconda) if not vnc_can_be_started: # VNC can't be started - disable the VNC question and log # all the errors that prevented VNC from being started flags.vncquestion = False for error_message in vnc_error_messages: stdout_log.warning(error_message) # Should we try to start Xorg? want_x = anaconda.gui_mode and not (flags.preexisting_x11 or flags.usevnc) # Is Xorg is actually available? if want_x and not os.access("/usr/bin/Xorg", os.X_OK): stdout_log.warning( _("Graphical installation is not available. " "Starting text mode.")) time.sleep(2) anaconda.display_mode = constants.DisplayModes.TUI want_x = False if anaconda.tui_mode and flags.vncquestion: # we prefer vnc over text mode, so ask about that message = _("Text mode provides a limited set of installation " "options. It does not offer custom partitioning for " "full control over the disk layout. Would you like " "to use VNC mode instead?") ask_vnc_question(anaconda, vnc_server, message) if not anaconda.ksdata.vnc.enabled: # user has explicitly specified text mode flags.vncquestion = False anaconda.log_display_mode() startup_utils.check_memory(anaconda, options) # check_memory may have changed the display mode want_x = want_x and (anaconda.gui_mode) if want_x: try: start_x11(xtimeout) do_startup_x11_actions() except TimeoutError as e: log.warning("X startup failed: %s", e) print( "\nX did not start in the expected time, falling back to text mode. There are " "multiple ways to avoid this issue:") wrapper = textwrap.TextWrapper( initial_indent=" * ", subsequent_indent=" ", width=os.get_terminal_size().columns - 3) for line in X_TIMEOUT_ADVICE.split("\n"): print(wrapper.fill(line)) util.vtActivate(1) anaconda.display_mode = constants.DisplayModes.TUI anaconda.gui_startup_failed = True time.sleep(2) except (OSError, RuntimeError) as e: log.warning("X or window manager startup failed: %s", e) print( "\nX or window manager startup failed, falling back to text mode." ) util.vtActivate(1) anaconda.display_mode = constants.DisplayModes.TUI anaconda.gui_startup_failed = True time.sleep(2) if not anaconda.gui_startup_failed: do_extra_x11_actions(options.runres, gui_mode=anaconda.gui_mode) if anaconda.tui_mode and anaconda.gui_startup_failed and flags.vncquestion and not anaconda.ksdata.vnc.enabled: message = _( "X was unable to start on your machine. Would you like to start VNC to connect to " "this computer from another computer and perform a graphical installation or continue " "with a text mode installation?") ask_vnc_question(anaconda, vnc_server, message) # if they want us to use VNC do that now if anaconda.gui_mode and flags.usevnc: vnc_server.startServer() do_startup_x11_actions() # with X running we can initialize the UI interface anaconda.initInterface()