You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
5.1 KiB
193 lines
5.1 KiB
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
MagicWord 0.2.1 手动发布包创建脚本
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import zipfile
|
|
from datetime import datetime
|
|
|
|
def create_manual_package():
|
|
"""创建手动发布包"""
|
|
print("创建 MagicWord 0.2.1 手动发布包...")
|
|
|
|
# 创建发布目录
|
|
release_dir = "dist_package"
|
|
if os.path.exists(release_dir):
|
|
shutil.rmtree(release_dir)
|
|
os.makedirs(release_dir)
|
|
|
|
# 复制主要文件
|
|
files_to_copy = [
|
|
("README.md", "README.md"),
|
|
("CHANGELOG.md", "CHANGELOG.md"),
|
|
("requirements.txt", "requirements.txt"),
|
|
("setup.py", "setup.py"),
|
|
("install_and_fix.py", "install_and_fix.py"),
|
|
]
|
|
|
|
for src, dst in files_to_copy:
|
|
if os.path.exists(src):
|
|
shutil.copy2(src, os.path.join(release_dir, dst))
|
|
print(f"复制: {src} -> {dst}")
|
|
else:
|
|
print(f"警告: 文件 {src} 不存在")
|
|
|
|
# 复制源代码
|
|
src_dir = os.path.join(release_dir, "src")
|
|
if os.path.exists("src"):
|
|
shutil.copytree("src", src_dir)
|
|
print("复制源代码目录")
|
|
else:
|
|
print("警告: src 目录不存在")
|
|
|
|
# 复制资源文件
|
|
resources_dir = os.path.join(release_dir, "resources")
|
|
if os.path.exists("resources"):
|
|
shutil.copytree("resources", resources_dir)
|
|
print("复制资源文件目录")
|
|
else:
|
|
print("警告: resources 目录不存在")
|
|
|
|
# 创建运行脚本
|
|
run_bat = """@echo off
|
|
echo MagicWord 0.2.1 启动中...
|
|
cd /d "%~dp0"
|
|
python src/main.py
|
|
pause
|
|
"""
|
|
|
|
run_sh = """#!/bin/bash
|
|
echo "MagicWord 0.2.1 启动中..."
|
|
cd "$(dirname "$0")"
|
|
python3 src/main.py
|
|
"""
|
|
|
|
with open(os.path.join(release_dir, "run.bat"), "w", encoding="utf-8") as f:
|
|
f.write(run_bat)
|
|
|
|
with open(os.path.join(release_dir, "run.sh"), "w", encoding="utf-8") as f:
|
|
f.write(run_sh)
|
|
|
|
# 创建安装脚本
|
|
install_bat = """@echo off
|
|
echo 正在安装 MagicWord 0.2.1 依赖...
|
|
python -m pip install -r requirements.txt
|
|
echo 安装完成!
|
|
pause
|
|
"""
|
|
|
|
with open(os.path.join(release_dir, "install.bat"), "w", encoding="utf-8") as f:
|
|
f.write(install_bat)
|
|
|
|
# 创建发布说明
|
|
release_info = f"""MagicWord 0.2.1 手动发布包
|
|
构建时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
|
|
安装和运行说明:
|
|
|
|
1. 安装依赖:
|
|
- Windows: 运行 install.bat
|
|
- Linux/Mac: pip install -r requirements.txt
|
|
|
|
2. 运行应用:
|
|
- Windows: 运行 run.bat
|
|
- Linux/Mac: 运行 run.sh 或 python3 src/main.py
|
|
|
|
3. 主要功能:
|
|
- 完整的天气功能集成
|
|
- 自动IP定位功能
|
|
- 40+个城市支持
|
|
- 中英文城市名智能映射
|
|
- Microsoft Word风格界面
|
|
- 每日一言功能集成
|
|
- 附加工具菜单(原天气信息菜单重命名)
|
|
|
|
详细更新请查看 CHANGELOG.md
|
|
|
|
注意: 需要Python 3.6+环境
|
|
"""
|
|
|
|
with open(os.path.join(release_dir, "RELEASE_INFO.txt"), "w", encoding="utf-8") as f:
|
|
f.write(release_info)
|
|
|
|
# 创建ZIP包
|
|
zip_name = f"MagicWord_v0.2.1_Manual_Package.zip"
|
|
with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
|
for root, dirs, files in os.walk(release_dir):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
arc_name = os.path.relpath(file_path, release_dir)
|
|
zipf.write(file_path, arc_name)
|
|
|
|
print(f"\n发布包创建成功: {zip_name}")
|
|
print(f"包含文件数量: {sum(len(files) for _, _, files in os.walk(release_dir))}")
|
|
|
|
return True
|
|
|
|
def verify_package():
|
|
"""验证发布包内容"""
|
|
print("\n验证发布包内容...")
|
|
|
|
release_dir = "dist_package"
|
|
if not os.path.exists(release_dir):
|
|
print("发布目录不存在")
|
|
return False
|
|
|
|
# 检查关键文件
|
|
required_files = [
|
|
"README.md",
|
|
"CHANGELOG.md",
|
|
"requirements.txt",
|
|
"src/main.py",
|
|
"src/ui/word_style_ui.py",
|
|
"run.bat",
|
|
"run.sh",
|
|
"install.bat",
|
|
"RELEASE_INFO.txt"
|
|
]
|
|
|
|
missing_files = []
|
|
for file_path in required_files:
|
|
full_path = os.path.join(release_dir, file_path)
|
|
if os.path.exists(full_path):
|
|
print(f"✓ {file_path}")
|
|
else:
|
|
print(f"✗ {file_path}")
|
|
missing_files.append(file_path)
|
|
|
|
if missing_files:
|
|
print(f"\n缺失文件: {', '.join(missing_files)}")
|
|
return False
|
|
|
|
print("\n发布包验证通过!")
|
|
return True
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("=" * 60)
|
|
print("MagicWord 0.2.1 手动发布包创建工具")
|
|
print("=" * 60)
|
|
|
|
# 创建发布包
|
|
if not create_manual_package():
|
|
print("发布包创建失败")
|
|
return 1
|
|
|
|
# 验证发布包
|
|
if not verify_package():
|
|
print("发布包验证失败")
|
|
return 1
|
|
|
|
print("\n" + "=" * 60)
|
|
print("手动发布包创建完成!")
|
|
print("用户需要手动安装Python依赖并运行应用")
|
|
print("=" * 60)
|
|
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
import sys
|
|
sys.exit(main()) |