forked from OBOFoundry/OBOFoundry.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk_domain_rename.py
37 lines (26 loc) · 943 Bytes
/
bulk_domain_rename.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""This script bulk renames a given domain.
Run with: ``python bulk_domain_rename.py <old> <new>``.
Author: `Charles Tapley Hoyt <https://cthoyt.com>`_.
"""
import pathlib
import click
HERE = pathlib.Path(__file__).parent.resolve()
ONTOLOGY_DIRECTORY = HERE.parent.joinpath("ontology").resolve()
@click.command()
@click.argument("old_label")
@click.argument("new_label")
def main(old_label: str, new_label: str):
"""Rename domains across all ontologies."""
old_line = f"domain: {old_label}"
new_line = f"domain: {new_label}"
for path in ONTOLOGY_DIRECTORY.glob("*.md"):
with path.open() as file:
lines = [line.rstrip("\n") for line in file]
with path.open("w") as file:
for line in lines:
if line == old_line:
print(new_line, file=file)
else:
print(line, file=file)
if __name__ == "__main__":
main()