def load_services(self, options, config): """Load services into each protocol server. :param options: The options for the commands that shall be created. :param config: The configuration for the commands that shall be created. """ _LOGGER.info("Loading Services.") find_commands(config) for group_name in get_groups(): for command_name in get_commands(group_name): command = get_command(group_name, command_name) if hasattr(command, "execute"): _LOGGER.debug( "Registering %s.", command.group_name + '.' + \ command.command_name ) if self.__mysql_server: cmd = command() cmd.setup_server(self.__mysql_server, options, config) self.__mysql_server.register_command(cmd) if self.__rpc_server: cmd = command() cmd.setup_server(self.__rpc_server, options, config) self.__rpc_server.register_command(cmd)
def show_commands(): """List the possible commands and their descriptions. """ commands = [] max_name_size = 0 for group_name in get_groups(): for command_name in get_commands(group_name): cls = get_command(group_name, command_name) doc_text = "" if cls.__doc__ and cls.__doc__.find(".") != -1: doc_text = cls.__doc__[0:cls.__doc__.find(".") + 1] elif cls.__doc__: doc_text = cls.__doc__ doc_text = [text.strip(" ") for text in doc_text.split("\n")] commands.append((group_name, command_name, " ".join(doc_text))) name_size = len(group_name) + len(command_name) if name_size > max_name_size: max_name_size = name_size # Format each description and print the result. wrapper = textwrap.TextWrapper(subsequent_indent=(" " * (max_name_size + 3))) for group_name, command_name, help_text in commands: padding_size = max_name_size - len(group_name) - len(command_name) padding_size = 0 if padding_size < 0 else padding_size padding_text = "".rjust(padding_size, " ") help_text = wrapper.fill(help_text) text = (group_name, command_name, padding_text, help_text) print " ".join(text)
def _handle_information_schema_routines(self, is_routines_match): """Handle a select from INFORMATION_SCHEMA.ROUTINES We give a list of all groups and commands. There is no filtering going on. :param is_routines_match: :return: """ groups = get_groups() self.send_packet(self.column_count_packet(5)) self.send_packet(self.column_packet( 'SPECIFIC_NAME', type_=str, table='routines', catalog='information_schema' )) self.send_packet(self.column_packet( 'ROUTINE_CATALOG', type_=str, table='routines', catalog='information_schema' )) self.send_packet(self.column_packet( 'ROUTINE_SCHEMA', type_=str, table='routines', catalog='information_schema' )) self.send_packet(self.column_packet( 'ROUTINE_NAME', type_=str, table='routines', catalog='information_schema' )) self.send_packet(self.column_packet( 'ROUTINE_TYPE', type_=str, table='routines', catalog='information_schema' )) self.send_packet(self.eof_packet()) for group in groups: commands = get_commands(group) for command in commands: self.send_packet(self.row_packet( '{0}.{1}'.format(group, command), # specific_name 'fabric', # catalog group, # routine_schema command, # routine_name 'FABRIC_COMMAND', # routine_type )) self.send_packet(self.eof_packet())
def help_group(group_name): """Print help on a command group and exit. This will print a list of the commands available in the group, or an error message if the group is not available, and then exit with exit code 2. """ indent = " " * 4 try: commands = get_commands(group_name) print print "Commands available in group '%s' are:" % (group_name,) for cmdname in commands: print indent + get_command(group_name, cmdname).get_signature() except KeyError: PARSER.print_error(_ERR_GROUP_MISSING % (group_name, )) PARSER.exit(2)
def help_group(group_name): """Print help on a command group and exit. This will print a list of the commands available in the group, or an error message if the group is not available, and then exit with exit code 2. """ indent = " " * 4 try: commands = get_commands(group_name) print print "Commands available in group '%s' are:" % (group_name, ) for cmdname in commands: print indent + get_command(group_name, cmdname).get_signature() except KeyError: PARSER.print_error(_ERR_GROUP_MISSING % (group_name, )) PARSER.exit(2)
def show_commands(): """List the possible commands and their descriptions. """ commands = [] max_name_size = 0 for group_name in get_groups(): for command_name in get_commands(group_name): cls = get_command(group_name, command_name) doc_text = "" if cls.__doc__ and cls.__doc__.find(".") != -1: doc_text = cls.__doc__[0: cls.__doc__.find(".") + 1] elif cls.__doc__: doc_text = cls.__doc__ doc_text = [text.strip(" ") for text in doc_text.split("\n")] commands.append( (group_name, command_name, " ".join(doc_text)) ) name_size = len(group_name) + len(command_name) if name_size > max_name_size: max_name_size = name_size # Format each description and print the result. wrapper = textwrap.TextWrapper( subsequent_indent=(" " * (max_name_size + 3))) for group_name, command_name, help_text in commands: padding_size = max_name_size - len(group_name) - len(command_name) padding_size = 0 if padding_size < 0 else padding_size padding_text = "".rjust(padding_size, " ") help_text = wrapper.fill(help_text) text = (group_name, command_name, padding_text, help_text) print " ".join(text)