import re


def parse_remote_msg(msg):
    """ Figure out the different components of the output of the remote script.

    Arguments
    ---------
    msg: str
        Unicode string that encodes the output.

    Returns
    -------
    error_msg: str
        List of error messages, empty list means no errors.
    exec_line: str
        Line to execute on remote (anything not starting with #/*/Error
    info_msg: str
        Anything starting with asterixes (*)
    """
    msg = msg.split("\n")
    exec_line = ""
    info_msg = ""
    error_msg = []
    for line in msg:
        sw_hash = re.match(r'^#', line) is not None
        sw_asterix = re.match(r'^\*', line) is not None
        sw_error = re.match(r'^Error', line) is not None
        if sw_asterix:
            info_msg += line+"\n"
        elif line == "" or sw_hash:
            pass
        elif sw_error:
            error_msg.append(line)
        else:
            exec_line += line

    return error_msg, exec_line, info_msg