-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpatch_version.py
97 lines (84 loc) · 3.27 KB
/
patch_version.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
import re
import sys
def patch_installer(tag):
"""Patches the installer with the correct connector version and specklepy version"""
iss_file = "speckle-sharp-ci-tools/qgis.iss"
metadata = "metadata.txt"
plugin_start_file = "speckle_qgis.py"
try:
with open(iss_file, "r") as file:
lines = file.readlines()
new_lines = []
for i, line in enumerate(lines):
if "#define AppVersion " in line:
line = f'#define AppVersion "{tag.split("-")[0]}"\n'
if "#define AppInfoVersion " in line:
line = f'#define AppInfoVersion "{tag}"\n'
new_lines.append(line)
with open(iss_file, "w") as file:
file.writelines(new_lines)
print(f"Patched installer with connector v{tag} ")
file.close()
except:
pass
with open(metadata, "r") as file:
lines = file.readlines()
new_lines = []
for i, line in enumerate(lines):
if "version=" in line:
line = f"version={tag}\n" # .split("-")[0]
if "experimental=" in line:
if "-" in tag:
line = f"experimental=True\n" # .split("-")[0]
elif len(tag.split(".")) == 3 and tag != "0.0.99":
line = f"experimental=False\n" # .split("-")[0]
new_lines.append(line)
with open(metadata, "w") as file:
file.writelines(new_lines)
print(f"Patched metadata v{tag} ")
file.close()
with open(plugin_start_file, "r") as file:
lines = file.readlines()
for i, line in enumerate(lines):
if "self.version = " in line:
lines[i] = (
lines[i].split('"')[0]
+ '"'
+ tag.split("-")[0]
+ '"'
+ lines[i].split('"')[2]
)
break
with open(plugin_start_file, "w") as file:
file.writelines(lines)
print(f"Patched GIS start file with connector v{tag} and specklepy ")
file.close()
r"""
def whlFileRename(fileName: str):
with open(fileName, "r") as file:
lines = file.readlines()
for i, line in enumerate(lines):
if "-py3-none-any.whl" in line:
p1 = line.split("-py3-none-any.whl")[0].split("-")[0]
p2 = f'{tag.split("-")[0]}'
p3 = line.split("-py3-none-any.whl")[1]
lines[i] = p1+"-"+p2+"-py3-none-any.whl"+p3
with open(fileName, "w") as file:
file.writelines(lines)
print(f"Patched toolbox_installer with connector v{tag} and specklepy ")
file.close()
whlFileRename(conda_file)
whlFileRename(toolbox_install_file)
whlFileRename(toolbox_manual_install_file)
"""
def main():
if len(sys.argv) < 2:
return
tag = sys.argv[1]
if not re.match(r"([0-9]+)\.([0-9]+)\.([0-9]+)", tag):
raise ValueError(f"Invalid tag provided: {tag}")
print(f"Patching version: {tag}")
# patch_connector(tag.split("-")[0]) if I need to edit a connector file
patch_installer(tag)
if __name__ == "__main__":
main()