import re


def _xfsdump_output(data):
    """
    Parse CLI output of the xfsdump utility.
    """
    out = {}
    summary = []
    summary_block = False

    for line in [l.strip() for l in data.split("\n") if l.strip()]:
        line = re.sub("^xfsdump: ", "", line)
        if line.startswith("session id:"):
            out["Session ID"] = line.split(" ")[-1]
        elif line.startswith("session label:"):
            out["Session label"] = re.sub("^session label: ", "", line)
        elif line.startswith("media file size"):
            out["Media size"] = re.sub(r"^media file size\s+", "", line)
        elif line.startswith("dump complete:"):
            out["Dump complete"] = re.sub(r"^dump complete:\s+", "", line)
        elif line.startswith("Dump Status:"):
            out["Status"] = re.sub(r"^Dump Status:\s+", "", line)
        elif line.startswith("Dump Summary:"):
            summary_block = True
            continue

        if line.startswith(" ") and summary_block:
            summary.append(line.strip())
        elif not line.startswith(" ") and summary_block:
            summary_block = False

    if summary:
        out["Summary"] = " ".join(summary)

    return out