[patch] DY-token检测逻辑修改 修改本地打包环境路径锁定
This commit is contained in:
@@ -1,57 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
生产环境打包脚本 - 自动禁用日志功能
|
||||
Production build script - Automatically disable logging functionality
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Ensure script runs in correct directory
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(SCRIPT_DIR)
|
||||
print(f"Working directory: {SCRIPT_DIR}")
|
||||
|
||||
def disable_logging():
|
||||
"""自动禁用所有日志功能"""
|
||||
"""Disable all logging functionality"""
|
||||
print("Disabling logging functionality...")
|
||||
|
||||
# 备份原文件
|
||||
# Backup original files
|
||||
files_to_backup = ['main.py', 'exe_file_logger.py']
|
||||
for file_name in files_to_backup:
|
||||
if os.path.exists(file_name):
|
||||
shutil.copy(file_name, f'{file_name}.backup')
|
||||
print(f"Backed up {file_name}")
|
||||
|
||||
# 1. 修改 main.py - 注释掉日志初始化
|
||||
# 1. Modify main.py - comment out logging initialization
|
||||
if os.path.exists('main.py'):
|
||||
with open('main.py', 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 注释掉日志相关的导入和初始化
|
||||
# Comment out logging related imports and initialization
|
||||
content = content.replace(
|
||||
'from exe_file_logger import setup_file_logging, log_to_file',
|
||||
'# from exe_file_logger import setup_file_logging, log_to_file # 生产环境禁用'
|
||||
'# from exe_file_logger import setup_file_logging, log_to_file # Production disabled'
|
||||
).replace(
|
||||
'setup_file_logging()',
|
||||
'# setup_file_logging() # 生产环境禁用'
|
||||
'# setup_file_logging() # Production disabled'
|
||||
).replace(
|
||||
'print("文件日志系统已在main.py中初始化")',
|
||||
'# print("文件日志系统已在main.py中初始化") # 生产环境禁用'
|
||||
'# print("文件日志系统已在main.py中初始化") # Production disabled'
|
||||
)
|
||||
|
||||
with open('main.py', 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
print("Disabled logging in main.py")
|
||||
|
||||
# 2. 修改 exe_file_logger.py - 让所有函数变成空操作
|
||||
# 2. Modify exe_file_logger.py - make all functions no-op
|
||||
if os.path.exists('exe_file_logger.py'):
|
||||
with open('exe_file_logger.py', 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 将 setup_file_logging 函数替换为空函数
|
||||
# Replace setup_file_logging function with empty function
|
||||
content = content.replace(
|
||||
'def setup_file_logging():',
|
||||
'def setup_file_logging():\n """生产环境 - 禁用文件日志"""\n return None\n\ndef setup_file_logging_original():'
|
||||
'def setup_file_logging():\n """Production - Logging disabled"""\n return None\n\ndef setup_file_logging_original():'
|
||||
).replace(
|
||||
'def log_to_file(message):',
|
||||
'def log_to_file(message):\n """生产环境 - 禁用文件日志"""\n pass\n\ndef log_to_file_original(message):'
|
||||
'def log_to_file(message):\n """Production - Logging disabled"""\n pass\n\ndef log_to_file_original(message):'
|
||||
)
|
||||
|
||||
with open('exe_file_logger.py', 'w', encoding='utf-8') as f:
|
||||
@@ -61,37 +67,54 @@ def disable_logging():
|
||||
print("All logging functionality disabled")
|
||||
|
||||
def restore_logging():
|
||||
"""恢复日志功能"""
|
||||
"""Restore logging functionality"""
|
||||
print("Restoring development configuration...")
|
||||
files_to_restore = ['main.py', 'exe_file_logger.py']
|
||||
restored_count = 0
|
||||
|
||||
for file_name in files_to_restore:
|
||||
backup_file = f'{file_name}.backup'
|
||||
if os.path.exists(backup_file):
|
||||
shutil.copy(backup_file, file_name)
|
||||
os.remove(backup_file)
|
||||
print(f"Restored {file_name}")
|
||||
print("All files restored to development configuration")
|
||||
try:
|
||||
if os.path.exists(backup_file):
|
||||
# Ensure target file is writable
|
||||
if os.path.exists(file_name):
|
||||
os.chmod(file_name, 0o666)
|
||||
|
||||
shutil.copy(backup_file, file_name)
|
||||
os.remove(backup_file)
|
||||
print(f"[OK] Restored {file_name}")
|
||||
restored_count += 1
|
||||
else:
|
||||
print(f"[WARN] Backup file not found: {backup_file}")
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to restore {file_name}: {e}")
|
||||
|
||||
if restored_count == len(files_to_restore):
|
||||
print("[OK] All files restored to development configuration")
|
||||
else:
|
||||
print(f"[WARN] Restored {restored_count}/{len(files_to_restore)} files")
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
"""Main function"""
|
||||
print("Production Build Tool (No Logging Version)")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
# 1. 禁用日志功能
|
||||
# 1. Disable logging functionality
|
||||
disable_logging()
|
||||
|
||||
# 2. 执行打包
|
||||
# 2. Execute build
|
||||
print("\nStarting build...")
|
||||
result = subprocess.run(['python', 'quick_build.py'], capture_output=False)
|
||||
|
||||
if result.returncode == 0:
|
||||
# 验证最终输出(quick_build.py 已统一输出到 MultiPlatformGUI)
|
||||
# Verify output (quick_build.py outputs to MultiPlatformGUI)
|
||||
if os.path.exists('dist/MultiPlatformGUI'):
|
||||
print("\nProduction build completed successfully!")
|
||||
print("Output directory: dist/MultiPlatformGUI/")
|
||||
print("All logging disabled - client will not generate log files")
|
||||
|
||||
# 验证关键文件
|
||||
# Verify key files
|
||||
exe_path = 'dist/MultiPlatformGUI/main.exe'
|
||||
if os.path.exists(exe_path):
|
||||
size = os.path.getsize(exe_path) / 1024 / 1024 # MB
|
||||
@@ -107,8 +130,8 @@ def main():
|
||||
print(f"ERROR: Build process error: {e}")
|
||||
|
||||
finally:
|
||||
# 3. 恢复日志功能(用于开发)
|
||||
print("\nRestoring development configuration...")
|
||||
# 3. Restore logging functionality (for development)
|
||||
print()
|
||||
restore_logging()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
|
||||
Reference in New Issue
Block a user