-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcompile.py
59 lines (45 loc) · 1.67 KB
/
compile.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
import json
import os
import shutil
import subprocess
import zipfile
import PyInstaller.__main__
app_name = os.path.basename(os.getcwd()).replace('-v2', '')
version = json.load(open('package.json', encoding='utf-8'))['version']
web_dist = 'build/web_dist'
work_path = 'build/pyinstaller'
dist_path = 'build/dist'
shutil.rmtree(dist_path, ignore_errors=True)
shutil.rmtree(work_path, ignore_errors=True)
completed = subprocess.run('npm run build', shell=True)
if completed.returncode:
print("NPM build failed!")
exit()
PyInstaller.__main__.run([
'main.py', f'--name={app_name}', '--icon=public/favicon.ico',
f'--distpath={dist_path}/{app_name}', f'--workpath={work_path}', '--onefile', '--noconfirm',
'--hidden-import=app',
# PonyORM and SQLite
'--hidden-import=pony.orm.dbproviders',
'--hidden-import=pony.orm.dbproviders.sqlite',
# Websockets
'--hidden-import=websockets.legacy',
'--hidden-import=websockets.legacy.server',
])
shutil.copy('package.json', f"{dist_path}/{app_name}")
shutil.copy('logging_config.json', f"{dist_path}/{app_name}")
shutil.copytree('executables', f"{dist_path}/{app_name}/executables", dirs_exist_ok=True)
shutil.copytree(web_dist, f"{dist_path}/{app_name}/web", dirs_exist_ok=True)
print("Zipping files...")
current_dir = os.getcwd()
os.chdir(dist_path)
dist_file = zipfile.ZipFile(f'{app_name}-v{version}.zip', 'w')
for folder, _, filenames in os.walk(app_name):
for filename in filenames:
filepath = os.path.join(folder, filename)
print(f"Zipping {filepath}")
dist_file.write(filepath)
os.chdir(current_dir)
if os.path.exists(f"{app_name}.spec"):
os.remove(f"{app_name}.spec")
print("Done!")