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
def test_skip_blank_lines2(): expected = [" a", "b", "", " "] input = [" ", "\t", "\n"] + expected output = parser.skip_blank_lines(input) assert expected == output
def test_skip_blank_lines1(): input = ["a", "b", "", " "] output = parser.skip_blank_lines(input) assert input == output
def test_skip_blank_lines4(): assert parser.skip_blank_lines(["", "# Comment", " \t # Another", "x"]) == ["x"]
def test_skip_blank_lines3(): assert parser.skip_blank_lines([]) == []