Beispiel #1
0
def write(var, output_format="str", no_colour=True):
    """
    Writes ``var`` to stdout. If output_format is set to "json" or "yaml",
    write ``var`` as a JSON or YAML string.

    :param var: The object to print
    :type var: obj
    :param output_format: The format to print the output as. Allowed values: \
    "str", "json", "yaml"
    :type output_format: str
    :param no_colour: Whether to colour stack statuses
    :type no_colour: bool
    """
    stream = var

    if output_format == "json":
        encoder = CustomJsonEncoder(indent=4)
        stream = encoder.encode(var)
    if output_format == "yaml":
        stream = yaml.safe_dump(var, default_flow_style=False)
    if output_format == "str":
        stream = var
    if not no_colour:
        stack_status_colourer = StackStatusColourer()
        stream = stack_status_colourer.colour(stream)

    click.echo(stream)
Beispiel #2
0
def write(var, output_format="text", no_colour=True):
    """
    Writes ``var`` to stdout. If output_format is set to "json" or "yaml",
    write ``var`` as a JSON or YAML string.

    :param var: The object to print
    :type var: obj
    :param output_format: The format to print the output as. Allowed values: \
    "text", "json", "yaml"
    :type output_format: str
    :param no_colour: Whether to colour stack statuses
    :type no_colour: bool
    """
    output = var

    if output_format == "json":
        output = _generate_json(var)
    if output_format == "yaml":
        output = _generate_yaml(var)
    if output_format == "text":
        output = var
    if not no_colour:
        stack_status_colourer = StackStatusColourer()
        output = stack_status_colourer.colour(str(output))

    click.echo(output)
Beispiel #3
0
class ColouredFormatter(logging.Formatter):
    """
    ColouredFormatter add colours to all stack statuses that appear in log
    messages.
    """

    stack_status_colourer = StackStatusColourer()

    def format(self, record):
        """
        Colours and returns all stack statuses in ``record``.

        :param record: The log item to format.
        :type record: str
        :returns: str
        """
        response = super(ColouredFormatter, self).format(record)
        coloured_response = self.stack_status_colourer.colour(response)
        return coloured_response
 def setup_method(self, test_method):
     init()
     self.stack_status_colourer = StackStatusColourer()
     self.statuses = {
         "CREATE_COMPLETE": Fore.GREEN,
         "CREATE_FAILED": Fore.RED,
         "CREATE_IN_PROGRESS": Fore.YELLOW,
         "DELETE_COMPLETE": Fore.GREEN,
         "DELETE_FAILED": Fore.RED,
         "DELETE_IN_PROGRESS": Fore.YELLOW,
         "ROLLBACK_COMPLETE": Fore.RED,
         "ROLLBACK_FAILED": Fore.RED,
         "ROLLBACK_IN_PROGRESS": Fore.YELLOW,
         "UPDATE_COMPLETE": Fore.GREEN,
         "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS": Fore.YELLOW,
         "UPDATE_FAILED": Fore.RED,
         "UPDATE_IN_PROGRESS": Fore.YELLOW,
         "UPDATE_ROLLBACK_COMPLETE": Fore.GREEN,
         "UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS": Fore.YELLOW,
         "UPDATE_ROLLBACK_FAILED": Fore.RED,
         "UPDATE_ROLLBACK_IN_PROGRESS": Fore.YELLOW
     }