Repository navigation
Expand file tree
/
Copy pathbuild.py
More file actions
239 lines (189 loc) · 7.98 KB
/
Copy pathbuild.py
File metadata and controls
239 lines (189 loc) · 7.98 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
if __name__ == "__main__":
import requests
import subprocess
import argparse
from zipfile import ZipFile
from pathlib import Path
import webbrowser
from github import Github
import click
import re
def update_init_file(init_file: Path, version: tuple):
with open(init_file, "r") as file:
text = file.read()
version = tuple(version)
str_version = [str(v) for v in version]
matcher = '"name".*:.*,'
name_match = re.findall(matcher, text)
matcher = '"version".*:.*,'
version_match = re.findall(matcher, text)
text = text.replace(name_match[0], f'"name": "Node Pie {".".join(str_version)}",')
text = text.replace(version_match[0], f'"version": {str(version)},')
with open(init_file, "w") as file:
file.write(text)
def update_constants_file(constants_file, value):
with open(constants_file, "r") as file:
text = file.read()
matcher = '__IS_DEV__.*=.*'
name_match = re.findall(matcher, text)
text = text.replace(name_match[0], f'__IS_DEV__ = {str(value)}')
with open(constants_file, "w") as file:
file.write(text)
def update_manifest_file(manifest_file: Path, version: tuple):
with open(manifest_file, 'r') as file:
text = file.read()
version = tuple(version)
matcher = r'^version *= *"\d*.\d*.\d*"'
# print(text)
# matcher = '^version = '
match = re.findall(matcher, text, flags=re.MULTILINE)
str_version = [str(v) for v in version]
text = text.replace(match[0], f'version = \"{".".join(str_version)}\"')
with open(manifest_file, 'w') as file:
file.write(text)
# def multi_input(prompt=""):
# """Get user input over multiple lines. Exit with Ctrl-Z"""
# print(prompt)
# contents = []
# while True:
# try:
# line = input()
# except EOFError:
# break
# contents.append(line)
# return "\n".join(contents)
# def multi_line_input(prompt):
# dark = "#26242f"
# win = tkinter.Tk()
# w = h = 750
# # get screen width and height
# ws = win.winfo_screenwidth() # width of the screen
# hs = win.winfo_screenheight() # height of the screen
# # calculate x and y coordinates for the Tk root window
# x = int((ws/2) - (w/2))
# y = int((hs/2) - (h/2))
# win.geometry(f"{w}x{h}+{x}+{y}")
# win.config(bg=dark)
# def confirm():
# confirm.final_text = text.get("1.0", tkinter.END)
# win.quit()
# label = tkinter.Label(win, text=prompt)
# label.configure(bg=dark, fg="white")
# label.pack()
# button = tkinter.Button(win, text="Confirm", width=20, command=confirm)
# button.pack(side=tkinter.BOTTOM)
# button.configure(bg=dark, fg="white")
# text = tkinter.Text(win,)
# scroll = tkinter.Scrollbar(win)
# text.configure(yscrollcommand=scroll.set, bg=dark, fg="white")
# text.focus_set()
# text.pack(side=tkinter.LEFT, fill=tkinter.BOTH)
# scroll.config(command=text.yview)
# scroll.pack(side=tkinter.RIGHT, fill=tkinter.BOTH)
# win.mainloop()
# return confirm.final_text
# def multi_line_input(prompt):
# ctk.set_appearance_mode("dark")
# ctk.set_default_color_theme("dark-blue")
# win = ctk.CTk()
# w = h = 750
# # get screen width and height
# ws = win.winfo_screenwidth() # width of the screen
# hs = win.winfo_screenheight() # height of the screen
# # calculate x and y coordinates for the Tk root window
# x = int((ws / 2) - (w / 2))
# y = int((hs / 2) - (h / 2))
# win.geometry(f"{w}x{h}+{x}+{y}")
# # win.config(bg=dark)
# def confirm():
# confirm.final_text = textbox.textbox.get("1.0", ctk.END)
# win.quit()
# label = ctk.CTkLabel(win, text=prompt)
# label.pack()
# button = ctk.CTkButton(win, text="Confirm", width=20, command=confirm)
# button.pack(side=ctk.BOTTOM)
# # button.configure(bg=dark, fg="white")
# textbox = ctk.CTkTextbox(win)
# textbox.focus_set()
# textbox.pack(fill=ctk.BOTH, side=ctk.LEFT)
# # scroll = ctk.CTkScrollbar(win)
# # textbox.configure(width=w - scroll.winfo_width() * 20)
# textbox.configure(width=w)
# # textbox.configure(yscrollcommand=scroll.set)
# # scroll.configure(command=textbox.yview)
# # scroll.pack(side=ctk.RIGHT, fill=ctk.BOTH)
# win.mainloop()
# return confirm.final_text
def multi_line_input(prompt: str):
return click.edit(text=prompt, editor="code -w -n", extension=".md")
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-v",
"--version",
help="The version number to use, in the format '0.0.1'",
default="",
type=str,
)
args = parser.parse_args()
ignore = ["images\\", "README", ".gitignore", "build.py", "build.bat", "vendor\\"]
path = Path(__file__).parent
files = [Path(f.decode("utf8")) for f in subprocess.check_output("git ls-files", shell=True).splitlines()]
files = [f for f in files if not any(i in str(f) for i in ignore)]
# pprint(files)
# version
if args.version:
file_version = args.version.replace(".", "_")
else:
res = requests.get("https://api.github.com/repos/strike-digital/node_pie/releases").json()[0]
latest_version: str = res["tag_name"]
subversion = latest_version.split(".")[-1]
file_version = "_".join(latest_version.split(".")[:-1] + [str(int(subversion) + 1)])
print(file_version)
version = tuple(int(f) for f in file_version.split("_"))
update_init_file(path / "__init__.py", version)
update_manifest_file(path / "blender_manifest.toml", version)
# update_constants_file(constants_file, False)
out_path = path / "builds" / f"node_pie_{file_version}.zip"
print(f"Zipping {len(files)} files")
with ZipFile(out_path, 'w') as z:
# writing each file one by one
for file in files:
print(file, file.exists())
# print(file)
# z.write(file, arcname=str(file).replace("asset_bridge", f"asset_bridge_{file_version}"))
z.write(file, arcname=str(f"node_pie_{file_version}" / file))
print(f"Zipped: {out_path}")
try:
with open("tokens.txt", "r") as f:
token = f.readlines()[0]
except Exception:
webbrowser.open(out_path.parent)
return
create_release = input("Do you want to create a release on github? (y/n) ")
if create_release == "y":
gh = Github(token)
repo = gh.get_repo("strike-digital/node_pie")
version = file_version.replace("_", ".")
commit = repo.get_commits()[0]
message = multi_line_input("Release message:")
if message.rstrip().endswith("CANCEL"):
print("Cancelled release")
return
release = repo.create_git_tag_and_release(
tag=version,
release_name="v" + version,
release_message=message,
tag_message=version,
object=commit.sha,
type="",
)
release.upload_asset(str(out_path))
webbrowser.open(release.html_url)
webbrowser.open(out_path.parent)
webbrowser.open("https://extensions.blender.org/add-ons/nodepie/manage/versions/new/")
print("FINISHED!")
else:
webbrowser.open(out_path.parent)
if __name__ == "__main__":
main()