-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_encrypted.py
More file actions
208 lines (166 loc) Β· 6.54 KB
/
Copy pathbuild_encrypted.py
File metadata and controls
208 lines (166 loc) Β· 6.54 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# build_encrypted.py - FIXED (with proper imports)
# Location: Project Root
# Purpose: Build encrypted .exe with license protection
"""
Build encrypted .exe with license protection.
Usage:
python build_encrypted.py --full (Build + License)
python build_encrypted.py --license (License only)
"""
import os
import sys
import subprocess
from pathlib import Path
# FIX: Add project root to path BEFORE importing services
project_root = Path(__file__).parent
if str(project_root) not in sys.path:
sys.path.insert(0, str(project_root))
# NOW import services
from services.license_manager import LicenseManager
class EncryptedBuilder:
"""Builds encrypted .exe with PyInstaller."""
def __init__(self, project_root: Path = None):
self.project_root = project_root or Path(__file__).parent
self.dist_dir = self.project_root / "dist"
self.build_dir = self.project_root / "build"
def check_dependencies(self) -> bool:
"""Check if required tools are installed."""
required = ["PyInstaller", "pyarmor"]
print("π Checking dependencies...")
missing = []
for tool in required:
result = subprocess.run(
[sys.executable, "-m", "pip", "show", tool],
capture_output=True
)
if result.returncode != 0:
missing.append(tool)
if missing:
print(f"β Missing: {', '.join(missing)}")
print(f"\nπ¦ Install with:")
print(f" pip install {' '.join(missing)}")
return False
print("β
All dependencies installed")
return True
def build_exe(self) -> bool:
"""Build executable using PyInstaller."""
print("\nπ¨ Building executable with PyInstaller...")
print(" (This may take 5-10 minutes)")
try:
# Build command - uses valid PyInstaller arguments only
cmd = [
sys.executable,
"-m",
"PyInstaller",
"--onefile",
"--windowed",
"--name", "NetworkMonitor",
"--icon", str(self.project_root / "app" / "resources" / "app_icon.ico"),
"--add-data", f"{self.project_root / 'app' / 'theme' / 'dark.qss'}:app/theme",
"--add-data", f"{self.project_root / 'app' / 'resources'}:app/resources",
"--add-data", f"{self.project_root / 'storage' / 'schema.sql'}:storage",
"--hidden-import", "PySide6",
"--hidden-import", "pyqtgraph",
"--hidden-import", "psutil",
str(self.project_root / "app" / "main.py")
]
# Run build from project root
result = subprocess.run(cmd, cwd=str(self.project_root))
if result.returncode == 0:
exe_path = self.dist_dir / "NetworkMonitor.exe"
if exe_path.exists():
size_mb = exe_path.stat().st_size / (1024**2)
print(f"β
Executable built successfully")
print(f" π¦ NetworkMonitor.exe ({size_mb:.1f} MB)")
return True
except Exception as e:
print(f"β Build error: {e}")
import traceback
traceback.print_exc()
return False
def create_license(self, days_valid: int = 365) -> bool:
"""Create hardware-locked license file."""
print("\nπ Generating license key...")
try:
# Get hardware ID
hardware_id = LicenseManager.get_hardware_id()
print(f" π± Hardware ID: {hardware_id}")
# Generate license
license_dict = LicenseManager.generate_license_key(
hardware_id,
days_valid
)
# Save license to project root
license_path = self.project_root / "network_monitor.lic"
if LicenseManager.save_license(license_dict, license_path):
print(f"β
License created")
print(f" π {license_path}")
print(f" π
Valid until: {license_dict['expiry']}")
return True
else:
print("β Failed to save license")
return False
except Exception as e:
print(f"β License error: {e}")
import traceback
traceback.print_exc()
return False
def full_build(self) -> bool:
"""Complete build process."""
print("=" * 60)
print("π NETWORK MONITOR - ENCRYPTED BUILD")
print("=" * 60)
# Check dependencies
if not self.check_dependencies():
return False
# Build executable
if not self.build_exe():
return False
# Create license
if not self.create_license():
print("β οΈ License creation failed (continuing anyway)")
# Success
print("\n" + "=" * 60)
print("β
BUILD COMPLETE!")
print("=" * 60)
print(f"\nπ¦ Output:")
print(f" Executable: {self.dist_dir}/NetworkMonitor.exe")
print(f" License: {self.project_root}/network_monitor.lic")
print(f"\nπ Next steps:")
print(f" 1. Test: dist\\NetworkMonitor.exe")
print(f" 2. Copy license: C:\\Users\\<name>\\.network_monitor\\license.lic")
print(f" 3. Run application")
return True
def main():
"""Main entry point."""
import argparse
parser = argparse.ArgumentParser(
description="Build encrypted Network Monitor executable"
)
parser.add_argument(
"--full",
action="store_true",
help="Full build (build + license)"
)
parser.add_argument(
"--license",
action="store_true",
help="Create license only"
)
args = parser.parse_args()
builder = EncryptedBuilder()
# Show help if no args
if not any([args.full, args.license]):
parser.print_help()
print("\nπ Examples:")
print(" python build_encrypted.py --full (Build + License)")
print(" python build_encrypted.py --license (License only)")
return
# Full build
if args.full:
builder.full_build()
# License only
if args.license:
builder.create_license()
if __name__ == "__main__":
main()