-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_release_generator.py
More file actions
131 lines (103 loc) · 4.73 KB
/
build_release_generator.py
File metadata and controls
131 lines (103 loc) · 4.73 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
import os, tomllib, zipfile
from string import Template
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
)
def build():
PREFIX_BLEND_ASSETS = "SculptWolf_"
OUTPUT_VDM_DIR = "output_vdm/"
BUILD_DIR = ".build/"
_file_prefix = Template("${filename}_${version}${completer}.zip")
logging.info("[🐺] Starting build process")
def readtoml(key):
version = None
with open("blender_manifest.toml", "rb") as f:
data = tomllib.load(f)
version = data[key]
if version is None:
logging.error("[🐺] Version not found in blender_metadata.toml. Please check the file.")
raise ValueError("Version not found in blender_metadata.toml. Please check the file.")
return version
_file_prefix = Template(_file_prefix.safe_substitute({
"filename": readtoml("id"),
"version": readtoml("version")
}))
# make two filenames
ADDONS_INSTALLS_FILE = _file_prefix.safe_substitute({"completer": "_addons"})
LIBRARY_ONLY_FILE = _file_prefix.safe_substitute({"completer": "_library"})
logging.info(f"[🐺] Initializing {ADDONS_INSTALLS_FILE} and {LIBRARY_ONLY_FILE} files")
#
# listing all 3D VDM brushes
#
# output_vdm folder is required!
VDM_BRUSHES = []
logging.info(f"[🐺] Listing all 3D VDM brushes in {OUTPUT_VDM_DIR}")
for root, _, files in os.walk(OUTPUT_VDM_DIR):
for file in files:
if file.endswith(".exr"):
VDM_BRUSHES.append(os.path.join(root, file))
#
# listing all required files for blender_assets
#
logging.info(f"[🐺] Listing all required files to be zipped for {LIBRARY_ONLY_FILE}")
LIBRARY_ONLY_FILES = [*VDM_BRUSHES, "./blender_assets.cats.txt"].copy()
if not os.path.exists(LIBRARY_ONLY_FILES[-1]):
logging.error(f"[🐺] Could not find {LIBRARY_ONLY_FILES[-1]}, this is means your blender_assets.cats.txt file is missing or not initialized in your blender project.")
raise FileNotFoundError(f"Could not find {LIBRARY_ONLY_FILES[-1]}, this is means your blender_assets.cats.txt file is missing or not initialized in your blender project.")
# listing it up by SculptWolf prefix and append it to LIBRARY_ONLY_FILE
BLEND_FILES = []
for root, _, files in os.walk("."):
for file in files:
if file.startswith(PREFIX_BLEND_ASSETS) and file.endswith(".blend"):
BLEND_FILES.append(os.path.join(root, file))
LIBRARY_ONLY_FILES.append(os.path.join(root, file))
logging.info(f"[🐺] Listing required files to be zipped for {ADDONS_INSTALLS_FILE}")
ADDONS_INSTALLS_FILES = [*LIBRARY_ONLY_FILES].copy()
REQUIRED_FILES = ["blender_manifest.toml", "__init__.py"]
for root, _, files in os.walk("."):
for file in files:
if file in REQUIRED_FILES:
ADDONS_INSTALLS_FILES.append(os.path.join(root, file))
logging.info(f"[🐺] Finished listing files to be zipped")
logging.info(f"[🐺] Totals: {len(VDM_BRUSHES)} VDM Brushes, {len(BLEND_FILES)} .blend files, and __init__.py")
#
# creating two zip files
#
def make_zip(filename, contents: list[str] = []):
try:
zip = zipfile.ZipFile(filename, "w", zipfile.ZIP_DEFLATED, compresslevel=9)
# parsing directory via contents before zipping it to fix path
for file in contents:
zip.write(file)
zip.close()
except Exception as e:
logging.error(f"[🐺] Failed to create {filename} file: {e}")
raise e
logging.info(f"[🐺] Creating {LIBRARY_ONLY_FILE} file")
make_zip(BUILD_DIR + LIBRARY_ONLY_FILE, LIBRARY_ONLY_FILES)
logging.info(f"[🐺] Creating {ADDONS_INSTALLS_FILE} file")
make_zip(BUILD_DIR + ADDONS_INSTALLS_FILE, ADDONS_INSTALLS_FILES)
logging.info(f"[🐲] Finished creating {LIBRARY_ONLY_FILE} and {ADDONS_INSTALLS_FILE} files")
logging.info(f"[🐲] Finished build process")
while True:
open_explorer = input("[🐺] Open explorer? (y/n): ")
if open_explorer.lower() == "y":
os.startfile(os.path.dirname(BUILD_DIR))
logging.info(f"[🐲] Opened explorer")
break
elif open_explorer.lower() == "n":
logging.info(f"[🐲] Not opening explorer")
break
else:
logging.info(f"[🐺] Invalid input")
if __name__ == "__main__":
try:
build()
except Exception as e:
logging.error(f"[🐺] Failed to build release: {e}")
logging.info(f"[🐲] Have a nice day!")
input("[🐲] Press enter to exit...")
exit(0)