コード例 #1
0
def _parse_arg_commands(commands):
    input_commands = commands.split(',')
    available_commands = HaproxyLogFile.commands()
    for cmd in input_commands:
        if cmd not in available_commands:
            msg = 'command "{0}" is not available. Use --list-commands to ' \
                  'get a list of all available commands.'
            raise ValueError(msg.format(cmd))
    return input_commands
コード例 #2
0
def _parse_arg_commands(commands):
    input_commands = commands.split(',')
    available_commands = HaproxyLogFile.commands()
    for cmd in input_commands:
        if cmd not in available_commands:
            msg = 'command "{0}" is not available. Use --list-commands to ' \
                  'get a list of all available commands.'
            raise ValueError(msg.format(cmd))
    return input_commands
コード例 #3
0
    def test_arg_parser_list_commands_output(self):
        """Test that list commands argument outputs what's expected."""
        arguments = ['--list-commands', ]
        data = parse_arguments(self.parser.parse_args(arguments))
        test_output = NamedTemporaryFile(mode='w', delete=False)

        with RedirectStdout(stdout=test_output):
            main(data)

        with open(test_output.name, 'r') as output_file:
            output_text = output_file.read()

            for cmd in HaproxyLogFile.commands():
                self.assertIn(cmd, output_text)
コード例 #4
0
def print_commands():
    """Prints all commands available from HaproxyLogFile with their
    description.
    """
    dummy_log_file = HaproxyLogFile()
    commands = HaproxyLogFile.commands()
    commands.sort()

    for cmd in commands:
        description = eval('dummy_log_file.cmd_{0}.__doc__'.format(cmd))
        if description:
            description = re.sub(r'\n\s+', ' ', description)
            description = description.strip()

        print('{0}: {1}\n'.format(cmd, description))
コード例 #5
0
def print_commands():
    """Prints all commands available from HaproxyLogFile with their
    description.
    """
    dummy_log_file = HaproxyLogFile()
    commands = HaproxyLogFile.commands()
    commands.sort()

    for cmd in commands:
        description = eval('dummy_log_file.cmd_{0}.__doc__'.format(cmd))
        if description:
            description = re.sub(r'\n\s+', ' ', description)
            description = description.strip()

        print('{0}: {1}\n'.format(cmd, description))
コード例 #6
0
    def test_arg_parser_list_commands_output(self):
        """Test that list commands argument outputs what's expected."""
        arguments = [
            '--list-commands',
        ]
        data = parse_arguments(self.parser.parse_args(arguments))
        test_output = NamedTemporaryFile(mode='w', delete=False)

        with RedirectStdout(stdout=test_output):
            main(data)

        with open(test_output.name, 'r') as output_file:
            output_text = output_file.read()

            for cmd in HaproxyLogFile.commands():
                self.assertIn(cmd, output_text)