def setUp(self):
        super().setUp()
        self.create_loop()
        App.initialize(event_loop=self.loop)

        self._callback_called = False
        self._callback_input = ""
Beispiel #2
0
def start_rescue_mode_ui(anaconda):
    """Start the rescue mode UI."""

    ksdata_rescue = None
    if anaconda.ksdata.rescue.seen:
        ksdata_rescue = anaconda.ksdata.rescue
    scripts = anaconda.ksdata.scripts
    storage = anaconda.storage
    reboot = True
    if conf.target.is_image:
        reboot = False
    if flags.automatedInstall and anaconda.ksdata.reboot.action not in [KS_REBOOT, KS_SHUTDOWN]:
        reboot = False

    rescue = Rescue(storage, ksdata_rescue, reboot, scripts)
    rescue.initialize()

    # We still want to choose from multiple roots, or unlock encrypted devices
    # if needed, so we run UI even for kickstarts (automated install).
    App.initialize()
    loop = App.get_event_loop()
    loop.set_quit_callback(tui_quit_callback)
    spoke = RescueModeSpoke(rescue)
    ScreenHandler.schedule_screen(spoke)
    App.run()
Beispiel #3
0
def start_rescue_mode_ui(anaconda):
    """Start the rescue mode UI."""

    ksdata_rescue = None
    if anaconda.ksdata.rescue.seen:
        ksdata_rescue = anaconda.ksdata.rescue
    scripts = anaconda.ksdata.scripts
    storage = anaconda.storage
    reboot = True
    if conf.target.is_image:
        reboot = False
    if flags.automatedInstall and anaconda.ksdata.reboot.action not in [
            KS_REBOOT, KS_SHUTDOWN
    ]:
        reboot = False

    rescue = Rescue(storage, ksdata_rescue, reboot, scripts)
    rescue.initialize()

    # We still want to choose from multiple roots, or unlock encrypted devices
    # if needed, so we run UI even for kickstarts (automated install).
    App.initialize()
    loop = App.get_event_loop()
    loop.set_quit_callback(tui_quit_callback)
    spoke = RescueModeSpoke(rescue)
    ScreenHandler.schedule_screen(spoke)
    App.run()
Beispiel #4
0
    def test_input_thread_manager_after_initialize(self):
        App.initialize()

        thread_mgr = InputThreadManager.get_instance()

        App.initialize()

        self.assertNotEqual(thread_mgr, InputThreadManager.get_instance())
    def test_no_separator_when_screen_setup_fails(self, stdout_mock):
        ui_screen = ScreenSetupFailMock()

        App.initialize()
        App.get_scheduler().schedule_screen(ui_screen)
        App.run()

        self.assertEqual("", stdout_mock.getvalue())
    def test_close_screen(self):
        screen = UIScreen()

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        # Program will quit in close_screen when stack is empty
        App.get_scheduler().schedule_screen(UIScreen())
        screen.close()
Beispiel #7
0
    def test_create_instance_with_custom_everything(self):
        event_loop = CustomEventLoop()
        App.initialize(event_loop=event_loop,
                       scheduler=CustomScreenScheduler(event_loop),
                       global_configuration=CustomGlobalConfiguration())

        self.assertTrue(isinstance(App.get_event_loop(), CustomEventLoop))
        self.assertTrue(isinstance(App.get_scheduler(), CustomScreenScheduler))
        self.assertTrue(isinstance(App.get_configuration(), CustomGlobalConfiguration))
    def test_basic_connect(self):
        connect_screen = UIScreen()

        App.initialize(scheduler=MagicMock())
        connect_screen.connect(SignalMock, self._callback)
        App.get_event_loop().enqueue_signal(SignalMock(self))
        App.get_event_loop().process_signals()

        self.assertTrue(self.callback_called)
    def test_width(self):
        self._check_default_width()

        App.initialize()
        App.get_configuration().width = 100
        self._check_default_width(100)

        App.initialize()
        self._check_default_width()
    def test_emit(self):
        connect_screen = UIScreen()

        App.initialize(scheduler=MagicMock())
        connect_screen.connect(TestSignal, self._callback)
        connect_screen.emit(TestSignal(self))
        App.get_event_loop().process_signals()

        self.assertTrue(self.callback_called)
Beispiel #11
0
    def test_widget_multiline(self, out_mock, in_mock):
        widget_text = "Testing output\n\n\nAgain..."
        screen = ScreenWithWidget(widget_text)

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        App.run()

        self.assertEqual(self._expected_output(widget_text), out_mock.getvalue())
Beispiel #12
0
    def test_draw_simple_widget(self, out_mock, in_mock):
        widget_text = "Test"
        screen = ScreenWithWidget(widget_text)

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        App.run()

        self.assertEqual(self._expected_output(widget_text), out_mock.getvalue())
    def test_create_signal(self):
        connect_screen = UIScreen()

        App.initialize(scheduler=MagicMock())
        signal = connect_screen.create_signal(TestSignal, priority=20)

        self.assertEqual(signal.priority, 20)
        self.assertTrue(isinstance(signal, TestSignal))
        # source is set by create_signal
        self.assertEqual(signal.source, connect_screen)
    def test_password_function(self):
        self._check_default_password_function()

        test_mock = MagicMock()
        App.initialize()
        App.get_configuration().password_function = test_mock
        self._check_default_password_function(test_mock)

        App.initialize()
        self._check_default_password_function()
    def test_connect_react_on_rendering(self, _):
        connect_test_screen = TestRenderConnectHandler()
        screen2 = EmptyScreen()

        App.initialize()
        App.get_scheduler().schedule_screen(connect_test_screen)
        App.get_scheduler().schedule_screen(screen2)
        App.run()

        self.assertTrue(connect_test_screen.callback_called)
Beispiel #16
0
    def test_widget_is_exactly_height_to_print(self, out_mock, in_mock):
        widget_text = ("Line\n" "Line2\n" "Line3\n" "Line4")
        # Screen height take into account also 2 lines for prompt
        screen = ScreenWithWidget(widget_text, height=6)

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        App.run()

        self.assertEqual(self._expected_output(widget_text, widget_height=6),
                         out_mock.getvalue())
    def test_screen_event_loop_processing_with_two_screens(self, _):
        first_screen = EmptyScreenMock()
        screen = EmptyScreenMock()

        App.initialize()
        App.get_scheduler().schedule_screen(first_screen)
        App.get_scheduler().schedule_screen(screen)
        App.run()

        self.assertTrue(first_screen)
        self.assertTrue(screen)
Beispiel #18
0
    def test_list_widget_input_processing(self, out_mock, in_mock):
        # call first container callback
        in_mock.return_value = "2"

        screen = ScreenWithListWidget(3)

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        App.run()

        self.assertEqual(1, screen.container_callback_input)
Beispiel #19
0
    def test_widget_too_high(self, out_mock, in_mock):
        in_mock.return_value = "\n"
        in_mock.side_effect = lambda: print('\n')

        widget_text = ("Line\n" "Line2\n" "Line3\n" "Line4\n" "Line5")
        # Screen height take into account also 2 lines for prompt
        screen = ScreenWithWidget(widget_text, height=6)

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        App.run()

        self.assertEqual(self._expected_output(widget_text, widget_height=6),
                         out_mock.getvalue())
Beispiel #20
0
    def setup(self, data):
        """Construct all the objects required to implement this interface.

        This method must be provided by all subclasses.
        """
        # Use GLib event loop for the Simpleline TUI
        loop = GLibEventLoop()
        App.initialize(event_loop=loop)

        loop.set_quit_callback(tui_quit_callback)
        scheduler = App.get_scheduler()
        scheduler.quit_screen = YesNoDialog(self.quitMessage)

        # tell python-meh it should use our raw_input
        meh_io_handler = meh.ui.text.IOHandler(
            in_func=self._get_meh_input_func)
        self._meh_interface.set_io_handler(meh_io_handler)

        # register handlers for various messages
        loop = App.get_event_loop()
        loop.register_signal_handler(ExceptionSignal, exception_msg_handler)
        loop.register_signal_handler(SendMessageSignal,
                                     self._handle_show_message)

        _hubs = self._list_hubs()

        # First, grab a list of all the standalone spokes.
        spokes = self._collectActionClasses(self.paths["spokes"],
                                            StandaloneSpoke)
        actionClasses = self._orderActionClasses(spokes, _hubs)

        for klass in actionClasses:
            obj = klass(data, self.storage, self.payload)

            # If we are doing a kickstart install, some standalone spokes
            # could already be filled out.  In that case, we do not want
            # to display them.
            if self._is_standalone(obj) and obj.completed:
                del (obj)
                continue

            if hasattr(obj, "set_path"):
                obj.set_path("spokes", self.paths["spokes"])
                obj.set_path("categories", self.paths["categories"])

            should_schedule = obj.setup(self.ENVIRONMENT)

            if should_schedule:
                scheduler.schedule_screen(obj)
    def setUp(self):
        super().setUp()
        self.create_loop()
        App.initialize(event_loop=self.loop)

        self._callback_called = False
        self._callback_input = ""

        self._callback_called2 = False
        self._callback_input2 = ""

        self._thread_barrier = Barrier(2, timeout=3)
        self._thread_event_wait_for_inner = Event()
        self._thread_event_wait_for_outer = Event()
        self._threads = []
Beispiel #22
0
    def changeVNCPasswdWindow(self):
        """ Change the password to a sane parameter.

        We ask user to input a password that (len(password) > 6
        and len(password) <= 8) or password == ''.
        """

        message = _("VNC password must be six to eight characters long.\n"
                    "Please enter a new one, or leave blank for no password.")
        App.initialize()
        loop = App.get_event_loop()
        loop.set_quit_callback(tui_quit_callback)
        spoke = VNCPassSpoke(self.anaconda.ksdata, None, None, message)
        ScreenHandler.schedule_screen(spoke)
        App.run()

        self.password = self.anaconda.ksdata.vnc.password
Beispiel #23
0
    def changeVNCPasswdWindow(self):
        """ Change the password to a sane parameter.

        We ask user to input a password that (len(password) > 6
        and len(password) <= 8) or password == ''.
        """

        message = _("VNC password must be six to eight characters long.\n"
                    "Please enter a new one, or leave blank for no password.")
        App.initialize()
        loop = App.get_event_loop()
        loop.set_quit_callback(tui_quit_callback)
        spoke = VNCPassSpoke(self.anaconda.ksdata, None, None, None, message)
        ScreenHandler.schedule_screen(spoke)
        App.run()

        self.password = self.anaconda.ksdata.vnc.password
Beispiel #24
0
    def setup(self, data):
        """Construct all the objects required to implement this interface.

        This method must be provided by all subclasses.
        """
        # Use GLib event loop for the Simpleline TUI
        loop = GLibEventLoop()
        App.initialize(event_loop=loop)

        loop.set_quit_callback(tui_quit_callback)
        scheduler = App.get_scheduler()
        scheduler.quit_screen = YesNoDialog(self.quitMessage)

        # tell python-meh it should use our raw_input
        meh_io_handler = meh.ui.text.IOHandler(in_func=self._get_meh_input_func)
        self._meh_interface.set_io_handler(meh_io_handler)

        # register handlers for various messages
        loop = App.get_event_loop()
        loop.register_signal_handler(ExceptionSignal, exception_msg_handler)
        loop.register_signal_handler(SendMessageSignal, self._handle_show_message)

        _hubs = self._list_hubs()

        # First, grab a list of all the standalone spokes.
        spokes = self._collectActionClasses(self.paths["spokes"], StandaloneSpoke)
        actionClasses = self._orderActionClasses(spokes, _hubs)

        for klass in actionClasses:
            obj = klass(data, self.storage, self.payload, self.instclass)

            # If we are doing a kickstart install, some standalone spokes
            # could already be filled out.  In that case, we do not want
            # to display them.
            if self._is_standalone(obj) and obj.completed:
                del(obj)
                continue

            if hasattr(obj, "set_path"):
                obj.set_path("spokes", self.paths["spokes"])
                obj.set_path("categories", self.paths["categories"])

            should_schedule = obj.setup(self.ENVIRONMENT)

            if should_schedule:
                scheduler.schedule_screen(obj)
Beispiel #25
0
def ask_vnc_question(anaconda, vnc_server, message):
    """ Ask the user if TUI or GUI-over-VNC should be started.

    :param anaconda: instance of the Anaconda class
    :param vnc_server: instance of the VNC server object
    :param str message: a message to show to the user together
                        with the question
    """
    App.initialize()
    loop = App.get_event_loop()
    loop.set_quit_callback(tui_quit_callback)
    spoke = AskVNCSpoke(anaconda.ksdata, message)
    ScreenHandler.schedule_screen(spoke)
    App.run()

    if anaconda.ksdata.vnc.enabled:
        if not anaconda.gui_mode:
            log.info("VNC requested via VNC question, switching Anaconda to GUI mode.")
        anaconda.display_mode = constants.DisplayModes.GUI
        flags.usevnc = True
        vnc_server.password = anaconda.ksdata.vnc.password
Beispiel #26
0
def ask_vnc_question(anaconda, vnc_server, message):
    """ Ask the user if TUI or GUI-over-VNC should be started.

    :param anaconda: instance of the Anaconda class
    :param vnc_server: instance of the VNC server object
    :param str message: a message to show to the user together
                        with the question
    """
    App.initialize()
    loop = App.get_event_loop()
    loop.set_quit_callback(tui_quit_callback)
    spoke = AskVNCSpoke(anaconda.ksdata, message)
    ScreenHandler.schedule_screen(spoke)
    App.run()

    if anaconda.ksdata.vnc.enabled:
        if not anaconda.gui_mode:
            log.info("VNC requested via VNC question, switching Anaconda to GUI mode.")
        anaconda.display_mode = constants.DisplayModes.GUI
        flags.usevnc = True
        vnc_server.password = anaconda.ksdata.vnc.password
Beispiel #27
0
    def test_reinitialize(self):
        event_loop1 = CustomEventLoop()
        event_loop2 = CustomEventLoop()
        scheduler1 = CustomScreenScheduler(event_loop1)
        scheduler2 = CustomScreenScheduler(event_loop2)
        configuration1 = CustomGlobalConfiguration()
        configuration2 = CustomGlobalConfiguration()

        App.initialize(event_loop=event_loop1, scheduler=scheduler1,
                       global_configuration=configuration1)
        self._check_app_settings(event_loop1, scheduler1, configuration1)

        App.initialize(event_loop=event_loop2, scheduler=scheduler2,
                       global_configuration=configuration2)
        self._check_app_settings(event_loop2, scheduler2, configuration2)

        App.initialize()
        self.assertNotEqual(App.get_event_loop(), event_loop2)
        self.assertNotEqual(App.get_scheduler(), scheduler2)
        self.assertNotEqual(App.get_configuration(), configuration2)
Beispiel #28
0
 def test_run_shortcut(self, run_mock):
     App.initialize()
     App.get_configuration().should_run_with_empty_stack = True
     App.run()
     self.assertTrue(run_mock.called)
 def setUp(self):
     App.initialize()
Beispiel #30
0
 def test_run_with_empty_screen_stack(self):
     App.initialize()
     with self.assertRaises(NothingScheduledError):
         App.run()
Beispiel #31
0
            # input is then required from the user.
            if num2 == 0:
                return InputState.DISCARDED

            self._message = int(num1 / num2)

            # Because this input is processed we need to show this screen (show the result).
            # This will call refresh so our new result will be processed inside of the refresh()
            # method.
            return InputState.PROCESSED_AND_REDRAW
        else:
            # Not input for our screen, try other default inputs. This will result in the
            # same state as DISCARDED when no default option is used.
            return key


if __name__ == "__main__":
    # Initialize application (create scheduler and event loop).
    App.initialize()

    # Create our screen.
    screen = DividerScreen()

    # Schedule screen to the screen scheduler.
    # This can be called only after App.initialize().
    ScreenHandler.schedule_screen(screen)

    # Run the application. You must have some screen scheduled
    # otherwise it will end in an infinite loop.
    App.run()
    def test_failed_screen_setup(self):
        screen = FailedSetupScreenMock()

        App.initialize()
        App.get_scheduler().schedule_screen(screen)
        App.run()
 def test_running_empty_loop(self, _):
     App.initialize()
     loop = App.get_event_loop()
     loop.process_signals()
 def test_close_screen_closed_from_other_source_error(self):
     App.initialize()
     App.get_scheduler().schedule_screen(UIScreen())
     with self.assertRaises(RenderUnexpectedError):
         App.get_scheduler().close_screen(closed_from=mock.MagicMock())