forked from TheQwertiest/foo_discord_rich
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack_component.py
77 lines (58 loc) · 2.4 KB
/
pack_component.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
#!/usr/bin/env python3
import argparse
import zipfile
from pathlib import Path
from zipfile import ZipFile
import call_wrapper
def path_basename_tuple(path):
return (path, path.name)
def zipdir(zip_file, path, arc_path):
assert(path.exists() and path.is_dir())
for file in path.rglob("*"):
if (file.name.startswith(".")):
# skip `hidden` files
continue
if (arc_path):
file_arc_path = f"{arc_path}/{file.relative_to(path)}"
else:
file_arc_path = file.relative_to(path)
zip_file.write(file, file_arc_path)
def pack(is_debug = False):
cur_dir = Path(__file__).parent.absolute()
root_dir = cur_dir.parent
result_machine_dir = root_dir/"_result"/("Win32_Debug" if is_debug else "Win32_Release")
assert(result_machine_dir.exists() and result_machine_dir.is_dir())
output_dir = result_machine_dir
output_dir.mkdir(parents=True, exist_ok=True)
component_zip = output_dir/"foo_discord_rich.fb2k-component"
component_zip.unlink(missing_ok=True)
with ZipFile(component_zip, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as z:
zipdir(z, root_dir/'licenses', 'licenses')
z.write(*path_basename_tuple(root_dir/"LICENSE"))
z.write(*path_basename_tuple(root_dir/"CHANGELOG.md"))
z.write(*path_basename_tuple(result_machine_dir/"bin"/"foo_discord_rich.dll"))
if (is_debug):
# Only debug package should have pdbs inside
z.write(*path_basename_tuple(result_machine_dir/"dbginfo"/"foo_discord_rich.pdb"))
print(f"Generated file: {component_zip}")
if (not is_debug):
# Release pdbs are packed in a separate package
pdb_zip = output_dir/"foo_discord_rich_pdb.zip"
if (pdb_zip.exists()):
pdb_zip.unlink()
with ZipFile(pdb_zip, "w", zipfile.ZIP_DEFLATED) as z:
z.write(*path_basename_tuple(result_machine_dir/"dbginfo"/"foo_discord_rich.pdb"))
print(f"Generated file: {pdb_zip}")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Pack component to .fb2k-component')
parser.add_argument('--debug', default=False, action='store_true')
args = parser.parse_args()
call_wrapper.final_call_decorator(
"Packing component",
"Packing component: success",
"Packing component: failure!"
)(
pack
)(
args.debug
)