Example #1
0
def parse_describe_changelist(text):
    if isinstance(text, str):
        output = text.split("\n")
    else:
        output = text

    first = output.pop(0)
    m = re.search(
        "Change (?P<number>[0-9]+) by (?P<user>[^@]+)@(?P<workspace>[^ ]+) on (?P<datestr>[0-9/]+ [0-9:]+) *(?P<pending>\*pending\*)?",
        first)
    if not m:
        print(output)
        raise Exception("Unable to parse line " + first)

    changelist = Changelist(**m.groupdict())

    output = skip_blank_lines(output)
    # print("\n".join(output))
    description, output = read_tabbed(output)
    changelist.description = "\n".join(description)

    output = skip_blank_lines(output)
    while output:
        title = output.pop(0)
        if "Affected files" in title:
            output = skip_blank_lines(output)
            files, output = read_until_blank(output)
            changelist.affected_files = parse_files(files)
        elif "Shelved files" in title:
            output = skip_blank_lines(output)
            files, output = read_until_blank(output)
            changelist.shelved_files = parse_files(files)
        elif title.startswith("Differences ..."):
            output = skip_blank_lines(output)
            changelist.differences = output
            output = []

    streams = set()
    if changelist.affected_files:
        for f in changelist.affected_files:
            path = f[0].split("/")
            stream_path = "/".join(path[:4])
            streams.add(stream_path)

    if changelist.shelved_files:
        for f in changelist.shelved_files:
            path = f[0].split("/")
            stream_path = "/".join(path[:4])
            streams.add(stream_path)

    changelist.stream = list(streams)

    return changelist
Example #2
0
def test_read_until_blank4():
    assert parser.read_until_blank(["a", "b", "\t",
                                    "c"]) == (["a", "b"], ["\t", "c"])
Example #3
0
def test_read_until_blank3():
    assert parser.read_until_blank(["a"]) == (["a"], [])
Example #4
0
def test_read_until_blank2():
    assert parser.read_until_blank([" "]) == ([], [" "])
Example #5
0
def test_read_until_blank1():
    assert parser.read_until_blank([]) == ([], [])