-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip_addon_release.py
78 lines (59 loc) · 2.53 KB
/
zip_addon_release.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
import os
import zipfile
from pathlib import Path
def zip_dir(directory: Path, zip_path: str, exclude_folders, exclude_files):
"""
Compress a directory (ZIP file).
"""
if os.path.exists(directory):
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as out_zip_file:
# The root directory within the ZIP file.
rootdir = os.path.basename(directory)
for dirpath, dirnames, filenames in os.walk(directory):
dirnames[:] = [d for d in dirnames if d not in exclude_folders]
for filename in filenames:
if filename in exclude_files:
continue
# Write the file named filename to the archive,
# giving it the archive name 'arcname'.
filepath = os.path.join(dirpath, filename)
parentpath = os.path.relpath(filepath, directory)
arcname = os.path.join(rootdir, parentpath)
out_zip_file.write(filepath, arcname)
def get_ints_from_str(string: str):
"""
Get all the integers from a string.
"""
return [int(s) for s in string if s.isdigit()]
def get_version(line_num: int = 19):
"""
Get the version number from the __init__.py file.
Parameters
----------
line_num : int
The number of the line in the __init__.py file that contains the version number.
Default is 19. If you change the line of version number in the __init__.bl_info,
you must change this number to match.
"""
current_dir = Path(__file__).resolve().parent
init_file_path = current_dir / "__init__.py"
with open(init_file_path, "r") as f:
lines = f.readlines()
version_line = lines[line_num-1]
version = get_ints_from_str(version_line)
print(version)
version = "_".join(str(num) for num in version)
return version
if __name__ == "__main__":
version = get_version()
print(version)
exclude_folders = ["non-public", "releases",
"__pycache__", ".git", ".vscode", ".gitignore", "zip_addon_release.py"]
exclude_files = [".gitignore", "zip_addon_release.py"]
current_dir = Path(__file__).resolve().parent
releases_dir = current_dir / "releases"
releases_dir.mkdir(exist_ok=True)
zip_name = f"{current_dir.name}_{version}.zip"
zip_path = releases_dir / zip_name
zip_dir(directory=current_dir, zip_path=zip_path,
exclude_folders=exclude_folders, exclude_files=exclude_files)