coalib.output package

Submodules

coalib.output.ConfWriter module

class coalib.output.ConfWriter.ConfWriter(file_name, key_value_delimiters=('=', ), comment_seperators=('#', ), key_delimiters=(', ', ' '), section_name_surroundings=None, section_override_delimiters=('.', ), unsavable_keys=('save', ))

Bases: pyprint.ClosableObject.ClosableObject

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

coalib.output.ConsoleInteraction module

coalib.output.ConsoleInteraction.acquire_actions_and_apply(console_printer, log_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.
  • log_printer – Printer responsible for logging the messages.
  • 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)

This method prompts the user for the given settings.

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.

    Example:

{"UseTabs": ["describes whether tabs should be used instead of spaces",
             "SpaceConsistencyBear",
             "SomeOtherBear"]}
Returns:a dictionary with the settings name as key and the given value as value.
coalib.output.ConsoleInteraction.ask_for_action_and_apply(log_printer, 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:
  • log_printer – Printer responsible for logging the messages.
  • 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 its 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)

Get 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.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 touple 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, section, result, file_dict, color=True)

Print all the afected files and affected lines within them.

Parameters:
  • console_printer – Object to print messages on the console.
  • 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.
  • color – Boolean variable to print the results in color or not. Can be used for testing.
coalib.output.ConsoleInteraction.print_affected_lines(console_printer, file_dict, section, sourcerange)
coalib.output.ConsoleInteraction.print_bears(console_printer, bears, compress)

Presents all bears being used in a stylized manner.

Parameters:
  • console_printer – Object to print messages on the console.
  • bears – Its a dictionary with bears as keys and list of sections containing those bears as values.
  • compress – If set to true, output will be compressed (just show bear names as a list)
coalib.output.ConsoleInteraction.print_lines(console_printer, file_dict, section, 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, log_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.
  • log_printer – Printer responsible for logging the messages.
  • 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, color=True)

Print 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.
  • color – Boolean variable to print the results in color or not. Can be used for testing.
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, color=True)

Print 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.
  • color – Boolean variable to print the results in color or not. Can be used for testing.
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.print_spaces_tabs_in_unicode(console_printer, line, tab_dict, color, index=0)

Prints the lines with tabs and spaces replaced by unicode symbols.

Parameters:
  • console_printer – The Printer object to print to.
  • line – The line-text to print to console_printer.
  • tab_dict – A dictionary containing the indices of tabs inside line as keys and the tab-length as values.
  • color – The color to print the line with (except for spaces and tabs.
  • index – The index from where to start the printing.
coalib.output.ConsoleInteraction.require_setting(log_printer, setting_name, arr)

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

Parameters:
  • log_printer – Printer responsible for logging the messages.
  • setting_name – Name od 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.
coalib.output.ConsoleInteraction.show_bear(console_printer, bear, sections, metadata)

Display all information about a bear.

Parameters:
  • console_printer – Object to print messages on the console.
  • bear – The bear to be displayed.
  • sections – The sections to which the bear belongs.
  • metadata – Metadata about the bear.
coalib.output.ConsoleInteraction.show_bears(local_bears, global_bears, compress, 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.
  • compress – If set to true, output will be compressed (just show bear names as a list)
  • show_bears_callback – The callback that is used to print these bears. It will get one parameter holding bears as key and the list of section names where it’s used as values.
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 in a stylized format. If the iterable object is empty, it prints a specific statement give 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.Interactions module

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

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)

coalib.output.Tagging module

coalib.output.Tagging.delete_tagged_results(tag, project, log_printer)

Deletes previously tagged results.

Parameters:
  • tag – The tag name.
  • project – Path to the coafile the results belong to.
  • log_printer – The logger which logs errors.
coalib.output.Tagging.get_tag_path(tag, project, log_printer)

Creates a hash value that is used for tagging and creates a path for it.

Parameters:
  • tag – The name for the tag.
  • project – The related coafile.
  • log_printer – The logger which logs errors.
Returns:

A path containing a hash as filename that identifies the given parameters.

coalib.output.Tagging.get_tags_dir(log_printer)
coalib.output.Tagging.load_tagged_results(tag, project, log_printer)

Retrieves results previously stored with tag_results.

Parameters:
  • tag – The tag name.
  • project – Path to the coafile the results belong to.
  • log_printer – The logger which logs errors.
Returns:

A results dictionary, as generated by coala.

coalib.output.Tagging.tag_results(tag, project, results, log_printer)

This method takes a tag provided from the user and saves the results dictionary output by coala to a file. That file is uniquely identified by the combined hash of the project (i.e. coafile) and the provided tag.

Parameters:
  • tag – Tag provided by user.
  • project – Path to the coafile the results belong to.
  • log_printer – The logger which logs errors.
  • results – Results dictionary generated by coala.

Module contents