- 新增 ForceUpdateCommand 类实现强制更新功能 - 添加 force-update CLI 命令支持 - 实现参数验证、配置对比、CDN缓存刷新 - 添加完整的测试用例和使用示例 - 更新文档和进度跟踪 - 支持模拟环境测试 - 添加警告提示和错误处理 主要文件: - src/config_man/core/force_update_command.py (新增) - src/config_man/cli/main.py (更新) - examples/test_force_update.py (新增) - examples/force_update_usage.py (新增) - docs/progress-tracker.md (更新)
189 lines
5.5 KiB
Python
189 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
强制更新功能使用示例
|
||
|
||
演示如何使用强制更新功能来直接更新目标版本的Ver属性。
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
from pathlib import Path
|
||
|
||
# 添加项目根目录到Python路径
|
||
project_root = Path(__file__).parent.parent
|
||
sys.path.insert(0, str(project_root))
|
||
|
||
from config_man.core.force_update_command import ForceUpdateCommand
|
||
from config_man.utils.mock_rclone import patch_rclone
|
||
|
||
|
||
def example_force_update_android():
|
||
"""示例:强制更新Android平台配置"""
|
||
print("📱 示例:强制更新Android平台配置")
|
||
print("-" * 50)
|
||
|
||
# 启用模拟环境
|
||
patch_rclone()
|
||
|
||
# 创建强制更新命令处理器
|
||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||
|
||
# 执行强制更新:将0.29版本的Ver属性更新为0.30版本的Ver值
|
||
success = force_cmd.execute(
|
||
platform="android",
|
||
target_version="0.29", # 目标版本
|
||
update_version="0.30" # 更新版本
|
||
)
|
||
|
||
if success:
|
||
print("✅ Android平台强制更新成功")
|
||
else:
|
||
print("❌ Android平台强制更新失败")
|
||
|
||
return success
|
||
|
||
|
||
def example_force_update_ios():
|
||
"""示例:强制更新iOS平台配置"""
|
||
print("\n🍎 示例:强制更新iOS平台配置")
|
||
print("-" * 50)
|
||
|
||
# 启用模拟环境
|
||
patch_rclone()
|
||
|
||
# 创建强制更新命令处理器
|
||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||
|
||
# 执行强制更新:将0.29版本的Ver属性更新为0.30版本的Ver值
|
||
success = force_cmd.execute(
|
||
platform="ios",
|
||
target_version="0.29", # 目标版本
|
||
update_version="0.30" # 更新版本
|
||
)
|
||
|
||
if success:
|
||
print("✅ iOS平台强制更新成功")
|
||
else:
|
||
print("❌ iOS平台强制更新失败")
|
||
|
||
return success
|
||
|
||
|
||
def example_force_update_with_custom_paths():
|
||
"""示例:使用自定义路径进行强制更新"""
|
||
print("\n🔧 示例:使用自定义路径进行强制更新")
|
||
print("-" * 50)
|
||
|
||
# 启用模拟环境
|
||
patch_rclone()
|
||
|
||
# 创建强制更新命令处理器,使用自定义路径
|
||
force_cmd = ForceUpdateCommand(
|
||
storage_path="custom/path", # 自定义存储路径
|
||
cdn_base_url="https://custom.cdn.com" # 自定义CDN URL
|
||
)
|
||
|
||
# 执行强制更新
|
||
success = force_cmd.execute(
|
||
platform="android",
|
||
target_version="0.28",
|
||
update_version="0.29"
|
||
)
|
||
|
||
if success:
|
||
print("✅ 自定义路径强制更新成功")
|
||
else:
|
||
print("❌ 自定义路径强制更新失败")
|
||
|
||
return success
|
||
|
||
|
||
def example_force_update_validation():
|
||
"""示例:参数验证功能"""
|
||
print("\n🔍 示例:参数验证功能")
|
||
print("-" * 50)
|
||
|
||
# 启用模拟环境
|
||
patch_rclone()
|
||
|
||
# 创建强制更新命令处理器
|
||
force_cmd = ForceUpdateCommand()
|
||
|
||
# 测试各种无效参数
|
||
test_cases = [
|
||
{
|
||
"name": "无效平台",
|
||
"params": ("invalid", "0.29", "0.30"),
|
||
"expected": False
|
||
},
|
||
{
|
||
"name": "无效版本格式",
|
||
"params": ("android", "invalid", "0.30"),
|
||
"expected": False
|
||
},
|
||
{
|
||
"name": "相同版本",
|
||
"params": ("android", "0.29", "0.29"),
|
||
"expected": False
|
||
},
|
||
{
|
||
"name": "有效参数",
|
||
"params": ("android", "0.29", "0.30"),
|
||
"expected": True
|
||
}
|
||
]
|
||
|
||
for test_case in test_cases:
|
||
print(f"测试: {test_case['name']}")
|
||
success = force_cmd.execute(*test_case['params'])
|
||
status = "✅ 通过" if success == test_case['expected'] else "❌ 失败"
|
||
print(f" 结果: {status}")
|
||
|
||
return True
|
||
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print("🚀 强制更新功能使用示例")
|
||
print("=" * 60)
|
||
|
||
# 运行所有示例
|
||
examples = [
|
||
("Android平台强制更新", example_force_update_android),
|
||
("iOS平台强制更新", example_force_update_ios),
|
||
("自定义路径强制更新", example_force_update_with_custom_paths),
|
||
("参数验证功能", example_force_update_validation),
|
||
]
|
||
|
||
results = []
|
||
for example_name, example_func in examples:
|
||
try:
|
||
result = example_func()
|
||
results.append((example_name, result))
|
||
except Exception as e:
|
||
print(f"❌ {example_name} 示例异常: {e}")
|
||
results.append((example_name, False))
|
||
|
||
# 显示结果
|
||
print("\n" + "=" * 60)
|
||
print("📊 示例执行结果:")
|
||
|
||
for example_name, result in results:
|
||
status = "✅ 成功" if result else "❌ 失败"
|
||
print(f" {example_name}: {status}")
|
||
|
||
print("\n💡 使用说明:")
|
||
print(" 1. 强制更新会直接修改目标版本的Ver属性")
|
||
print(" 2. 更新会立即影响使用该版本的应用")
|
||
print(" 3. 建议在更新前通知相关方")
|
||
print(" 4. 可以使用 --mock 参数进行测试")
|
||
|
||
print("\n🔧 CLI命令示例:")
|
||
print(" config-man force-update --platform android --target-version 0.29 --update-version 0.30")
|
||
print(" config-man force-update --platform ios --target-version 0.29 --update-version 0.30 --mock")
|
||
print(" config-man force-update --platform android --target-version 0.29 --update-version 0.30 --storage-path custom/path")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|