-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmake_releases.py
92 lines (75 loc) · 2.71 KB
/
make_releases.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
# Copyright (c) 2019 - 2022 Elie Michel
#
# This file is part of LilySurfaceScraper, a Blender add-on to import
# materials from a single URL. It is released under the terms of the GPLv3
# license. See the LICENSE.md file for the full text.
import sys
import os
from os.path import join as P
import shutil
from subprocess import run
#------------------------------------------------------------
# Config
addon_list = [
"LilySurfaceScraper",
]
#------------------------------------------------------------
# Main
def main():
with cd(this_scripts_directory()):
addon = "LilySurfaceScraper"
addon_path = P("blender", addon)
version = get_addon_version(addon_path)
zip(addon_path, P("releases", f"{addon}-v{version}"))
print(f"Done! You may install in Blender the addon releases/{addon}-v{version}.zip.")
#------------------------------------------------------------
# Utils
class cd:
"""Context manager for changing the current working directory"""
def __init__(self, directory):
self.directory = os.path.expanduser(directory)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.directory)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
def ensure_dir(directory):
os.makedirs(directory, exist_ok=True)
def zip(directory, zipfile):
"""compresses a directory into a zip file"""
print(f"Zipping {directory} into {zipfile}...")
directory = os.path.realpath(directory)
parent = os.path.dirname(directory)
base = os.path.basename(directory)
shutil.make_archive(zipfile, 'zip', parent, base)
def get_addon_version(addon_directory):
"""Extract the version of the addon from its init file"""
with open(P(addon_directory, "__init__.py"), 'r') as f:
text = f.read()
bl_info = eval(text[text.find("{"):text.find("}")+1])
return "{}.{}.{}".format(*bl_info["version"])
def this_scripts_directory():
return os.path.dirname(os.path.realpath(__file__))
def find_python39():
path_sep = ";" if sys.platform == "win32" else ":"
python_exe = "python.exe" if sys.platform == "win32" else "python"
python3_exe = "python3.exe" if sys.platform == "win32" else "python3"
path = os.environ["PATH"].split(path_sep)
for p in path:
try:
files = os.listdir(p)
except FileNotFoundError:
continue
full_python_exe = None
if python_exe in files:
full_python_exe = os.path.join(p, python_exe)
if python3_exe in files:
full_python_exe = os.path.join(p, python3_exe)
if full_python_exe is not None:
ret = run([full_python_exe, "--version"], capture_output=True)
if ret.stdout.startswith(b"Python 3.9"):
return full_python_exe
print("Could not find Python 3.9 in your PATH!")
exit(1)
#------------------------------------------------------------
main()