-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
zipper.py
88 lines (73 loc) · 2.3 KB
/
zipper.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
from zipfile import ZipFile, ZIP_DEFLATED
from zipper_env import PY3, 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("Version number not provided.")
if len(tuple(version.strip().split("."))) != 3:
raise Exception('Invalid version number. Valid version number is "X.X.X".')
if PY3:
print("We building Py3 tonight.\n")
else:
print("We building Py2 tonight.\n")
# Create ZIP Directory
if not os.path.exists("./ZIPs"):
os.makedirs("./ZIPs")
main_zip_name = str(PRIMARY_NAME + version)
if PY3:
main_zip_name += "-Py3"
print("Creating Template ZIP file.")
with ZipFile(
os.path.join(".", "ZIPs", 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("Finished writing the Mod Template ZIP package.\n")
if EXTRAS:
print("Creating Extra Template content ZIP file.")
extras_zip_name = str(PRIMARY_NAME + version)
if PY3:
extras_zip_name += "-Py3Extras"
else:
extras_zip_name += "-Extras"
with ZipFile(
os.path.join(".", "ZIPs", 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("Finished writing the Mod Template Extras ZIP package.\n")
print("Finished packaging.")
if __name__ == "__main__":
main()