formatting.py

Bladerunner output formatting functions.

This file is part of Bladerunner.

Copyright (c) 2014, Activision Publishing, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Activision Publishing, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class bladerunner.formatting.FakeStdOut[source]

An object to pass to pexpect’s debug logger to simulate sys.stdout.

static flush()[source]

Fake flush, print will flush.

static write(string)[source]

Fake write, use print instead.

bladerunner.formatting.consolidate(results)[source]

Makes a list of servers and replies, consolidates dupes.

Args:
results: the results dictionary from Bladerunner.run
Returns:
a results dictionary, with a names key instead of name, containing a lists of hosts with matching outputs
bladerunner.formatting.csv_results(results, options=None)[source]

Prints the results consolidated and in a CSV-ish fashion.

Args:

results: the results dictionary from Bladerunner.run
options: dictionary with optional keys:
    csv_char: a character or string to separate with
bladerunner.formatting.format_line(line, options=None)[source]

Removes whitespace, weird tabs, etc...

Args:

line: string line to clean
options: dictionary of Bladerunner options
bladerunner.formatting.format_output(output, command, options=None)[source]

Formatting function to strip colours, remove tabs, etc.

Args:

output: the pexpect object's before method after issuing the command
command: the command last issued
options: dictionary of Bladerunner options
Returns:
a (hopefully) nicely formatted string of the command’s output
bladerunner.formatting.no_empties(input_list)[source]

Searches through a list and tosses empty elements.

bladerunner.formatting.prepare_results(results, options=None)[source]

Prepare the results and options dictionary for pretty printing.

Args:

results: the bladerunner result dictionary
options: the bladerunner options dictionary
Returns:
a tuple of (results, options) after modifying the keys for printing
bladerunner.formatting.pretty_header(options)[source]

Internal function for printing the header of pretty_results.

Args:

options: a dictionary with the following keys:
    width: terminal width, already determined in pretty_results
    chars: the character dictionary map, defined in pretty_results
    left_len: the left side length, defined in pretty_results
    jump_host: a string hostname of the jumpbox (if any)
bladerunner.formatting.pretty_results(results, options=None)[source]

Prints the results in a relatively pretty way.

Args:

results: the results dictionary from Bladerunner.run
options: a dictionary with optional keys.
    style: integer style, from 0-3
    jump_host: the string jumpbox hostname
    width: integer fixed width for output
bladerunner.formatting.stacked_results(results, options=None)[source]

Display the results in a vertical stack without a frame.

Args:

results: the bladerunner result dictionary
options: the bladerunner options dictionary
bladerunner.formatting.write(string, options, end='')[source]

Writes a line of output to either the output file or stdout.

Args:

string: the string to write out
options: the options dictionary, uses 'output_file' key only
end: character or empty string to end the print statement with

Previous topic

cmdline.py

Next topic

interactive.py

This Page