import re


def parse_show_platform(desired_states, cmd_output):
    """
    Parse output of 'show platform'
    :param desired_states: Set of one or more LC state that is desired. That is, is_complete will return true
                           only if all LCs are in any of the desired states.
    :param cmd_output: an iterable of lines (str) from the command output
    :return: (is_complete, is_success) tuple of bool. is_complete indicates whether the request completed,
             is_success indicates whether it was successful.
    """
    line_regex = re.compile(
        r'(?P<node>\d+/\S+)'
        r'\s+(?P<lc>[a-zA-Z0-9\-]+)(?:\((?P<redundancy_state>[a-zA-Z]+)\))?(?:\s+(?P<plim>[a-zA-Z/]+))?'
        r'\s+(?P<state>(IOS XR RUN|OK|OPERATIONAL|FPD_UPGRADE|BOOTING|PLATFORM INITIALIZED|SHUTTING DOWN|CARD_ACCESS_DOWN|ONLINE|DATA PATH POWERED ON)+)'
        r'\s+(?P<config_state>[a-zA-Z,]+)$'
    )

    is_complete = False
    num_matches = 0
    for cmd_line in cmd_output:
        match = line_regex.match(cmd_line)
        if match:
            num_matches += 1
            if match.group('state') not in desired_states:
                break
    else:
        is_complete = True

    return is_complete, num_matches > 0