-
Notifications
You must be signed in to change notification settings - Fork 2
/
post_build.py
91 lines (73 loc) · 2.2 KB
/
post_build.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
import glob, os, sys
import shutil
import argparse
def make_folder_if_not_exist(directory):
if os.path.exists(directory):
shutil.rmtree(directory)
os.makedirs(directory)
def GetLicense(x):
result = {
"My": "License",
}.get(x, None)
if result:
result = "%s.txt" % result
return result
# Make the argument parser
parser = argparse.ArgumentParser(description="Perform post-build actions")
parser.add_argument(
"--ModName", metavar="M", type=str, nargs=1, help="The name of the mod"
)
parser.add_argument(
"--TargetDir",
metavar="T",
type=str,
nargs=1,
help="The dir of the compiled results",
)
parser.add_argument(
"--License",
metavar="L",
type=str,
nargs="+",
help="The license the mod is released under",
)
parser.add_argument(
"--ExtraFiles", metavar="F", type=str, nargs="*", help="Any and all extra files"
)
args = parser.parse_args()
# Get the arguments
ModName = args.ModName[0]
TargetDir = args.TargetDir[0]
License = args.License[0] if args.License != None else None
ExtraFiles = args.ExtraFiles
readme = "Readme.txt"
changeLog = "ChangeLog.txt"
info = "info.json"
if not shutil.which("izarcc"):
exit(0)
licenseToAdd = GetLicense(License)
# Figure out which files we need and add them to the list
Files = [readme, changeLog, info]
if licenseToAdd != None:
Files.append(licenseToAdd)
Files.append("%s.dll" % ModName)
if ExtraFiles != None and len(ExtraFiles) > 0:
for file in ExtraFiles:
Files.append(file)
# Move the files over to a folder where we can easily zip it
make_folder = "%s%s\%s" % (TargetDir, ModName, ModName)
make_folder_if_not_exist(make_folder)
for mod_file in Files:
from_path = "%s%s" % (TargetDir, mod_file)
to_path = "%s%s\%s\." % (TargetDir, ModName, ModName)
shutil.copy(from_path, to_path)
# Perform the zip operation
mod_folder = "%s%s" % (TargetDir, ModName)
zip_file_name = "%s.zip" % (mod_folder)
if os.path.isfile(zip_file_name):
os.remove(zip_file_name)
os.system("izarcc -a -r -p -cx %s %s\\" % (zip_file_name, mod_folder))
result_dir = "..\..\..\Result"
if not os.path.exists(result_dir):
os.makedirs(result_dir)
shutil.copy(zip_file_name, "%s\\." % result_dir)