<commit_before># Copyright (C) 2013 SignalFuse, Inc.
#
# Docker container orchestration utility.

import json
import sys
import time

from . import exceptions


# Some utility functions for output.
def color(cond):
    """Returns 32 (green) or 31 (red) depending on the validity of the given
    condition."""
    return cond and 32 or 31


def up(cond):
    """Returns 'up' or 'down' depending on the validity of the given
    condition."""
    return cond and 'up' or 'down'


class BaseOrchestrationPlay:
    """Base class for orchestration plays, holds the ordered list containers to
    act on."""

    def __init__(self, containers=[]):
        self._containers = containers

    def run(self):
        raise NotImplementedError


class OutputFormatter:
    """Output formatter for nice, progressive terminal output.

    Manages the output of a progressively updated terminal line, with "in
    progress" labels and a "committed" base label.
    """
    def __init__(self, prefix=None):
        self._committed = prefix

    def commit(self, s=None):
        if self._committed and s:
            self._committed = '{} {}'.format(self._committed, s)
        elif not self._committed and s:
            self._committed = s
        print('{}\033[K\r'.format(self._committed),)
        sys.stdout.flush()

    def pending(self, s):
        if self._committed and s:
            print('{} {}\033[K\r'.format(self._committed, s),)
        elif not self._committed and s:
            print('{}\033[K\r'.format(s),)
        sys.stdout.flush()

    def end(self):
        print()
        sys.stdout.flush()


class FullStatus(BaseOrchestrationPlay):
    """A Maestro orchestration play that displays the status of the given
    services and/or instance containers."""

    def __init__(self, containers=[]):
        BaseOrchestrationPlay.__init__(self, containers)

    def run(self):
        print('{:>3s}  {:<20s} {:<15s} {:<20s} {:<15s} {:<10s}'.format(
            '  #', 'INSTANCE', 'SERVICE', 'SHIP', 'CONTAINER', 'STATUS'))

        for order, container in enumerate(self._containers, 1):
            o = OutputFormatter(<commit_msg>Need to use backports since OutputFormatter needs special functionality<commit_after># Copyright (C) 2013 SignalFuse, Inc.
#
# Docker container orchestration utility.

from __future__ import print_function

import json
import sys
import time

from . import exceptions


# Some utility functions for output.
def color(cond):
    """Returns 32 (green) or 31 (red) depending on the validity of the given
    condition."""
    return cond and 32 or 31


def up(cond):
    """Returns 'up' or 'down' depending on the validity of the given
    condition."""
    return cond and 'up' or 'down'


class BaseOrchestrationPlay:
    """Base class for orchestration plays, holds the ordered list containers to
    act on."""

    def __init__(self, containers=[]):
        self._containers = containers

    def run(self):
        raise NotImplementedError


class OutputFormatter:
    """Output formatter for nice, progressive terminal output.

    Manages the output of a progressively updated terminal line, with "in
    progress" labels and a "committed" base label.
    """
    def __init__(self, prefix=None):
        self._committed = prefix

    def commit(self, s=None):
        if self._committed and s:
            self._committed = '{} {}'.format(self._committed, s)
        elif not self._committed and s:
            self._committed = s
        print('{}\033[K\r'.format(self._committed), end='')
        sys.stdout.flush()

    def pending(self, s):
        if self._committed and s:
            print('{} {}\033[K\r'.format(self._committed, s), end='')
        elif not self._committed and s:
            print('{}\033[K\r'.format(s), end='')
        sys.stdout.flush()

    def end(self):
        print('')
        sys.stdout.flush()


class FullStatus(BaseOrchestrationPlay):
    """A Maestro orchestration play that displays the status of the given
    services and/or instance containers."""

    def __init__(self, containers=[]):
        BaseOrchestrationPlay.__init__(self, containers)

    def run(self):
        print('{:>3s}  {:<20s} {:<15s} {:<20s} {:<15s} {:<10s}'.format(
            '  #', 'INSTANCE', 'SERVICE', 'SHIP', 'CONTAINER', 'STATUS'))

        for order, container in enumerate(self._containers, 1):
            o = OutputFormatter(
{'fraction_non_alphanumeric': 0.12255570713960891, 'fraction_numerical': 0.015006821282401092, 'mean_word_length': 2.86215978928885, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4578112', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1258, 'n_words': 424}