# Path: heatclient/_i18n.py
# def get_available_languages():
# def enable_lazy():
# 
# Path: heatclient/common/utils.py
# LOG = logging.getLogger(__name__)
# def arg(*args, **kwargs):
#     def _decorator(func):
# def env(*args, **kwargs):
# def add_arg(func, *args, **kwargs):
# def print_list(objs, fields, formatters=None, sortby_index=0,
#                mixed_case_fields=None, field_labels=None):
# def link_formatter(links):
#     def format_link(l):
# def resource_nested_identifier(rsrc):
# def json_formatter(js):
# def yaml_formatter(js):
# def text_wrap_formatter(d):
# def newline_list_formatter(r):
# def print_dict(d, formatters=None):
#     def __init__(self):
#     def prepend_paths(self, resource_path, stack_id):
#     def build_resource_name(self, event):
#         def get_stack_id():
# def event_log_formatter(events, event_log_context=None):
# def print_update_list(lst, fields, formatters=None):
# def find_resource(manager, name_or_id):
# def format_parameters(params, parse_semicolon=True):
# def format_all_parameters(params, param_files,
#                           template_file=None, template_url=None):
# def format_parameter_file(param_files, template_file=None,
#                           template_url=None):
# def resolve_param_get_file(file, base_url):
# def format_output(output, format='yaml'):
# def parse_query_url(url):
# def get_template_url(template_file=None, template_url=None):
# def read_url_content(url):
# def base_url_for_url(url):
# def normalise_file_path_to_url(path):
# def get_response_body(resp):
# class EventLogContext(object):
# 
# Path: heatclient/v1/events.py
# DEFAULT_PAGE_SIZE = 20
# class Event(base.Resource):
# class EventManager(stacks.StackChildManager):
#     def __repr__(self):
#     def update(self, **fields):
#     def delete(self):
#     def data(self, **kwargs):
#     def list(self, stack_id, resource_name=None, **kwargs):
#     def get(self, stack_id, resource_name, event_id):


import sys
import time
import heatclient.exc as exc
from heatclient._i18n import _
from heatclient.common import utils
from heatclient.v1 import events as events_mod
def _get_stack_events(hc, stack_id, event_args):
    event_args['stack_id'] = stack_id
    try:
        events = hc.events.list(**event_args)
    except exc.HTTPNotFound as ex:
        # it could be the stack or resource that is not found
        # just use the message that the server sent us.
        raise exc.CommandError(str(ex))
    else:
        stack_name = stack_id.split("/")[0]
        # Show which stack the event comes from (for nested events)
        for e in events:
            e.stack_name = _get_stack_name_from_links(e) or stack_name
        return events


def poll_for_events(hc, stack_name, action=None, poll_period=5, marker=None,
                    out=None, nested_depth=0):
    """Continuously poll events and logs for performed action on stack."""

    if action:
        stop_status = ('%s_FAILED' % action, '%s_COMPLETE' % action)
        stop_check = lambda a: a in stop_status  # noqa: E731
    else:
        stop_check = lambda a: a.endswith('_COMPLETE') or a.endswith('_FAILED')  # noqa E731

    no_event_polls = 0
    msg_template = _("\n Stack %(name)s %(status)s \n")
    if not out:
        out = sys.stdout

# Path: heatclient/_i18n.py
# def get_available_languages():
# def enable_lazy():
# 
# Path: heatclient/common/utils.py
# LOG = logging.getLogger(__name__)
# def arg(*args, **kwargs):
#     def _decorator(func):
# def env(*args, **kwargs):
# def add_arg(func, *args, **kwargs):
# def print_list(objs, fields, formatters=None, sortby_index=0,
#                mixed_case_fields=None, field_labels=None):
# def link_formatter(links):
#     def format_link(l):
# def resource_nested_identifier(rsrc):
# def json_formatter(js):
# def yaml_formatter(js):
# def text_wrap_formatter(d):
# def newline_list_formatter(r):
# def print_dict(d, formatters=None):
#     def __init__(self):
#     def prepend_paths(self, resource_path, stack_id):
#     def build_resource_name(self, event):
#         def get_stack_id():
# def event_log_formatter(events, event_log_context=None):
# def print_update_list(lst, fields, formatters=None):
# def find_resource(manager, name_or_id):
# def format_parameters(params, parse_semicolon=True):
# def format_all_parameters(params, param_files,
#                           template_file=None, template_url=None):
# def format_parameter_file(param_files, template_file=None,
#                           template_url=None):
# def resolve_param_get_file(file, base_url):
# def format_output(output, format='yaml'):
# def parse_query_url(url):
# def get_template_url(template_file=None, template_url=None):
# def read_url_content(url):
# def base_url_for_url(url):
# def normalise_file_path_to_url(path):
# def get_response_body(resp):
# class EventLogContext(object):
# 
# Path: heatclient/v1/events.py
# DEFAULT_PAGE_SIZE = 20
# class Event(base.Resource):
# class EventManager(stacks.StackChildManager):
#     def __repr__(self):
#     def update(self, **fields):
#     def delete(self):
#     def data(self, **kwargs):
#     def list(self, stack_id, resource_name=None, **kwargs):
#     def get(self, stack_id, resource_name, event_id):


# Path: heatclient/common/event_utils.py
import sys
import time
import heatclient.exc as exc
from heatclient._i18n import _
from heatclient.common import utils
from heatclient.v1 import events as events_mod

def _get_stack_events(hc, stack_id, event_args):
    event_args['stack_id'] = stack_id
    try:
        events = hc.events.list(**event_args)
    except exc.HTTPNotFound as ex:
        # it could be the stack or resource that is not found
        # just use the message that the server sent us.
        raise exc.CommandError(str(ex))
    else:
        stack_name = stack_id.split("/")[0]
        # Show which stack the event comes from (for nested events)
        for e in events:
            e.stack_name = _get_stack_name_from_links(e) or stack_name
        return events


def poll_for_events(hc, stack_name, action=None, poll_period=5, marker=None,
                    out=None, nested_depth=0):
    """Continuously poll events and logs for performed action on stack."""

    if action:
        stop_status = ('%s_FAILED' % action, '%s_COMPLETE' % action)
        stop_check = lambda a: a in stop_status  # noqa: E731
    else:
        stop_check = lambda a: a.endswith('_COMPLETE') or a.endswith('_FAILED')  # noqa E731

    no_event_polls = 0
    msg_template = _("\n Stack %(name)s %(status)s \n")
    if not out:
        out = sys.stdout

    event_log_context = utils.EventLogContext()