コード例 #1
0
def _show_screens(group):
    with terminalui as initscr:
        win_size_y, win_size_x = initscr.getmaxyx()
        if win_size_y < 24 or win_size_x < 80:
            msg = ("     Terminal too small. Min size is 80x24."
                   " Current size is %(x)ix%(y)i." %
                   {'x': win_size_x, 'y': win_size_y})
            sys.exit(msg)
        screen_list = ScreenList()
        
        actions = [Action(curses.KEY_F2, "Continue", screen_list.get_next),
                   Action(curses.KEY_F3, "Back",
                          screen_list.previous_screen),
                   Action(curses.KEY_F6, "Help", screen_list.show_help),
                   Action(curses.KEY_F9, "Quit", screen_list.quit)]
        
        main_win = MainWindow(initscr, screen_list, actions)
        screen_list.help = HelpScreen(main_win, "Help Topics",
                                      "Help Index",
                                      "Select a topic and press Continue.")
        
        if group == "flow":
            win_list = get_selector_screens(main_win)
        else:
            win_list = basic_screens(main_win)
        screen_list.help.setup_help_data(win_list)
        screen_list.screen_list = win_list
        screen = screen_list.get_next()
        
        while screen is not None:
            screen = screen.show()
コード例 #2
0
def _show_screens(options):
    '''Navigate user through the set of configuration screens.
    Return True if user went through the complete set of screens,
    otherwise return False.'''
    with terminalui as initscr:
        win_size_y, win_size_x = initscr.getmaxyx()
        if win_size_y < 24 or win_size_x < 80:
            msg = _("     Terminal too small. Min size is 80x24."
                    " Current size is %(x)ix%(y)i.") % \
                    {'x': win_size_x, 'y': win_size_y}
            sys.exit(msg)
        screen_list = ScreenList()

        actions = [
            Action(curses.KEY_F2, _("Continue"), screen_list.get_next),
            Action(curses.KEY_F3, _("Back"), screen_list.previous_screen),
            Action(curses.KEY_F6, _("Help"), screen_list.show_help),
            Action(curses.KEY_F9, _("Quit"), screen_list.quit)
        ]

        main_win = MainWindow(initscr,
                              screen_list,
                              actions,
                              force_bw=options.force_bw)
        screen_list.help = HelpScreen(main_win, _("Help Topics"),
                                      _("Help Index"),
                                      _("Select a topic and press Continue."))

        win_list = _make_screen_list(main_win)
        screen_list.help.setup_help_data(win_list)
        screen_list.screen_list = win_list
        screen = screen_list.get_next()

        signal.signal(signal.SIGINT, signal.SIG_IGN)

        try:
            while screen is not None:
                eng = InstallEngine.get_instance()
                sc_prof = eng.doc.persistent.get_first_child(name="sysconfig")
                LOGGER.debug("Sysconfig profile:\n%s", sc_prof)
                LOGGER.debug("Displaying screen: %s", type(screen))
                screen = screen.show()
        except QuitException:
            LOGGER.info("User quit the application prematurely.")
            return False
        else:
            return True
コード例 #3
0
 def setUp(self):
     self.HelpScreen__init__ = HelpScreen.__init__
     HelpScreen.__init__ = lambda x, y: None
     self.help = HelpScreen(None)
     self.help.locale = "C"
     self.temp_dir = None
コード例 #4
0
class TestHelpScreen(unittest.TestCase):
    def setUp(self):
        self.HelpScreen__init__ = HelpScreen.__init__
        HelpScreen.__init__ = lambda x, y: None
        self.help = HelpScreen(None)
        self.help.locale = "C"
        self.temp_dir = None

    def tearDown(self):
        HelpScreen.__init__ = self.HelpScreen__init__
        self.help = None
        if self.temp_dir:
            shutil.rmtree(self.temp_dir)

    def test_setup_help_data_normal(self):
        '''HelpScreen.setup_help_data() correctly generates help_dict
           and help_info for screens with help_data'''
        screen = MockAll()
        screen.instance = ".test"
        screen.help_data = ("help data", "tuple")
        screen.help_format = "%s"

        self.help.setup_help_data([screen])
        self.assertEquals(screen.help_data,
                          self.help.help_dict["MockAll.test"])
        self.assertEquals(("MockAll.test", " %s"), self.help.help_info[0])

    def test_setup_help_data_no_data(self):
        '''HelpScreen.setup_help_data() generates empty help_dict/help_info
           for screens with no help_data'''
        screen = MockAll()
        screen.instance = ".test"
        screen.help_data = (None, None)
        screen.help_format = "%s"

        self.help.setup_help_data([screen])
        self.assertFalse(self.help.help_dict,
                         "HelpScreen.help_dict should be empty")
        self.assertFalse(self.help.help_info,
                         "HelpScreen.help_info should be empty")

    def test_get_locids_locale_has_encoding(self):
        '''HelpScreen._get_locids() includes correct possibilities
           if the current locale has an encoding.
           This includes: The current locale, the locale (without encoding),
           and the default ("C") locale.
        
        '''
        self.help.locale = "ab_CD.EFG-1"
        locids = self.help._get_locids()
        self.assertEquals(["ab_CD.EFG-1", "ab_CD", "ab", "C"], locids)

    def test_get_locids_locale_has_dialect(self):
        '''HelpScreen._get_locids() includes correct possibilities if current
           locales has dialect.
           This includes: The current locale, the language (locale without
           dialect), and the default ("C") locale.
        
        '''
        self.help.locale = "ab_CD"
        locids = self.help._get_locids()
        self.assertEquals(["ab_CD", "ab", "C"], locids)

    def test_get_help_text_file_exists(self):
        '''HelpScreen.get_help_text() loads help text from existent file'''
        temp_dir = tempfile.mkdtemp()
        self.temp_dir = temp_dir  # tearDown will clean up self.temp_dir
        os.makedirs(os.path.join(temp_dir, "C"))
        filename = os.path.join(temp_dir, "%s", "help.txt")
        temp_file = filename % "C"
        with open(temp_file, "w") as help_file:
            help_file.write(HELP_FILE_CONTENTS)

        help_text = self.help.get_help_text(filename=filename)
        self.assertEquals(HELP_FILE_CONTENTS, help_text)

    def test_get_help_text_file_does_not_exist(self):
        '''HelpScreen.get_help_text() falls back gracefully when
           no help text file is found'''
        badfile = os.tempnam() + "/%s/help.txt"
        help_text = self.help.get_help_text(filename=badfile)
        self.assertEquals("Help for this screen is not available", help_text)
コード例 #5
0
ファイル: __init__.py プロジェクト: alhazred/caiman
                exit_text_installer(errcode=msg)

            screen_list = ScreenList()
            actions = [
                Action(curses.KEY_F2, _("Continue"), screen_list.get_next),
                Action(curses.KEY_F3, _("Back"), screen_list.previous_screen),
                Action(curses.KEY_F6, _("Help"), screen_list.show_help),
                Action(curses.KEY_F9, _("Quit"), screen_list.quit)
            ]

            main_win = MainWindow(initscr,
                                  screen_list,
                                  actions,
                                  force_bw=options.force_bw)
            screen_list.help = HelpScreen(
                main_win, _("Help Topics"), _("Help Index"),
                _("Select a topic and press "
                  "Continue."))
            doc = InstallEngine.get_instance().doc

            debug_tc = False
            if options.debug:
                debug_tc = True
            target_controller = TargetController(doc,
                                                 debug=debug_tc,
                                                 dry_run=options.no_install)

            win_list = make_screen_list(main_win, target_controller,
                                        install_data)
            screen_list.help.setup_help_data(win_list)
            screen_list.screen_list = win_list
            screen = screen_list.get_next()
コード例 #6
0
 def setUp(self):
     self.HelpScreen__init__ = HelpScreen.__init__
     HelpScreen.__init__ = lambda x, y: None
     self.help = HelpScreen(None)
     self.help.locale = "C"
     self.temp_dir = None
コード例 #7
0
class TestHelpScreen(unittest.TestCase):
    
    def setUp(self):
        self.HelpScreen__init__ = HelpScreen.__init__
        HelpScreen.__init__ = lambda x, y: None
        self.help = HelpScreen(None)
        self.help.locale = "C"
        self.temp_dir = None
    
    def tearDown(self):
        HelpScreen.__init__ = self.HelpScreen__init__
        self.help = None
        if self.temp_dir:
            shutil.rmtree(self.temp_dir)
    
    def test_setup_help_data_normal(self):
        '''HelpScreen.setup_help_data() correctly generates help_dict
           and help_info for screens with help_data'''
        screen = MockAll()
        screen.instance = ".test"
        screen.help_data = ("help data", "tuple")
        screen.help_format = "%s"
        
        self.help.setup_help_data([screen])
        self.assertEquals(screen.help_data,
                          self.help.help_dict["MockAll.test"])
        self.assertEquals(("MockAll.test", " %s"), self.help.help_info[0])
    
    def test_setup_help_data_no_data(self):
        '''HelpScreen.setup_help_data() generates empty help_dict/help_info
           for screens with no help_data'''
        screen = MockAll()
        screen.instance = ".test"
        screen.help_data = (None, None)
        screen.help_format = "%s"
        
        self.help.setup_help_data([screen])
        self.assertFalse(self.help.help_dict,
                         "HelpScreen.help_dict should be empty")
        self.assertFalse(self.help.help_info,
                         "HelpScreen.help_info should be empty")
    
    def test_get_locids_locale_has_encoding(self):
        '''HelpScreen._get_locids() includes correct possibilities
           if the current locale has an encoding.
           This includes: The current locale, the locale (without encoding),
           and the default ("C") locale.
        
        '''
        self.help.locale = "ab_CD.EFG-1"
        locids = self.help._get_locids()
        self.assertEquals(["ab_CD.EFG-1", "ab_CD", "ab", "C"], locids)
    
    def test_get_locids_locale_has_dialect(self):
        '''HelpScreen._get_locids() includes correct possibilities if current
           locales has dialect.
           This includes: The current locale, the language (locale without
           dialect), and the default ("C") locale.
        
        '''
        self.help.locale = "ab_CD"
        locids = self.help._get_locids()
        self.assertEquals(["ab_CD", "ab", "C"], locids)
    
    def test_get_help_text_file_exists(self):
        '''HelpScreen.get_help_text() loads help text from existent file'''
        temp_dir = tempfile.mkdtemp()
        self.temp_dir = temp_dir # tearDown will clean up self.temp_dir
        os.makedirs(os.path.join(temp_dir, "C"))
        filename = os.path.join(temp_dir, "%s", "help.txt")
        temp_file = filename % "C"
        with open(temp_file, "w") as help_file:
            help_file.write(HELP_FILE_CONTENTS)
        
        help_text = self.help.get_help_text(filename=filename)
        self.assertEquals(HELP_FILE_CONTENTS, help_text)
    
    def test_get_help_text_file_does_not_exist(self):
        '''HelpScreen.get_help_text() falls back gracefully when
           no help text file is found'''
        badfile = os.tempnam() + "/%s/help.txt"
        help_text = self.help.get_help_text(filename=badfile)
        self.assertEquals("Help for this screen is not available", help_text)