forked from Bronya-Rand/DDLCModTemplate2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzipper.py
More file actions
79 lines (64 loc) · 2.33 KB
/
zipper.py
File metadata and controls
79 lines (64 loc) · 2.33 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
from zipfile import ZipFile, ZIP_DEFLATED
from zipper_env import EXTRAS
import sys
import os
PRIMARY_NAME = "DDLCModTemplate-"
EXCLUDE_LIST = [
".github",
".git",
".gitattributes",
".gitignore",
"requirements.txt",
"ZIPs",
"Additional Mod Features",
"zipper.py",
"zipper_env.py",
"__pycache__",
]
def main():
try:
version = sys.argv[1]
except IndexError:
raise Exception("Не указан номер версии.")
if len(tuple(version.strip().split("."))) != 3:
raise Exception('Некорректный номер версии. Допустимое значение: "X.X.X".')
print("Сегодня вечером мы собираем Py3-пакет.\n")
# Создание каталога для ZIP-архивов
if not os.path.exists("./ZIPs"):
os.makedirs("./ZIPs")
main_zip_name = f"{PRIMARY_NAME}{version}-Py3"
print("Создаю ZIP-файл шаблона.")
with ZipFile(
os.path.join(".", "ZIPs", f"{main_zip_name}.zip"),
"w",
ZIP_DEFLATED,
compresslevel=5,
) as main_template:
for src, dirs, files in os.walk("."):
for f in files:
path = os.path.join(src, f)
validLocation = True
for x in EXCLUDE_LIST:
if x in path:
validLocation = False
if validLocation:
main_template.write(path)
print("Запись ZIP-пакета мод-шаблона завершена.\n")
if EXTRAS:
print("Создаю ZIP-файл доп. контента шаблона.")
extras_zip_name = f"{PRIMARY_NAME}{version}-Py3Extras"
with ZipFile(
os.path.join(".", "ZIPs", f"{extras_zip_name}.zip"),
"w",
ZIP_DEFLATED,
compresslevel=5,
) as extras_template:
for src, dirs, files in os.walk("."):
for f in files:
path = os.path.join(src, f)
if "Additional Mod Features" in path:
extras_template.write(path)
print("Запись ZIP-пакета доп. контента шаблона завершена.\n")
print("Упаковка завершена.")
if __name__ == "__main__":
main()