# Path: awscfncli2/cli/utils/colormaps.py
# CHANGESET_STATUS_TO_COLOR = ColorMap(_CHANGESET_STATUS_TO_COLOR)
# 
# CHANGESET_ACTION_TO_COLOR = ColorMap(_CHANGESET_ACTION_TO_COLOR)
# 
# CHANGESET_REPLACEMENT_TO_COLOR = ColorMap(_CHANGESET_REPLACEMENT_TO_COLOR)
# 
# DRIFT_STATUS_TO_COLOR = ColorMap(_DRIFT_STATUS_TO_COLOR)
# 
# STACK_STATUS_TO_COLOR = ColorMap(_STACK_STATUS_TO_COLOR)
# 
# CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR = ColorMap(
#     _CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR)
# 
# Path: awscfncli2/cli/utils/common.py
# def is_rate_limited_exception(e):
#     if isinstance(e, (botocore.exceptions.ClientError, botocore.exceptions.WaiterError)):
#         return 'Rate exceeded' in str(e)
#     else:
#         return False
# 
# def is_not_rate_limited_exception(e):
#     return not is_rate_limited_exception(e)
# 
# Path: awscfncli2/cli/utils/events.py
# def start_tail_stack_events_daemon(session,
#                                    stack,
#                                    latest_events=1,
#                                    event_limit=10000,
#                                    time_limit=3600,
#                                    check_interval=5,
#                                    indent=0,
#                                    prefix=None):
#     """Start tailing stack events"""
# 
#     # TODO: Now this causes AWS throttling boto3 call if the tracking stack
#     #       contains a lot of nested stacks and/or long update history.
#     #       Should implement a barrier on how many querys are being sent
#     #       concurrently.
# 
#     thread = threading.Thread(target=tail_stack_events,
#                               args=(session,
#                                     stack, latest_events, event_limit,
#                                     time_limit, check_interval,
#                                     indent, prefix))
#     thread.daemon = True
#     thread.start()
# 
# Path: awscfncli2/cli/utils/pager.py
# def custom_paginator(f, l, **kwargs):
#     """Simple custom paginator for those can_pageniate() returns false
#     :param f: API function
#     :param l: name of the list object to paginate
#     :param kwargs: Args passes to the API function
#     :return: iterator of result object
#     """
#     next_token = None
#     while True:
# 
#         if next_token is None:
#             # boto3 does not accept f(NextToken=None)
#             r = f(**kwargs)
#         else:
#             r = f(NextToken=next_token, **kwargs)
# 
#         for i in r[l]:
#             yield i
# 
#         try:
#             next_token = r['NextToken']
#         except KeyError:
#             break


import difflib
import json
import backoff
import botocore.exceptions
import click
import yaml
from .colormaps import CHANGESET_STATUS_TO_COLOR, CHANGESET_ACTION_TO_COLOR, \
    CHANGESET_REPLACEMENT_TO_COLOR, DRIFT_STATUS_TO_COLOR, \
    STACK_STATUS_TO_COLOR, CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR
from .common import is_rate_limited_exception, is_not_rate_limited_exception
from .events import start_tail_stack_events_daemon
from .pager import custom_paginator
                    click.secho('--- end of {} ---'.format(k), fg='white',
                                dim=True)

    def pprint_stack(self, stack, status=False):
        """Pretty print stack status"""
        # echo_pair('StackName', stack.stack_name)
        if status:
            echo_pair('Status', stack.stack_status,
                      value_style=STACK_STATUS_TO_COLOR[stack.stack_status])

        if stack.stack_status == 'STACK_NOT_FOUND':
            return

        echo_pair('StackID', stack.stack_id)
        # echo_pair('Description', stack.description)
        echo_pair('Created', stack.creation_time)
        if stack.last_updated_time:
            echo_pair('Last Updated', stack.last_updated_time)
        if stack.capabilities:
            echo_pair('Capabilities', ', '.join(stack.capabilities),
                      value_style={'fg': 'yellow'})
        echo_pair('TerminationProtection',
                  str(stack.enable_termination_protection),
                  value_style={
                      'fg': 'red'} if stack.enable_termination_protection else None
                  )

        drift_status = stack.drift_information['StackDriftStatus']
        drift_timestamp = stack.drift_information.get('LastCheckTimestamp')
        echo_pair('Drift Status', drift_status,

# Path: awscfncli2/cli/utils/colormaps.py
# CHANGESET_STATUS_TO_COLOR = ColorMap(_CHANGESET_STATUS_TO_COLOR)
# 
# CHANGESET_ACTION_TO_COLOR = ColorMap(_CHANGESET_ACTION_TO_COLOR)
# 
# CHANGESET_REPLACEMENT_TO_COLOR = ColorMap(_CHANGESET_REPLACEMENT_TO_COLOR)
# 
# DRIFT_STATUS_TO_COLOR = ColorMap(_DRIFT_STATUS_TO_COLOR)
# 
# STACK_STATUS_TO_COLOR = ColorMap(_STACK_STATUS_TO_COLOR)
# 
# CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR = ColorMap(
#     _CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR)
# 
# Path: awscfncli2/cli/utils/common.py
# def is_rate_limited_exception(e):
#     if isinstance(e, (botocore.exceptions.ClientError, botocore.exceptions.WaiterError)):
#         return 'Rate exceeded' in str(e)
#     else:
#         return False
# 
# def is_not_rate_limited_exception(e):
#     return not is_rate_limited_exception(e)
# 
# Path: awscfncli2/cli/utils/events.py
# def start_tail_stack_events_daemon(session,
#                                    stack,
#                                    latest_events=1,
#                                    event_limit=10000,
#                                    time_limit=3600,
#                                    check_interval=5,
#                                    indent=0,
#                                    prefix=None):
#     """Start tailing stack events"""
# 
#     # TODO: Now this causes AWS throttling boto3 call if the tracking stack
#     #       contains a lot of nested stacks and/or long update history.
#     #       Should implement a barrier on how many querys are being sent
#     #       concurrently.
# 
#     thread = threading.Thread(target=tail_stack_events,
#                               args=(session,
#                                     stack, latest_events, event_limit,
#                                     time_limit, check_interval,
#                                     indent, prefix))
#     thread.daemon = True
#     thread.start()
# 
# Path: awscfncli2/cli/utils/pager.py
# def custom_paginator(f, l, **kwargs):
#     """Simple custom paginator for those can_pageniate() returns false
#     :param f: API function
#     :param l: name of the list object to paginate
#     :param kwargs: Args passes to the API function
#     :return: iterator of result object
#     """
#     next_token = None
#     while True:
# 
#         if next_token is None:
#             # boto3 does not accept f(NextToken=None)
#             r = f(**kwargs)
#         else:
#             r = f(NextToken=next_token, **kwargs)
# 
#         for i in r[l]:
#             yield i
# 
#         try:
#             next_token = r['NextToken']
#         except KeyError:
#             break


# Path: awscfncli2/cli/utils/pprint.py
import difflib
import json
import backoff
import botocore.exceptions
import click
import yaml
from .colormaps import CHANGESET_STATUS_TO_COLOR, CHANGESET_ACTION_TO_COLOR, \
    CHANGESET_REPLACEMENT_TO_COLOR, DRIFT_STATUS_TO_COLOR, \
    STACK_STATUS_TO_COLOR, CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR
from .common import is_rate_limited_exception, is_not_rate_limited_exception
from .events import start_tail_stack_events_daemon
from .pager import custom_paginator

                    click.secho('--- end of {} ---'.format(k), fg='white',
                                dim=True)

    def pprint_stack(self, stack, status=False):
        """Pretty print stack status"""
        # echo_pair('StackName', stack.stack_name)
        if status:
            echo_pair('Status', stack.stack_status,
                      value_style=STACK_STATUS_TO_COLOR[stack.stack_status])

        if stack.stack_status == 'STACK_NOT_FOUND':
            return

        echo_pair('StackID', stack.stack_id)
        # echo_pair('Description', stack.description)
        echo_pair('Created', stack.creation_time)
        if stack.last_updated_time:
            echo_pair('Last Updated', stack.last_updated_time)
        if stack.capabilities:
            echo_pair('Capabilities', ', '.join(stack.capabilities),
                      value_style={'fg': 'yellow'})
        echo_pair('TerminationProtection',
                  str(stack.enable_termination_protection),
                  value_style={
                      'fg': 'red'} if stack.enable_termination_protection else None
                  )

        drift_status = stack.drift_information['StackDriftStatus']
        drift_timestamp = stack.drift_information.get('LastCheckTimestamp')
        echo_pair('Drift Status', drift_status,

                  value_style=DRIFT_STATUS_TO_COLOR[drift_status])