coalib.output package

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', ))[source]

Bases: pyprint.ClosableObject.ClosableObject

static is_comment(key)[source]
write_section(section)[source]
write_sections(sections)[source]

coalib.output.ConsoleInteraction module

class coalib.output.ConsoleInteraction.BackgroundMessageStyle[source]

Bases: pygments.style.Style

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

Bases: pygments.style.Style

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

Bases: pygments.style.Style

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

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)[source]

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)[source]

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)[source]

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='')[source]
coalib.output.ConsoleInteraction.get_action_info(section, action, failed_actions)[source]

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)[source]
coalib.output.ConsoleInteraction.join_names(values)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]
coalib.output.ConsoleInteraction.print_lines(console_printer, file_dict, sourcerange)[source]

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)[source]

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)[source]

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)[source]
coalib.output.ConsoleInteraction.print_results_no_input(log_printer, section, result_list, file_dict, file_diff_dict, console_printer)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

Module contents