-
Notifications
You must be signed in to change notification settings - Fork 6
/
install_tech.py
51 lines (41 loc) · 1.38 KB
/
install_tech.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Symlink tech to klayout."""
import os
import pathlib
import shutil
import sys
def remove_path_or_dir(dest: pathlib.Path):
"""Remove a path or directory."""
if dest.is_dir():
os.unlink(dest)
else:
os.remove(dest)
def make_link(src, dest, overwrite: bool = True) -> None:
"""Make a symbolic link from src to dest."""
dest = pathlib.Path(dest)
if not src.exists():
raise FileNotFoundError(f"{src} does not exist")
if dest.exists() and not overwrite:
print(f"{dest} already exists")
return
if dest.exists() or dest.is_symlink():
print(f"removing {dest} already installed")
remove_path_or_dir(dest)
try:
os.symlink(src, dest, target_is_directory=True)
except OSError:
shutil.copytree(src, dest)
print("link made:")
print(f"From: {src}")
print(f"To: {dest}")
if __name__ == "__main__":
klayout_folder = "KLayout" if sys.platform == "win32" else ".klayout"
cwd = pathlib.Path(__file__).resolve().parent
home = pathlib.Path.home()
dest_folder = home / klayout_folder / "tech"
dest_folder.mkdir(exist_ok=True, parents=True)
src = cwd / "cspdk" / "si220" / "klayout"
dest = dest_folder / "cspdk_si220"
make_link(src=src, dest=dest)
src = cwd / "cspdk" / "sin300" / "klayout"
dest = dest_folder / "cspdk_sin300"
make_link(src=src, dest=dest)