splits _sources/reference.rst into separate files
()
| 5 | |
| 6 | |
| 7 | def preprocess(): |
| 8 | "splits _sources/reference.rst into separate files" |
| 9 | |
| 10 | text = open("./_sources/reference.rst", "r").read() |
| 11 | os.remove("./_sources/reference.rst") |
| 12 | |
| 13 | if not os.path.exists("./_sources/reference"): |
| 14 | os.makedirs("./_sources/reference") |
| 15 | |
| 16 | def pairwise(iterable): |
| 17 | "s -> (s0, s1), (s2, s3), (s4, s5), ..." |
| 18 | |
| 19 | iteration = iter(iterable) |
| 20 | return izip(iteration, iteration) |
| 21 | |
| 22 | sections = map(str.strip, re.split(r"<!--\s*(.+)\s*-->", text)) |
| 23 | for section, content in pairwise(sections[1:]): |
| 24 | if section.endswith(".proto"): |
| 25 | section_name = section[: -len(".proto")] |
| 26 | file_name = "./_sources/reference/{0}.rst".format(section_name) |
| 27 | with open(file_name, "w") as f: |
| 28 | f.truncate() |
| 29 | f.write(content) |
| 30 | f.close() |
| 31 | |
| 32 | |
| 33 | if __name__ == "__main__": |