-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
98 lines (87 loc) · 3.02 KB
/
Copy pathbuild.py
File metadata and controls
98 lines (87 loc) · 3.02 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
import os
import sys
import shutil
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
DIST_DIR = os.path.join(ROOT_DIR, 'dist')
BUILD_DIR = os.path.join(ROOT_DIR, 'build')
SPEC_FILE = os.path.join(ROOT_DIR, 'eNSP_AutoConfig.spec')
print("=" * 50)
print(" eNSP配置助手 v1.2 - Build Tool")
print("=" * 50)
if os.path.exists(DIST_DIR):
print("[1/4] Cleaning dist...")
shutil.rmtree(DIST_DIR, ignore_errors=True)
if os.path.exists(BUILD_DIR):
print("[2/4] Cleaning build...")
shutil.rmtree(BUILD_DIR, ignore_errors=True)
if os.path.exists(SPEC_FILE):
os.remove(SPEC_FILE)
print("[3/4] PyInstaller packaging (onefile mode)...")
app_py = os.path.join(ROOT_DIR, 'app.py')
templates_dir = os.path.join(ROOT_DIR, 'templates')
static_dir = os.path.join(ROOT_DIR, 'static')
teaching_dir = os.path.join(ROOT_DIR, 'teaching')
license_file = os.path.join(ROOT_DIR, 'LICENSE')
notice_file = os.path.join(ROOT_DIR, 'NOTICE')
command = (
'pyinstaller --noconfirm --onefile '
'--hidden-import jinja2 '
'--hidden-import jinja2.ext '
'--hidden-import markupsafe '
'--hidden-import flask '
'--hidden-import flask.json '
'--hidden-import ai_handler '
'--hidden-import template_manager '
'--hidden-import history_manager '
'--hidden-import device_info_reader '
'--hidden-import console_session '
'--hidden-import teaching '
'--hidden-import lab_packs '
'--hidden-import verify_helper '
'--hidden-import generators '
'--hidden-import generators.switching '
'--hidden-import generators.routing '
'--hidden-import generators.services '
'--hidden-import generators.common '
'--hidden-import network_utils '
'--hidden-import config '
'--add-data "' + templates_dir + ';templates/" '
'--add-data "' + static_dir + ';static/" '
'--add-data "' + teaching_dir + ';teaching/" '
'--add-data "' + license_file + ';." '
'--add-data "' + notice_file + ';." '
'--name eNSP_AutoConfig '
'--noconsole '
'"' + app_py + '"'
)
result = os.system(command)
if result == 0:
exe_path = os.path.join(DIST_DIR, 'eNSP_AutoConfig.exe')
if os.path.exists(exe_path):
size_mb = os.path.getsize(exe_path) / (1024 * 1024)
print("")
print("[4/4] Build SUCCESS!")
print(" Output: " + exe_path)
print(" Size: %.1f MB" % size_mb)
else:
print("")
print("[4/4] Build FAILED: output file not found")
sys.exit(1)
else:
print("")
print("Build FAILED, error code: %d" % result)
sys.exit(1)
history_dir = os.path.join(DIST_DIR, 'history')
if not os.path.exists(history_dir):
os.makedirs(history_dir)
print(" Created history dir: " + history_dir)
# 分发目录附带许可证文本(Apache 2.0)
for name in ('LICENSE', 'NOTICE'):
src = os.path.join(ROOT_DIR, name)
dst = os.path.join(DIST_DIR, name)
if os.path.exists(src):
shutil.copy2(src, dst)
print(" Copied " + name + " -> dist/")
print("")
print("Usage: Double-click eNSP_AutoConfig.exe to start")
print("=" * 50)