coalib.output package — coala 0.9.0.dev99999999999999 documentation

# coalib.output package

## Subpackages

- coalib.output.printers package
  - Submodules
  - coalib.output.printers.LOG_LEVEL module
  - coalib.output.printers.ListLogPrinter module
  - coalib.output.printers.LogPrinter module
  - Module contents

## Submodules

## coalib.output.ConfWriter module

class `coalib.output.ConfWriter.` `ConfWriter`(file_name, key_value_delimiters=('=', ), comment_separators=('#', ), key_delimiters=(', ', ' '), section_name_surroundings=mappingproxy({'[': ']'}), section_override_delimiters=('.', ), unsavable_keys=('save', ))

  Bases: `pyprint.ClosableObject.ClosableObject`

  static `is_comment`(key)
  `write_section`(section)
  `write_sections`(sections)

## coalib.output.ConsoleInteraction module

class `coalib.output.ConsoleInteraction.` `BackgroundMessageStyle`

  Bases: `pygments.style.Style`

  `styles` = {Token.Keyword.Pseudo: '', Token.Name.Other: '', Token.Name.Builtin.Pseudo: '', Token.Literal.Date: '', Token.Keyword.Namespace: '', Token.Literal.Number.Oct: '', Token.Comment.Special: '', Token.Literal.String.Regex: '', Token.Name.Variable.Instance: '', Token.Name.Constant: '', Token.Generic.Subheading: '', Token.Literal.String.Heredoc: '', Token.Name.Namespace: '', Token.Comment.PreprocFile: '', Token.Generic: '', Token.Literal.Number.Float: '', Token.Generic.Traceback: '', Token.Comment.Hashbang: '', Token.Generic.Emph: '', Token.Text.Whitespace: '', Token.Literal.String.Interpol: '', Token.Text: '', Token.Name.Class: '', Token.Keyword.Type: '', Token.Generic.Inserted: '', Token.Comment.Preproc: '', Token.Literal.String: '', Token.Name: '', Token.Name.Exception: '', Token.Escape: '', Token.Literal.String.Backtick: '', Token.Generic.Output: '', Token.Generic.Prompt: '', Token.Keyword.Declaration: '', Token.Error: '', Token.Literal.Number.Hex: '', Token.Literal.String.Char: '', Token.Literal.Number: '', Token.Name.Function: '', Token.Comment.Multiline: '', Token.Name.Variable.Global: '', Token.Other: '', Token.Literal.String.Single: '', Token.Generic.Error: '', Token.Name.Property: '', Token.Literal.String.Symbol: '', Token.Literal.Number.Bin: '', Token.Name.Decorator: '', Token.Literal: '', Token.Name.Builtin: '', Token.Generic.Deleted: '', Token.Generic.Strong: '', Token.Literal.String.Doc: '', Token.Comment: '', Token.Operator: '', Token.Literal.String.Other: '', Token.Name.Entity: '', Token.Comment.Single: '', Token.Literal.String.Escape: '', Token.Name.Label: '', Token.Generic.Heading: '', Token.Name.Attribute: '', Token.Literal.Number.Integer.Long: '', Token.Operator.Word: '', Token.Literal.String.Double: '', Token.Keyword.Constant: '', Token.Literal.Number.Integer: '', Token: 'bold bg:#eee #111', Token.Name.Variable.Class: '', Token.Keyword.Reserved: '', Token.Keyword: '', Token.Name.Tag: '', Token.Punctuation: '', Token.Name.Variable: ''}

class `coalib.output.ConsoleInteraction.` `BackgroundSourceRangeStyle`

  Bases: `pygments.style.Style`

  `styles` = {Token.Keyword.Pseudo: '', Token.Name.Other: '', Token.Name.Builtin.Pseudo: '', Token.Literal.Date: '', Token.Keyword.Namespace: '', Token.Literal.Number.Oct: '', Token.Comment.Special: '', Token.Literal.String.Regex: '', Token.Name.Variable.Instance: '', Token.Name.Constant: '', Token.Generic.Subheading: '', Token.Literal.String.Heredoc: '', Token.Name.Namespace: '', Token.Comment.PreprocFile: '', Token.Generic: '', Token.Literal.Number.Float: '', Token.Generic.Traceback: '', Token.Comment.Hashbang: '', Token.Generic.Emph: '', Token.Text.Whitespace: '', Token.Literal.String.Interpol: '', Token.Text: '', Token.Name.Class: '', Token.Keyword.Type: '', Token.Generic.Inserted: '', Token.Comment.Preproc: '', Token.Literal.String: '', Token.Name: '', Token.Name.Exception: '', Token.Escape: '', Token.Literal.String.Backtick: '', Token.Generic.Output: '', Token.Generic.Prompt: '', Token.Keyword.Declaration: '', Token.Error: '', Token.Literal.Number.Hex: '', Token.Literal.String.Char: '', Token.Literal.Number: '', Token.Name.Function: '', Token.Comment.Multiline: '', Token.Name.Variable.Global: '', Token.Other: '', Token.Literal.String.Single: '', Token.Generic.Error: '', Token.Name.Property: '', Token.Literal.String.Symbol: '', Token.Literal.Number.Bin: '', Token.Name.Decorator: '', Token.Literal: '', Token.Name.Builtin: '', Token.Generic.Deleted: '', Token.Generic.Strong: '', Token.Literal.String.Doc: '', Token.Comment: '', Token.Operator: '', Token.Literal.String.Other: '', Token.Name.Entity: '', Token.Comment.Single: '', Token.Literal.String.Escape: '', Token.Name.Label: '', Token.Generic.Heading: '', Token.Name.Attribute: '', Token.Literal.Number.Integer.Long: '', Token.Operator.Word: '', Token.Literal.String.Double: '', Token.Keyword.Constant: '', Token.Literal.Number.Integer: '', Token: 'bold bg:#BB4D3E #111', Token.Name.Variable.Class: '', Token.Keyword.Reserved: '', Token.Keyword: '', Token.Name.Tag: '', Token.Punctuation: '', Token.Name.Variable: ''}

class `coalib.output.ConsoleInteraction.` `NoColorStyle`

  Bases: `pygments.style.Style`

  `styles` = {Token.Keyword.Pseudo: '', Token.Name.Other: '', Token.Name.Builtin.Pseudo: '', Token.Literal.Date: '', Token.Keyword.Namespace: '', Token.Literal.Number.Oct: '', Token.Comment.Special: '', Token.Literal.String.Regex: '', Token.Name.Variable.Instance: '', Token.Name.Constant: '', Token.Generic.Subheading: '', Token.Literal.String.Heredoc: '', Token.Name.Namespace: '', Token.Comment.PreprocFile: '', Token.Generic: '', Token.Literal.Number.Float: '', Token.Generic.Traceback: '', Token.Comment.Hashbang: '', Token.Generic.Emph: '', Token.Text.Whitespace: '', Token.Literal.String.Interpol: '', Token.Text: '', Token.Name.Class: '', Token.Keyword.Type: '', Token.Generic.Inserted: '', Token.Comment.Preproc: '', Token.Literal.String: '', Token.Name: '', Token.Name.Exception: '', Token.Escape: '', Token.Literal.String.Backtick: '', Token.Generic.Output: '', Token.Generic.Prompt: '', Token.Keyword.Declaration: '', Token.Error: '', Token.Literal.Number.Hex: '', Token.Literal.String.Char: '', Token.Literal.Number: '', Token.Name.Function: '', Token.Comment.Multiline: '', Token.Name.Variable.Global: '', Token.Other: '', Token.Literal.String.Single: '', Token.Generic.Error: '', Token.Name.Property: '', Token.Literal.String.Symbol: '', Token.Literal.Number.Bin: '', Token.Name.Decorator: '', Token.Literal: '', Token.Name.Builtin: '', Token.Generic.Deleted: '', Token.Generic.Strong: '', Token.Literal.String.Doc: '', Token.Comment: '', Token.Operator: '', Token.Literal.String.Other: '', Token.Name.Entity: '', Token.Comment.Single: '', Token.Literal.String.Escape: '', Token.Name.Label: '', Token.Generic.Heading: '', Token.Name.Attribute: '', Token.Literal.Number.Integer.Long: '', Token.Operator.Word: '', Token.Literal.String.Double: '', Token.Keyword.Constant: '', Token.Literal.Number.Integer: '', Token: 'noinherit', Token.Name.Variable.Class: '', Token.Keyword.Reserved: '', Token.Keyword: '', Token.Name.Tag: '', Token.Punctuation: '', Token.Name.Variable: ''}

`coalib.output.ConsoleInteraction.` `acquire_actions_and_apply`(console_printer, section, file_diff_dict, result, file_dict, cli_actions=None)

  Acquires applicable actions and applies them.

  Parameters: | console_printer – Object to print messages on the console. section – Name of section to which the result belongs. file_diff_dict – Dictionary containing filenames as keys and Diff objects as values. result – A derivative of Result. file_dict – A dictionary containing all files with filename as key. cli_actions – The list of cli actions available.

`coalib.output.ConsoleInteraction.` `acquire_settings`(log_printer, settings_names_dict, section)

  This method prompts the user for the given settings.

  Parameters: | log_printer – Printer responsible for logging the messages. This is needed to comply with the interface. settings_names_dict – A dictionary with the settings name as key and a list containing a description in [0] and the name of the bears who need this setting in [1] and following. Example:

      {"UseTabs": ["describes whether tabs should be used instead of spaces",
                   "SpaceConsistencyBear",
                   "SomeOtherBear"]}

  Parameters: | section – The section the action corresponds to.
  Returns: | A dictionary with the settings name as key and the given value as value.

`coalib.output.ConsoleInteraction.` `ask_for_action_and_apply`(console_printer, section, metadata_list, action_dict, failed_actions, result, file_diff_dict, file_dict)

  Asks the user for an action and applies it.

  Parameters: | console_printer – Object to print messages on the console. section – Currently active section. metadata_list – Contains metadata for all the actions. action_dict – Contains the action names as keys and their references as values. failed_actions – A set of all actions that have failed. A failed action remains in the list until it is successfully executed. result – Result corresponding to the actions. file_diff_dict – If it is an action which applies a patch, this contains the diff of the patch to be applied to the file with filename as keys. file_dict – Dictionary with filename as keys and its contents as values.
  Returns: | Returns a boolean value. True will be returned, if it makes sense that the user may choose to execute another action, False otherwise.

`coalib.output.ConsoleInteraction.` `choose_action`(console_printer, actions)

  Presents the actions available to the user and takes as input the action the user wants to choose.

  Parameters: | console_printer – Object to print messages on the console. actions – Actions available to the user.
  Returns: | Return choice of action of user.

`coalib.output.ConsoleInteraction.` `format_lines`(lines, line_nr='')

`coalib.output.ConsoleInteraction.` `get_action_info`(section, action, failed_actions)

  Gets all the required Settings for an action. It updates the section with the Settings.

  Parameters: | section – The section the action corresponds to. action – The action to get the info for. failed_actions – A set of all actions that have failed. A failed action remains in the list until it is successfully executed.
  Returns: | Action name and the updated section.

`coalib.output.ConsoleInteraction.` `highlight_text`(no_color, text, lexer=<pygments.lexers.TextLexer>, style=None)

`coalib.output.ConsoleInteraction.` `join_names`(values)

  Produces a string by concatenating the items in `values` with commas, except the last element, which is concatenated with an “and”.

      >>> join_names(["apples", "bananas", "oranges"])
      'apples, bananas and oranges'
      >>> join_names(["apples", "bananas"])
      'apples and bananas'
      >>> join_names(["apples"])
      'apples'

  Parameters: | values – A list of strings.
  Returns: | The concatenated string.

`coalib.output.ConsoleInteraction.` `nothing_done`(log_printer)

  Will be called after processing a coafile when nothing had to be done, i.e. no section was enabled/targeted.

  Parameters: | log_printer – A LogPrinter object.

`coalib.output.ConsoleInteraction.` `print_actions`(console_printer, section, actions, failed_actions)

  Prints the given actions and lets the user choose.

  Parameters: | console_printer – Object to print messages on the console. actions – A list of FunctionMetadata objects. failed_actions – A set of all actions that have failed. A failed action remains in the list until it is successfully executed.
  Returns: | A tuple with the name member of the FunctionMetadata object chosen by the user and a Section containing at least all needed values for the action. If the user did choose to do nothing, return (None, None).

`coalib.output.ConsoleInteraction.` `print_affected_files`(console_printer, log_printer, result, file_dict)

  Prints all the affected files and affected lines within them.

  Parameters: | console_printer – Object to print messages on the console. log_printer – Printer responsible for logging the messages. result – The result to print the context for. file_dict – A dictionary containing all files with filename as key.

`coalib.output.ConsoleInteraction.` `print_affected_lines`(console_printer, file_dict, sourcerange)

  Prints the lines affected by the bears.

  Parameters: | console_printer – Object to print messages on the console. file_dict – A dictionary containing all files with filename as key. sourcerange – The SourceRange object referring to the related lines to print.

`coalib.output.ConsoleInteraction.` `print_bears`(bears, show_description, show_params, console_printer)

  Presents all bears being used in a stylized manner.

  Parameters: | bears – It’s a dictionary with bears as keys and list of sections containing those bears as values. show_description – True if the main description of the bears should be shown. show_params – True if the parameters and their description should be shown. console_printer – Object to print messages on the console.

`coalib.output.ConsoleInteraction.` `print_diffs_info`(diffs, printer)

`coalib.output.ConsoleInteraction.` `print_lines`(console_printer, file_dict, sourcerange)

  Prints the lines between the current and the result line. If needed they will be shortened.

  Parameters: | console_printer – Object to print messages on the console. file_dict – A dictionary containing all files as values with filenames as key. sourcerange – The SourceRange object referring to the related lines to print.

`coalib.output.ConsoleInteraction.` `print_result`(console_printer, section, file_diff_dict, result, file_dict, interactive=True)

  Prints the result to console.

  Parameters: | console_printer – Object to print messages on the console. section – Name of section to which the result belongs. file_diff_dict – Dictionary containing filenames as keys and Diff objects as values. result – A derivative of Result. file_dict – A dictionary containing all files with filename as key. interactive – Variable to check wether or not to offer the user actions interactively.

`coalib.output.ConsoleInteraction.` `print_results`(log_printer, section, result_list, file_dict, file_diff_dict, console_printer)

  Prints all the results in a section.

  Parameters: | log_printer – Printer responsible for logging the messages. section – The section to which the results belong to. result_list – List containing the results file_dict – A dictionary containing all files with filename as key. file_diff_dict – A dictionary that contains filenames as keys and diff objects as values. console_printer – Object to print messages on the console.

`coalib.output.ConsoleInteraction.` `print_results_formatted`(log_printer, section, result_list, *args)

`coalib.output.ConsoleInteraction.` `print_results_no_input`(log_printer, section, result_list, file_dict, file_diff_dict, console_printer)

  Prints all non interactive results in a section

  Parameters: | log_printer – Printer responsible for logging the messages. section – The section to which the results belong to. result_list – List containing the results file_dict – A dictionary containing all files with filename as key. file_diff_dict – A dictionary that contains filenames as keys and diff objects as values. console_printer – Object to print messages on the console.

`coalib.output.ConsoleInteraction.` `print_section_beginning`(console_printer, section)

  Will be called after initialization current_section in begin_section()

  Parameters: | console_printer – Object to print messages on the console. section – The section that will get executed now.

`coalib.output.ConsoleInteraction.` `require_setting`(setting_name, arr, section)

  This method is responsible for prompting a user about a missing setting and taking its value as input from the user.

  Parameters: | setting_name – Name of the setting missing arr – A list containing a description in [0] and the name of the bears who need this setting in [1] and following. section – The section the action corresponds to.

`coalib.output.ConsoleInteraction.` `show_bear`(bear, show_description, show_params, console_printer)

  Displays all information about a bear.

  Parameters: | bear – The bear to be displayed. show_description – True if the main description should be shown. show_params – True if the details should be shown. console_printer – Object to print messages on the console.

`coalib.output.ConsoleInteraction.` `show_bears`(local_bears, global_bears, show_description, show_params, console_printer)

  Extracts all the bears from each enabled section or the sections in the targets and passes a dictionary to the show_bears_callback method.

  Parameters: | local_bears – Dictionary of local bears with section names as keys and bear list as values. global_bears – Dictionary of global bears with section names as keys and bear list as values. show_description – True if the main description of the bears should be shown. show_params – True if the parameters and their description should be shown. console_printer – Object to print messages on the console.

`coalib.output.ConsoleInteraction.` `show_enumeration`(console_printer, title, items, indentation, no_items_text)

  This function takes as input an iterable object (preferably a list or a dict) and prints it in a stylized format. If the iterable object is empty, it prints a specific statement given by the user. An e.g :

  <indentation>Title: <indentation> * Item 1 <indentation> * Item 2

  Parameters: | console_printer – Object to print messages on the console. title – Title of the text to be printed items – The iterable object. indentation – Number of spaces to indent every line by. no_items_text – Text printed when iterable object is empty.

`coalib.output.ConsoleInteraction.` `show_language_bears_capabilities`(language_bears_capabilities, console_printer)

  Displays what the bears can detect and fix.

  Parameters: | language_bears_capabilities – Dictionary with languages as keys and their bears’ capabilities as values. The capabilities are stored in a tuple of two elements where the first one represents what the bears can detect, and the second one what they can fix. console_printer – Object to print messages on the console.

## coalib.output.Interactions module

`coalib.output.Interactions.` `fail_acquire_settings`(log_printer, settings_names_dict, section)

  This method throws an exception if any setting needs to be acquired.

  Parameters: | log_printer – Printer responsible for logging the messages. settings – A dictionary with the settings name as key and a list containing a description in [0] and the name of the bears who need this setting in [1] and following.
  Raises: | AssertionError – If any setting is required. TypeError – If `settings_names_dict` is not a dictionary.

## coalib.output.JSONEncoder module

`coalib.output.JSONEncoder.` `create_json_encoder`(**kwargs)

## Module contents