-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdroptrash.py
More file actions
146 lines (116 loc) · 4.78 KB
/
Copy pathdroptrash.py
File metadata and controls
146 lines (116 loc) · 4.78 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
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
#!/usr/bin/env python3
#
# DropTrash Release and Install tool
#
import argparse
import os
import shutil
import subprocess
import sys
import zipfile
VERSION = '2021.5.2' # year.month.build_num
UI_VERSION_CLASSIC = '11307' # patch 1.13.7
BOM_NAME_CLASSIC = 'DropTrash' # Directory and zip name
BOM_TITLE_CLASSIC = "DropTrash Bag Cleaner" # Title field in TOC
UI_VERSION_CLASSIC_TBC = '20501' # patch 2.5.1
BOM_NAME_CLASSIC_TBC = 'DropTrashTBC' # Directory and zip name
BOM_TITLE_CLASSIC_TBC = "DropTrash Bag Cleaner TBC" # Title field in TOC
COPY_DIRS = ['src', 'xml', 'classes']
COPY_FILES = ['README.md', 'Bindings.xml']
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'{BOM_NAME_CLASSIC}.toc',
ui_version=UI_VERSION_CLASSIC,
title=BOM_TITLE_CLASSIC)
self.create_toc(dst=f'{BOM_NAME_CLASSIC_TBC}.toc',
ui_version=UI_VERSION_CLASSIC_TBC,
title=BOM_TITLE_CLASSIC_TBC)
def do_install(self, toc_name: str):
self.copy_files.append(f'{toc_name}.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):
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}')
def do_zip(self, toc_name: str):
self.copy_files.append(f'{toc_name}.toc')
zip_name = f'{self.args.dst}/{toc_name}-{self.version}.zip'
with zipfile.ZipFile(zip_name, "w", zipfile.ZIP_DEFLATED,
allowZip64=True) as zip_file:
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"])
hash = str(p).rstrip("\\n'").lstrip("b'")
return hash[:8]
def create_toc(self, dst: str, ui_version: str, title: str):
hash = BuildTool.git_hash()
template = open('toc_template.toc', "rt").read()
template = template.replace('${UI_VERSION}', ui_version)
template = template.replace('${VERSION}', f'{VERSION}-{hash}')
template = template.replace('${ADDON_TITLE}', title)
with open(dst, "wt") as out_f:
out_f.write(template)
def main():
parser = argparse.ArgumentParser(
description="DropTrash 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'],
help='The version to copy or zip, classic or TBC')
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)
if args.version == 'classic':
bt.do_install(toc_name=BOM_NAME_CLASSIC)
else:
bt.do_install(toc_name=BOM_NAME_CLASSIC_TBC)
elif args.command == 'zip':
bt = BuildTool(args)
if args.version == 'classic':
bt.do_zip(toc_name=BOM_NAME_CLASSIC)
else:
bt.do_zip(toc_name=BOM_NAME_CLASSIC_TBC)
else:
parser.print_help()
if __name__ == "__main__":
main()