coalib.output package¶
Subpackages¶
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', ), key_value_append_delimiters=('+=', ))[source]¶ Bases:
pyprint.ClosableObject.ClosableObject
coalib.output.ConsoleInteraction module¶
-
class
coalib.output.ConsoleInteraction.
BackgroundMessageStyle
[source]¶ Bases:
pygments.style.Style
-
styles
= {Token.Generic.Deleted: '', Token.Name.Entity: '', Token.Generic: '', Token.Name.Decorator: '', Token.Name.Namespace: '', Token.Name.Constant: '', Token.Other: '', Token.Text: '', Token.Operator.Word: '', Token.Name.Function.Magic: '', Token.Literal.String.Backtick: '', Token.Error: '', Token.Name.Exception: '', Token.Name: '', Token.Keyword.Reserved: '', Token.Literal.Number.Oct: '', Token.Literal.Date: '', Token.Literal.String.Single: '', Token.Keyword.Type: '', Token.Keyword.Declaration: '', Token.Keyword.Namespace: '', Token.Generic.Output: '', Token.Name.Property: '', Token.Name.Builtin.Pseudo: '', Token.Punctuation: '', Token.Literal.String.Symbol: '', Token.Literal.String.Escape: '', Token.Literal.String.Heredoc: '', Token.Name.Other: '', Token: 'bold bg:#eee #111', Token.Name.Class: '', Token.Literal.String.Doc: '', Token.Generic.Traceback: '', Token.Literal: '', Token.Generic.Emph: '', Token.Comment.Hashbang: '', Token.Comment.Special: '', Token.Literal.String.Delimiter: '', Token.Literal.Number.Hex: '', Token.Name.Variable: '', Token.Literal.Number.Integer: '', Token.Name.Label: '', Token.Keyword: '', Token.Keyword.Pseudo: '', Token.Literal.String.Char: '', Token.Name.Function: '', Token.Literal.Number.Float: '', Token.Generic.Error: '', Token.Generic.Strong: '', Token.Comment.Preproc: '', Token.Literal.Number.Bin: '', Token.Literal.String.Interpol: '', Token.Escape: '', Token.Name.Attribute: '', Token.Generic.Heading: '', Token.Comment: '', Token.Generic.Prompt: '', Token.Keyword.Constant: '', Token.Generic.Inserted: '', Token.Name.Variable.Instance: '', Token.Literal.Number: '', Token.Comment.PreprocFile: '', Token.Generic.Subheading: '', Token.Literal.String.Double: '', Token.Operator: '', Token.Name.Variable.Magic: '', Token.Comment.Multiline: '', Token.Name.Variable.Global: '', Token.Name.Tag: '', Token.Comment.Single: '', Token.Name.Builtin: '', Token.Literal.String.Regex: '', Token.Literal.String.Affix: '', Token.Name.Variable.Class: '', Token.Literal.String: '', Token.Text.Whitespace: '', Token.Literal.Number.Integer.Long: '', Token.Literal.String.Other: ''}¶
-
-
class
coalib.output.ConsoleInteraction.
BackgroundSourceRangeStyle
[source]¶ Bases:
pygments.style.Style
-
styles
= {Token.Generic.Deleted: '', Token.Name.Entity: '', Token.Generic: '', Token.Name.Decorator: '', Token.Name.Namespace: '', Token.Name.Constant: '', Token.Other: '', Token.Text: '', Token.Operator.Word: '', Token.Name.Function.Magic: '', Token.Literal.String.Backtick: '', Token.Error: '', Token.Name.Exception: '', Token.Name: '', Token.Keyword.Reserved: '', Token.Literal.Number.Oct: '', Token.Literal.Date: '', Token.Literal.String.Single: '', Token.Keyword.Type: '', Token.Keyword.Declaration: '', Token.Keyword.Namespace: '', Token.Generic.Output: '', Token.Name.Property: '', Token.Name.Builtin.Pseudo: '', Token.Punctuation: '', Token.Literal.String.Symbol: '', Token.Literal.String.Escape: '', Token.Literal.String.Heredoc: '', Token.Name.Other: '', Token: 'bold bg:#BB4D3E #111', Token.Name.Class: '', Token.Literal.String.Doc: '', Token.Generic.Traceback: '', Token.Literal: '', Token.Generic.Emph: '', Token.Comment.Hashbang: '', Token.Comment.Special: '', Token.Literal.String.Delimiter: '', Token.Literal.Number.Hex: '', Token.Name.Variable: '', Token.Literal.Number.Integer: '', Token.Name.Label: '', Token.Keyword: '', Token.Keyword.Pseudo: '', Token.Literal.String.Char: '', Token.Name.Function: '', Token.Literal.Number.Float: '', Token.Generic.Error: '', Token.Generic.Strong: '', Token.Comment.Preproc: '', Token.Literal.Number.Bin: '', Token.Literal.String.Interpol: '', Token.Escape: '', Token.Name.Attribute: '', Token.Generic.Heading: '', Token.Comment: '', Token.Generic.Prompt: '', Token.Keyword.Constant: '', Token.Generic.Inserted: '', Token.Name.Variable.Instance: '', Token.Literal.Number: '', Token.Comment.PreprocFile: '', Token.Generic.Subheading: '', Token.Literal.String.Double: '', Token.Operator: '', Token.Name.Variable.Magic: '', Token.Comment.Multiline: '', Token.Name.Variable.Global: '', Token.Name.Tag: '', Token.Comment.Single: '', Token.Name.Builtin: '', Token.Literal.String.Regex: '', Token.Literal.String.Affix: '', Token.Name.Variable.Class: '', Token.Literal.String: '', Token.Text.Whitespace: '', Token.Literal.Number.Integer.Long: '', Token.Literal.String.Other: ''}¶
-
-
class
coalib.output.ConsoleInteraction.
NoColorStyle
[source]¶ Bases:
pygments.style.Style
-
styles
= {Token.Generic.Deleted: '', Token.Name.Entity: '', Token.Generic: '', Token.Name.Decorator: '', Token.Name.Namespace: '', Token.Name.Constant: '', Token.Other: '', Token.Text: '', Token.Operator.Word: '', Token.Name.Function.Magic: '', Token.Literal.String.Backtick: '', Token.Error: '', Token.Name.Exception: '', Token.Name: '', Token.Keyword.Reserved: '', Token.Literal.Number.Oct: '', Token.Literal.Date: '', Token.Literal.String.Single: '', Token.Keyword.Type: '', Token.Keyword.Declaration: '', Token.Keyword.Namespace: '', Token.Generic.Output: '', Token.Name.Property: '', Token.Name.Builtin.Pseudo: '', Token.Punctuation: '', Token.Literal.String.Symbol: '', Token.Literal.String.Escape: '', Token.Literal.String.Heredoc: '', Token.Name.Other: '', Token: 'noinherit', Token.Name.Class: '', Token.Literal.String.Doc: '', Token.Generic.Traceback: '', Token.Literal: '', Token.Generic.Emph: '', Token.Comment.Hashbang: '', Token.Comment.Special: '', Token.Literal.String.Delimiter: '', Token.Literal.Number.Hex: '', Token.Name.Variable: '', Token.Literal.Number.Integer: '', Token.Name.Label: '', Token.Keyword: '', Token.Keyword.Pseudo: '', Token.Literal.String.Char: '', Token.Name.Function: '', Token.Literal.Number.Float: '', Token.Generic.Error: '', Token.Generic.Strong: '', Token.Comment.Preproc: '', Token.Literal.Number.Bin: '', Token.Literal.String.Interpol: '', Token.Escape: '', Token.Name.Attribute: '', Token.Generic.Heading: '', Token.Comment: '', Token.Generic.Prompt: '', Token.Keyword.Constant: '', Token.Generic.Inserted: '', Token.Name.Variable.Instance: '', Token.Literal.Number: '', Token.Comment.PreprocFile: '', Token.Generic.Subheading: '', Token.Literal.String.Double: '', Token.Operator: '', Token.Name.Variable.Magic: '', Token.Comment.Multiline: '', Token.Name.Variable.Global: '', Token.Name.Tag: '', Token.Comment.Single: '', Token.Name.Builtin: '', Token.Literal.String.Regex: '', Token.Literal.String.Affix: '', Token.Name.Variable.Class: '', Token.Literal.String: '', Token.Text.Whitespace: '', Token.Literal.Number.Integer.Long: '', Token.Literal.String.Other: ''}¶
-
-
coalib.output.ConsoleInteraction.
acquire_actions_and_apply
(console_printer, section, file_diff_dict, result, file_dict, cli_actions=None, apply_single=False)[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.
- apply_single – The action that should be applied for all results. If it’s not selected, has a value of False.
- 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, applied_actions, apply_single=False)[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.
- apply_single – The action that should be applied for all results. If it’s not selected, has a value of False.
- applied_actions – A dictionary that contains the result, file_dict, file_diff_dict and the section for an action.
Returns: Returns a boolean value. True will be returned, if it makes sense that the user may choose to execute another action, False otherwise. If apply_single isn’t set, always return False.
-
coalib.output.ConsoleInteraction.
choose_action
(console_printer, actions, apply_single=False)[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.
- apply_single – The action that should be applied for all results. If it’s not selected, has a value of False.
Returns: Return a tuple of lists, a list with the names of actions that needs to be applied and a list with with the description of the actions.
-
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, style, lexer=<pygments.lexers.TextLexer>)[source]¶
-
coalib.output.ConsoleInteraction.
nothing_done
(log_printer=None)[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_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, args=None)[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 – This parameter is deprecated.
- show_params – This parameter is deprecated.
- console_printer – Object to print messages on the console.
- args – Args passed to coala command.
-
coalib.output.ConsoleInteraction.
print_diffs_info
(diffs, printer)[source]¶ Prints diffs information (number of additions and deletions) to the console.
Parameters: - diffs – List of Diff objects containing corresponding diff info.
- printer – Object responsible for printing diffs on console.
-
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, apply_single=False)[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.
- apply_single – The action that should be applied for all results. If it’s not selected, has a value of False.
- interactive – Variable to check whether 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, apply_single=False)[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.
- apply_single – The action that should be applied for all results. If it’s not selected, has a value of False.
- console_printer – Object to print messages on the console.
-
coalib.output.ConsoleInteraction.
print_results_formatted
(log_printer, section, result_list, file_dict, *args)[source]¶ Prints results through the format string from the format setting done by user.
Parameters: - log_printer – Printer responsible for logging the messages.
- section – The section to which the results belong.
- result_list – List of Result objects containing the corresponding results.
-
coalib.output.ConsoleInteraction.
print_results_no_input
(log_printer, section, result_list, file_dict, file_diff_dict, console_printer, apply_single=False)[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.
- apply_single – The action that should be applied for all results. If it’s not selected, has a value of False.
- 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.
- return – Returns the setting value that was requested from the user.
-
coalib.output.ConsoleInteraction.
show_bear
(bear, show_description, show_params, console_printer, args=None)[source]¶ Displays all information about a bear.
Parameters: - bear – The bear to be displayed.
- show_description – This parameter is deprecated.
- show_params – This parameter is deprecated.
- console_printer – Object to print messages on the console.
- args – Args passed to coala command.
-
coalib.output.ConsoleInteraction.
show_bears
(local_bears, global_bears, show_description, show_params, console_printer, args=None)[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 – This parameter is deprecated.
- show_params – This parameter is deprecated.
- console_printer – Object to print messages on the console.
- args – Args passed to coala command.
-
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.ConsoleInteraction.
try_to_apply_action
(action_name, chosen_action, console_printer, section, metadata_list, action_dict, failed_actions, result, file_diff_dict, file_dict, applied_actions)[source]¶ Try to apply the given action.
Parameters: - action_name – The name of the action.
- chosen_action – The action object that will be applied.
- 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.
- applied_actions – A dictionary that contains the result, file_dict, file_diff_dict and the section for an action.
- file_dict – Dictionary with filename as keys and its contents as values.
coalib.output.Interactions module¶
-
coalib.output.Interactions.
fail_acquire_settings
(log_printer, settings_names_dict)[source]¶ This method throws an exception if any setting needs to be acquired.
Parameters: - log_printer – Printer responsible for logging the messages.
- 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.
Raises: - AssertionError – If any setting is required.
- TypeError – If
settings_names_dict
is not a dictionary.
coalib.output.Logging module¶
-
class
coalib.output.Logging.
CounterHandler
(level=0)[source]¶ Bases:
logging.Handler
A logging handler which counts the number of calls for each logging level.
-
class
coalib.output.Logging.
JSONFormatter
(fmt=None, datefmt=None, style='%')[source]¶ Bases:
logging.Formatter
JSON formatter for python logging.