forked from kvakvs/wow-Restocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wowaddon.py
183 lines (150 loc) · 6.79 KB
/
wowaddon.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python3
#
# Generic Wow Addon Release and Install tool
#
import argparse
import os
import shutil
import subprocess
import sys
import zipfile
VERSION = '2024.5.0' # year.month.build_num
ADDON_NAME = 'Restocker' # Directory and zip name
ADDON_NAME_CLASSIC = ADDON_NAME # Directory and zip name
ADDON_TITLE_CLASSIC = ADDON_NAME # Title field in TOC
ADDON_TITLE_MAINLINE = ADDON_NAME # Title field in Retail mainline
UI_VERSION_CLASSIC = '11403' # patch 1.14.3
UI_VERSION_CLASSIC_TBC = '20504' # patch 2.5.4 Phase 4 and 5 TBC
UI_VERSION_CLASSIC_WOTLK = '30402' # patch 3.4.1 WotLK (TotGC)
UI_VERSION_CLASSIC_CATA = '40400' # patch 4.4.0 Cataclysm Classic
UI_VERSION_CLASSIC_MAINLINE = '100105' # patch 10.1.5 whatever that is
COPY_DIRS = ['Frames', 'Classes', 'Src', 'Ace3']
COPY_FILES = ['embeds.xml']
SUFFIX_CLASSIC = "-Classic" # "_Vanilla"
SUFFIX_TBC = "-BCC" # "_TBC"
SUFFIX_WRATH = "-WOTLKC" # "_Wrath"
SUFFIX_CATA = "-Cata" # "_Cata???"
SUFFIX_RETAIL = "-Mainline"
class BuildTool:
def __init__(self, args: argparse.Namespace):
self.args = args
self.version = VERSION
self.copy_dirs = COPY_DIRS[:]
self.copy_files = COPY_FILES[:]
self.create_toc(dst=f'{ADDON_NAME_CLASSIC}.toc',
ui_version=UI_VERSION_CLASSIC,
title=ADDON_TITLE_CLASSIC)
self.create_toc(dst=f'{ADDON_NAME_CLASSIC}{SUFFIX_CLASSIC}.toc',
ui_version=UI_VERSION_CLASSIC,
title=ADDON_TITLE_CLASSIC)
self.create_toc(dst=f'{ADDON_NAME_CLASSIC}{SUFFIX_TBC}.toc',
ui_version=UI_VERSION_CLASSIC_TBC,
title=ADDON_TITLE_CLASSIC)
self.create_toc(dst=f'{ADDON_NAME_CLASSIC}{SUFFIX_WRATH}.toc',
ui_version=UI_VERSION_CLASSIC_WOTLK,
title=ADDON_TITLE_CLASSIC)
self.create_toc(dst=f'{ADDON_NAME_CLASSIC}{SUFFIX_CATA}.toc',
ui_version=UI_VERSION_CLASSIC_CATA,
title=ADDON_TITLE_CLASSIC)
self.create_toc(dst=f'{ADDON_NAME_CLASSIC}{SUFFIX_RETAIL}.toc',
ui_version=UI_VERSION_CLASSIC_MAINLINE,
title=ADDON_TITLE_MAINLINE)
def do_install(self, toc_name: str):
self.copy_files.append(f'{toc_name}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_CLASSIC}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_TBC}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_WRATH}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_CATA}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_RETAIL}.toc')
dst_path = f'{self.args.dst}/{toc_name}'
if os.path.isdir(dst_path):
print("Warning: Folder already exists, removing!")
shutil.rmtree(dst_path)
os.makedirs(dst_path, exist_ok=True)
print(f'Destination: {dst_path}')
for copy_dir in self.copy_dirs:
print(f'Copying directory: {copy_dir}/*')
shutil.copytree(copy_dir, f'{dst_path}/{copy_dir}')
for copy_file in self.copy_files:
print(f'Copying: {copy_file}')
shutil.copy(copy_file, f'{dst_path}/{copy_file}')
@staticmethod
def do_zip_add_dir(zip: zipfile.ZipFile, dir: str, toc_name: str):
""" Add a directory to the zipfile, inside TOC_NAME/... subdir """
for file in os.listdir(dir):
file = dir + "/" + file
print(f'ZIP: Directory {file}/')
if os.path.isdir(file):
BuildTool.do_zip_add_dir(zip, dir=file, toc_name=toc_name)
else:
zip.write(file, f'{toc_name}/{file}')
@staticmethod
def do_zip_add_root_dir(zip: zipfile.ZipFile, dir: str, toc_name: str):
""" Add a directory to the root of the zip file """
for file in os.listdir(dir):
file = dir + "/" + file
print(f'ZIP: Directory {file}/')
if os.path.isdir(file):
BuildTool.do_zip_add_root_dir(zip, dir=file, toc_name=toc_name)
else:
zip.write(file, file)
def do_zip(self, toc_name: str):
self.copy_files.append(f'{toc_name}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_CLASSIC}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_TBC}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_WRATH}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_CATA}.toc')
self.copy_files.append(f'{toc_name}{SUFFIX_RETAIL}.toc')
zip_name = f'{self.args.dst}/{toc_name}-{VERSION}.zip'
with zipfile.ZipFile(zip_name, "w", zipfile.ZIP_DEFLATED,
allowZip64=True) as zip_file:
# Add deprecation addon to zip
# BuildTool.do_zip_add_root_dir(zip_file, dir=LEGACY_OVERRIDE_ADDON, toc_name=toc_name)
for input_dir in self.copy_dirs:
BuildTool.do_zip_add_dir(zip_file, dir=input_dir, toc_name=toc_name)
for input_f in self.copy_files:
print(f'ZIP: File {input_f}')
zip_file.write(input_f, f'{toc_name}/{input_f}')
@staticmethod
def git_hash() -> str:
# Call: git rev-parse HEAD
p = subprocess.check_output(
["git", "rev-parse", "HEAD"])
hash1 = str(p).rstrip("\\n'").lstrip("b'")
return hash1[:8]
@staticmethod
def create_toc(dst: str, ui_version: str, title: str):
hash1 = BuildTool.git_hash()
template = open('toc_template.toc', "rt").read()
template = template.replace('${UI_VERSION}', ui_version)
template = template.replace('${VERSION}', f'{VERSION}-{hash1}')
template = template.replace('${ADDON_TITLE}', title)
with open(dst, "wt") as out_f:
out_f.write(template)
def main():
parser = argparse.ArgumentParser(
description="Restocker Release and Install tool")
parser.add_argument(
'--dst', type=str, required=True, action='store',
help='The destination directory where the game Addons will be copied, '
'or where ZIP will be stored. TOC name will serve as directory '
'name.')
parser.add_argument(
'--version', choices=['classic', 'tbc', 'wotlk'],
help='The version to copy or zip: classic, TBC or WotLK')
parser.add_argument(
'command', choices=['help', 'zip', 'install'],
help='The action to take. ZIP will create an archive. '
'Install will copy')
args = parser.parse_args(sys.argv[1:])
print(args)
if args.command == 'install':
bt = BuildTool(args)
bt.do_install(toc_name=ADDON_NAME_CLASSIC)
elif args.command == 'zip':
bt = BuildTool(args)
bt.do_zip(toc_name=ADDON_NAME_CLASSIC)
else:
parser.print_help()
if __name__ == "__main__":
main()