Пример #1
0
def print_bears(bears,
                show_description,
                show_params,
                console_printer,
                args=None):
    """
    Presents all bears being used in a stylized manner.

    :param bears:            It's a dictionary with bears as keys and list of
                             sections containing those bears as values.
    :param show_description: This parameter is deprecated.
    :param show_params:      This parameter is deprecated.
    :param console_printer:  Object to print messages on the console.
    :param args:             Args passed to coala command.
    """
    check_deprecation(OrderedDict([
        ('show_description', show_description),
        ('show_params', show_params)]))

    if not bears and not (args and args.json):
        console_printer.print('No bears to show. Did you forget to install '
                              'the `coala-bears` package? Try `pip3 install '
                              'coala-bears`.')
        return

    results = [bear for bear, _ in sorted(bears.items(),
                                          key=lambda bear_tuple:
                                          bear_tuple[0].name.lower())]
    if args and args.json:
        from coalib.output.JSONEncoder import create_json_encoder
        JSONEncoder = create_json_encoder(use_relpath=args.relpath)
        json_output = {}
        if args.show_details:
            json_output['bears'] = results
        else:
            json_output['bears'] = [bear.name for bear in results]

        import json
        json_formatted_output = json.dumps(json_output,
                                           cls=JSONEncoder,
                                           sort_keys=True,
                                           indent=2,
                                           separators=(',', ': '))
        if args.output:
            filename = args.output[0]
            with open(filename, 'w') as fp:
                fp.write(json_formatted_output)
        else:
            print(json_formatted_output)
    elif args and args.format:
        print_bears_formatted(results)
    else:
        for bear in results:
            show_bear(bear,
                      show_description,
                      show_params,
                      console_printer,
                      args)
Пример #2
0
def print_bears(bears,
                show_description,
                show_params,
                console_printer,
                args=None):
    """
    Presents all bears being used in a stylized manner.

    :param bears:            It's a dictionary with bears as keys and list of
                             sections containing those bears as values.
    :param show_description: This parameter is deprecated.
    :param show_params:      This parameter is deprecated.
    :param console_printer:  Object to print messages on the console.
    :param args:             Args passed to coala command.
    """
    check_deprecation(
        OrderedDict([('show_description', show_description),
                     ('show_params', show_params)]))

    if not bears and not (args and args.json):
        console_printer.print('No bears to show. Did you forget to install '
                              'the `coala-bears` package? Try `pip3 install '
                              'coala-bears`.')
        return

    results = [
        bear for bear, _ in sorted(
            bears.items(), key=lambda bear_tuple: bear_tuple[0].name.lower())
    ]
    if args and args.json:
        from coalib.output.JSONEncoder import create_json_encoder
        JSONEncoder = create_json_encoder(use_relpath=args.relpath)
        json_output = {}
        if args.show_details:
            json_output['bears'] = results
        else:
            json_output['bears'] = [bear.name for bear in results]

        import json
        json_formatted_output = json.dumps(json_output,
                                           cls=JSONEncoder,
                                           sort_keys=True,
                                           indent=2,
                                           separators=(',', ': '))
        if args.output:
            filename = args.output[0]
            with open(filename, 'w') as fp:
                fp.write(json_formatted_output)
        else:
            print(json_formatted_output)
    elif args and args.format:
        print_bears_formatted(results)
    else:
        for bear in results:
            show_bear(bear, show_description, show_params, console_printer,
                      args)
Пример #3
0
def show_bear(bear, show_description, show_params, console_printer, args=None):
    """
    Displays all information about a bear.

    :param bear:             The bear to be displayed.
    :param show_description: This parameter is deprecated.
    :param show_params:      This parameter is deprecated.
    :param console_printer:  Object to print messages on the console.
    :param args:             Args passed to coala command.
    """
    console_printer.print(bear.name, color='blue')

    metadata = bear.get_metadata()

    check_deprecation(
        OrderedDict([('show_description', show_description),
                     ('show_params', show_params)]))

    if show_description:
        console_printer.print('  ' + metadata.desc.replace('\n', '\n  '))
        console_printer.print()  # Add a newline

    if show_params:
        show_enumeration(
            console_printer, 'Supported languages:', bear.LANGUAGES, '  ',
            'The bear does not provide information about which languages '
            'it can analyze.')

    if (args and args.show_settings) or show_params:
        show_enumeration(console_printer, 'Needed Settings:',
                         metadata.non_optional_params, '  ',
                         'No needed settings.')
        show_enumeration(console_printer, 'Optional Settings:',
                         metadata.optional_params, '  ',
                         'No optional settings.')

    if show_params:
        show_enumeration(
            console_printer, 'Can detect:', bear.can_detect, '  ',
            'This bear does not provide information about what '
            'categories it can detect.')
        show_enumeration(
            console_printer, 'Can fix:', bear.CAN_FIX, '  ',
            'This bear cannot fix issues or does not provide '
            'information about what categories it can fix.')
        console_printer.print('  Path:\n' + '   ' +
                              repr(bear.source_location) + '\n')
Пример #4
0
def show_bear(bear,
              show_description,
              show_params,
              console_printer,
              args=None):
    """
    Displays all information about a bear.

    :param bear:             The bear to be displayed.
    :param show_description: This parameter is deprecated.
    :param show_params:      This parameter is deprecated.
    :param console_printer:  Object to print messages on the console.
    :param args:             Args passed to coala command.
    """
    console_printer.print(bear.name, color='blue')

    metadata = bear.get_metadata()

    check_deprecation(OrderedDict([
        ('show_description', show_description),
        ('show_params', show_params)]))

    if show_description:
        console_printer.print(
            '  ' + metadata.desc.replace('\n', '\n  '))
        console_printer.print()  # Add a newline

    if show_params:
        show_enumeration(
            console_printer, 'Supported languages:',
            bear.LANGUAGES,
            '  ',
            'The bear does not provide information about which languages '
            'it can analyze.')

    if (args and args.show_settings) or show_params:
        show_enumeration(console_printer,
                         'Needed Settings:',
                         metadata.non_optional_params,
                         '  ',
                         'No needed settings.')
        show_enumeration(console_printer,
                         'Optional Settings:',
                         metadata.optional_params,
                         '  ',
                         'No optional settings.')

    if show_params:
        show_enumeration(console_printer,
                         'Can detect:',
                         bear.can_detect,
                         '  ',
                         'This bear does not provide information about what '
                         'categories it can detect.')
        show_enumeration(console_printer,
                         'Can fix:',
                         bear.CAN_FIX,
                         '  ',
                         'This bear cannot fix issues or does not provide '
                         'information about what categories it can fix.')
        console_printer.print(
            '  Path:\n' + '   ' + repr(bear.source_location) + '\n')