- Updated `Config.json` to change encryption keys and update version to 1.2.4.1. - Modified `GetApi.py` and `LogApi.py` for improved code readability and consistency. - Enhanced `decryptOpt.py` with better structure and error handling. - Refactored `downLib` modules for improved exception handling and code clarity. - Added `readCFG.py` for server configuration and keychip retrieval from SQLite database. - Updated `zip.PY` for better error handling and code consistency.
83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
import json
|
||
import os
|
||
import subprocess
|
||
import datetime
|
||
import sys
|
||
|
||
|
||
def main():
|
||
# 检查7z工具是否存在
|
||
seven_zip_path = os.path.join("Lib", "7z", "7z.exe")
|
||
if not os.path.exists(seven_zip_path):
|
||
print(f"错误: 7z工具未在 {seven_zip_path} 找到")
|
||
sys.exit(1)
|
||
|
||
# 读取版本号(处理编码问题)
|
||
config_path = "./DataBase/Config.json"
|
||
if not os.path.exists(config_path):
|
||
print(f"错误: 配置文件 {config_path} 不存在")
|
||
sys.exit(1)
|
||
|
||
try:
|
||
# 先以二进制模式读取,再检测编码
|
||
with open(config_path, "rb") as f:
|
||
raw_data = f.read()
|
||
|
||
# 尝试检测常见编码
|
||
for encoding in ["utf-8", "gbk", "latin-1"]:
|
||
try:
|
||
config = json.loads(raw_data.decode(encoding))
|
||
version = config.get("version")
|
||
if version:
|
||
break
|
||
except (UnicodeDecodeError, json.JSONDecodeError):
|
||
continue
|
||
else:
|
||
raise ValueError("无法确定文件编码")
|
||
|
||
if not version:
|
||
print("错误: 配置文件中未找到 version 字段")
|
||
sys.exit(1)
|
||
|
||
except Exception as e:
|
||
print(f"读取配置文件失败: {str(e)}")
|
||
sys.exit(1)
|
||
|
||
# 生成时间戳
|
||
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||
zip_name = f"MaiTec_Ver{version}_{timestamp}.zip"
|
||
|
||
# 构建7z命令(使用正斜杠确保跨平台兼容)
|
||
cmd = [
|
||
seven_zip_path,
|
||
"a", # 添加文件
|
||
"-tzip", # 压缩为ZIP格式
|
||
zip_name,
|
||
".", # 当前目录
|
||
]
|
||
|
||
# 执行压缩命令
|
||
try:
|
||
print(f"开始压缩: {zip_name}...")
|
||
result = subprocess.run(
|
||
cmd,
|
||
stdout=subprocess.PIPE,
|
||
stderr=subprocess.PIPE,
|
||
text=True,
|
||
encoding="utf-8",
|
||
errors="replace",
|
||
check=True,
|
||
)
|
||
print("压缩成功完成!")
|
||
print(f"输出信息: {result.stdout}")
|
||
except subprocess.CalledProcessError as e:
|
||
print(f"压缩失败: {e.stderr}")
|
||
sys.exit(1)
|
||
except Exception as e:
|
||
print(f"执行过程中出错: {str(e)}")
|
||
sys.exit(1)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|