This repository has been archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.py
80 lines (70 loc) · 3.02 KB
/
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
import json
import os
import platform
import sys
import zipfile
from pathlib import Path
print(r"""
__ ___ _ __ _ ____ ____ ____ ____ _ _ _
\ \ / (_|_)_ __ ___ _ __ ___ / _(_) | _ \| _ \ / ___| | __ ) _ _(_) | __| | ___ _ __
\ \ /\ / /| | | '_ ` _ \| '_ ` _ \| |_| |_____| |_) | |_) | | | _ \| | | | | |/ _` |/ _ \ '__|
\ V V / | | | | | | | | | | | | | _| |_____| _ <| __/| |___ | |_) | |_| | | | (_| | __/ |
\_/\_/ |_|_|_| |_| |_|_| |_| |_|_| |_| |_| \_\_| \____| |____/ \__,_|_|_|\__,_|\___|_|
""")
if 'PYTHON' not in os.environ:
os.environ['PYTHON'] = 'python'
script_dir = Path(sys.argv[0]).parent
plat = platform.system()
if plat not in ('Linux', 'Darwin', 'Windows'):
print(f'[!!] Platform {plat} not supported.')
sys.exit()
arch = platform.architecture()[0]
# find target version
try:
with (script_dir / 'data' / 'version_info.json').open('r') as file:
data = json.load(file)
version = data.get('version')
if not version:
print('[!!] No version found in data files!')
sys.exit()
print(f'[!] Detected Version: {version}')
print(f'[!] Building On {plat}')
except FileNotFoundError:
print('[!!] No version found in data files!')
sys.exit()
if __name__ == '__main__':
if len(sys.argv) == 1 or 'build' not in sys.argv[1]:
print()
print('WARNING: This script will build a bundled PyInstaller file.\n'
'If you just want to use the program, this isn\'t the right script for you.\n'
'Buttt... if you\'re convinced it is, use "build" as first argument.')
sys.exit()
print('[!] Installing Packages')
if plat in ('Windows', 'Darwin'):
command = os.environ['PYTHON']
os.system(f'{command} -m pip install -q -U -r requirements.txt')
os.system(f'{command} -m pip install -q -U pyinstaller')
elif plat == 'Linux':
os.system(f'pip install -U -r requirements.txt')
os.system(f'pip install -U pyinstaller')
print()
print('[!] Building Script')
if plat in ('Windows', 'Linux'):
command = os.environ['PYTHON'] + ' -m PyInstaller'
else:
command = 'pyinstaller'
os.system(
f'{command} -y -w --onefile -n "Wiimmfi-RPC v{version}" --log-level WARN ' \
f'--additional-hooks-dir=buildhooks/ --hidden-import=PyQt5.sip rpcgui.py')
print()
print('[!] Packing Files')
exec_path = list((script_dir / 'dist').iterdir())[0]
to_pack = list((script_dir / 'data').iterdir()) + list((script_dir / 'icons').iterdir())
with zipfile.ZipFile((script_dir / f'Wiimmfi-RPC_{plat}-{arch}.zip'), 'x') as archive:
archive.write(exec_path, arcname=exec_path.name)
for file in to_pack:
archive.write(file)
print()
if sys.argv[1] == 'build_appveyor':
os.system(f'appveyor PushArtifact Wiimmfi-RPC_{plat}-{arch}.zip')
print(f'[!] Finished Building. Output can be found in Wiimmfi-RPC_{plat}-{arch}.zip')