import re


def _read_pre_post_file(filename):
    """ Read the combined pre/post commands file.

    Arguments
    ---------
    filename: str
        Path to pre/post commands file.

    Returns
    -------
    str:
        Pre-commands split up per line.
    str:
        Post-commands split up per line.
    """
    pre_lines = ""
    post_lines = ""
    cur_position = "pre"
    with open(filename, "r") as f:
        for line in f:
            # Check for switching or pre/post commands.
            if re.match(r"## PRE_COMMANDS ##*", line):
                cur_position = "pre"
            elif re.match(r"## POST_COMMANDS ##*", line):
                cur_position = "post"
            else:
                if cur_position == "pre":
                    pre_lines += line
                else:
                    post_lines += line

    return (pre_lines, post_lines)