-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_helper.py
111 lines (72 loc) · 4.46 KB
/
update_helper.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import sys
import os
import shutil
# Move to using similar to any(ext in name for ext in [".asy", ".lib"])
# for all types of lib and asy..
is_file = lambda name: any(ext in name for ext in [".asy", ".lib", ".asc"])
if __name__=="__main__":
if sys.argv[1] == "--update-symlinks":
LTSPICE_LIB_PATH = sys.argv[2]
os.makedirs(LTSPICE_LIB_PATH+"/sym/qnn-spice", exist_ok=True)
os.makedirs(LTSPICE_LIB_PATH+"/sub/qnn-spice", exist_ok=True)
files_asy = []
files_lib = []
if os.path.exists("models.md"):
models = open("models.md", "r").read()
last_dir = []
dest_dir = []
last_dir_size = [-1]
for line in models.split("\n"):
indents = (len(line) - len(line.lstrip()))
try:
loc = line.split("- ")[1].split(":")[0]
if ":" in line:
name = line.split("- ")[1].split(":")[1].lstrip().rstrip()
path = line.split("- ")[1].split(":")[0].lstrip().rstrip()
elif is_file(line):
if ":" in line:
name = line.split("- ")[1].split(":")[1].rstrip().lstrip()
path = line.split("- ")[1].split(":")[0].rstrip().lstrip()
else:
name = line.split("- ")[1].rstrip().lstrip()
path = name
else:
name = "."
path = line.split("- ")[1].lstrip().rstrip()
if not is_file(name):
while indents < last_dir_size[-1]:
last_dir = last_dir[:-1]
dest_dir = dest_dir[:-1]
last_dir_size = last_dir_size[:-1]
if indents == last_dir_size[-1]:
last_dir[-1] = path+"/"
dest_dir[-1] = name+"/"
else: # indents > prev_indents
last_dir.append(path+"/")
dest_dir.append(name+"/")
last_dir_size.append(indents)
if ".asy" in name: files_asy.append((''.join(last_dir) + path,
(''.join(dest_dir)).replace("./", ""),
name
))
if (".lib" in name or ".asc" in name): files_lib.append((''.join(last_dir) + path,
(''.join(dest_dir)).replace("./", ""),
name
))
except:
print("skipping line:", line)
for src, dest, dest_filename in files_asy:
os.makedirs(LTSPICE_LIB_PATH + "/sym/qnn-spice/" + dest, exist_ok=True)
os.symlink(os.getcwd() + "/" + src, LTSPICE_LIB_PATH + "/sym/qnn-spice/" + dest + dest_filename)
print(" ADDED:", dest_filename)
for src, dest, dest_filename in files_lib:
os.makedirs(LTSPICE_LIB_PATH + "/sub/qnn-spice/" + dest, exist_ok=True)
inner_symlink = LTSPICE_LIB_PATH + "/sub/qnn-spice/" + dest + dest_filename
os.symlink(os.getcwd() + "/" + src, inner_symlink)
outer_symlink = LTSPICE_LIB_PATH + "/sub/" + dest_filename.split("/")[-1]
if os.path.exists(outer_symlink):
os.unlink(outer_symlink)
os.symlink(inner_symlink, outer_symlink)
print(" ADDED:", dest_filename)
else:
print("SKIPPING: NO MODEL FILE IN DIRECTORY")