Example #1
0
    def do_base_command_tab(self, command_text, matches):
        """Do the tab completion for a base command.

        This method prints the list of base commands that match the
        command. If the user pressed TAB twice, it displays the list of all
        matches. If a single match is found, it returns the balance of the
        command.

        Note: this method gets its matches from do_command_tab.

        command_text[in]   Command
        matches[in]        Known matches (from do_command_tab)
        """
        if self.tab_count == 2:
            print "\n"
            print_dictionary_list(['Command', 'Description'],
                                  ['name', 'text', 'alias'], matches,
                                  self.width, True)
            print
            self.cmd_line.display_command()
            self.tab_count = 0
        else:
            if len(matches) == 1:
                if matches[0]['name'][:len(command_text)] == command_text:
                    new_cmd = matches[0]['name'] + ' '
                else:
                    new_cmd = matches[0]['alias'] + ' '
                self.tab_count = 0
                self.cmd_line.add(new_cmd[len(command_text):])
    def show_custom_options(self):
        """Show all of the options for the mysqluc utility.

        This method reads all of the options specified when mysqluc was
        launched and displays them to the user. If none were specified, a
        message is displayed instead.
        """
        if self.quiet:
            return
        if len(self.options) == 0:
            print("\n\nNo options specified.\n")
            return

        # Build a new list that normalizes the options as a dictionary
        dictionary_list = []
        for key in self.options.keys():
            # Skip variables list and messages
            if not key in ['variables', 'welcome', 'goodbye']:
                value = self.options.get(key, '')
                item = {
                    'name': key,
                    'value': value
                }
                dictionary_list.append(item)

        print
        print
        print_dictionary_list(['Option', 'Value'], ['name', 'value'],
                              dictionary_list, self.width)
        print
Example #3
0
    def do_base_command_tab(self, command_text, matches):
        """Do the tab completion for a base command.

        This method prints the list of base commands that match the
        command. If the user pressed TAB twice, it displays the list of all
        matches. If a single match is found, it returns the balance of the
        command.

        Note: this method gets its matches from do_command_tab.

        command_text[in]   Command
        matches[in]        Known matches (from do_command_tab)
        """
        if self.tab_count == 2:
            print "\n"
            print_dictionary_list(['Command', 'Description'],
                                  ['name', 'text', 'alias'],
                                  matches, self.width, True)
            print
            self.cmd_line.display_command()
            self.tab_count = 0
        else:
            if len(matches) == 1:
                new_cmd = matches[0]['name'] + ' '
                self.tab_count = 0
                self.cmd_line.add(new_cmd[len(command_text):])
Example #4
0
    def show_command_help(self, commands):
        """Show the help for a list of commands.

        commands[in]       List of commands
        """
        if self.quiet:
            return
        print
        print_dictionary_list(['Command', 'Description'],
                              ['name', 'text', 'alias'], commands, self.width,
                              True)
        print
Example #5
0
    def show_command_help(self, commands):
        """Show the help for a list of commands.

        commands[in]       List of commands
        """
        if self.quiet:
            return
        print
        print_dictionary_list(['Command', 'Description'],
                              ['name', 'text', 'alias'],
                              commands, self.width, True)
        print
    def show_utility_help(self, utils):
        """Display help for a utility.

        utils[in]          The utility name.
        """
        if self.quiet:
            return
        options = self.utils.get_options_dictionary(utils[0])
        print("\n{0}\n".format(utils[0]['usage']))
        print("{0} - {1}\n".format(utils[0]['name'], utils[0]['description']))
        print("Options:")
        print_dictionary_list(['Option', 'Description'],
                              ['long_name', 'description'],
                              options, self.width, False)
        print
Example #7
0
 def show_utility_help(self, utils):
     """Display help for a utility.
     
     utils[in]          The utility name.
     """
     if self.quiet:
         return
     options = self.utils.get_options_dictionary(utils[0]['options'])
     print "\n%s\n" % utils[0]['usage']
     print "%s - %s\n" % (utils[0]['name'], utils[0]['description'])
     print "Options:"
     print_dictionary_list(['Option', 'Description'],
                           ['long_name', 'description'], options,
                           self.width, False)
     print
 def show_utility_help(self, utils):
     """Display help for a utility.
     
     utils[in]          The utility name.
     """
     if self.quiet:
         return
     options = self.utils.get_options_dictionary(utils[0]['options'])
     print "\n%s\n" % utils[0]['usage']
     print "%s - %s\n" % (utils[0]['name'], utils[0]['description'])
     print "Options:"
     print_dictionary_list(['Option', 'Description'],
                           ['long_name', 'description'],
                           options, self.width, False)
     print
Example #9
0
    def show_options(self, options):
        """Show list of options for a utility by name.

        options[in]    structure containing the options

        This method displays a list of the options and their descriptions
        for the given utility.
        """
        if len(options) > 0:
            dictionary_list = self.get_options_dictionary(options)
            print
            print
            print_dictionary_list(['Option', 'Description'],
                                  ['long_name', 'description'],
                                  dictionary_list, self.width)
            print
Example #10
0
 def show_options(self, options):
     """Show list of options for a utility by name.
     
     options[in]    structure containing the options
     
     This method displays a list of the options and their descriptions
     for the given utility.
     """  
     if len(options) > 0:
         dictionary_list = self.get_options_dictionary(options)
         print
         print
         print_dictionary_list(['Option', 'Description'],
                               ['long_name', 'description'],
                               dictionary_list, self.width)        
         print
Example #11
0
 def show_utilities(self, list=None):
     """Show list of utilities as a 2-column list.
     
     list[in]       list of utilities to print - default is None
                    which means print all utilities
     """
     
     if list is None:
         list_of_utilities = self.util_list
     else:
         list_of_utilities = list
     print
     if len(list_of_utilities) > 0:
         print_dictionary_list(['Utility', 'Description'],
                               ['name', 'description'],
                               list_of_utilities, self.width)        
     else:
         print
         print "No utilities match the search term."
     print
Example #12
0
    def show_help(self, parameter):
        """Display the help for either all commands or the help for a
        custom command.

        parameter[in]      Any parameter for the help command.
                           For example, 'help commands'
        """
        if self.quiet:
            return
        if not parameter or (parameter and parameter.lower() == 'commands'):
            print
            print_dictionary_list(['Command', 'Description'],
                                  ['name', 'text', 'alias'],
                                  self.base_commands, self.width, True)
            print
        else:
            matches = self.get_commands(parameter)
            if len(matches) > 0:
                self.show_command_help(matches)
            elif self.custom_commands:
                self.show_custom_command_help(parameter)
Example #13
0
    def show_help(self, parameter):
        """Display the help for either all commands or the help for a
        custom command.

        parameter[in]      Any parameters for the help command.
                           For example, 'help commands'
        """
        if self.quiet:
            return
        if not parameter or (parameter and parameter.lower() == 'commands'):
            print
            print_dictionary_list(['Command', 'Description'],
                                  ['name', 'text', 'alias'],
                                  self.base_commands, self.width, True)
            print
        else:
            matches = self.get_commands(parameter)
            if len(matches) > 0:
                self.show_command_help(matches)
            elif self.custom_commands:
                self.show_custom_command_help(parameter)
Example #14
0
 def show_variables(self, variables={}):
     """Display variables
     
     This method displays the variables included in the list passed or all
     variables is list passed is empty.
     
     variables[in]      List of variables
     """
     if self.options.get("quiet", False):
         return
     
     var_list = [ { 'name': key, 'value': value }
                  for key, value in self.iteritems() ]
     
     print "\n"
     if not self:
         print "There are no variables defined.\n"
         return
     
     print_dictionary_list(['Variable', 'Value'], ['name', 'value'],
                           var_list, self.width)
     print
Example #15
0
    def show_utilities(self, print_list=None):
        """Show list of utilities as a 2-column list.

        print_list[in]    list of utilities to print - default is None
                          which means print all utilities
        """

        if print_list is None:
            if len(self.util_list) != len(self.available_utilities):
                self.find_utilities()
            list_of_utilities = self.util_list
        else:
            list_of_utilities = print_list
        print
        if len(list_of_utilities) > 0:
            print_dictionary_list(['Utility', 'Description'],
                                  ['name', 'description'], list_of_utilities,
                                  self.width)
        else:
            print
            print "No utilities match the search term."
        print
Example #16
0
    def show_variables(self, variables=None):
        """Display variables

        This method displays the variables included in the list passed or all
        variables is list passed is empty.

        variables[in]      List of variables
        """
        if self.options.get("quiet", False):
            return

        var_list = [{'name': key, 'value': value}
                    for key, value in self.iteritems()]

        print "\n"
        if not self:
            print "There are no variables defined.\n"
            return

        print_dictionary_list(['Variable', 'Value'], ['name', 'value'],
                              var_list, self.width)
        print