# -*- coding:utf-8 -*- # 配置管理模块 import json import os import yaml from typing import Dict, List, Any, Optional class ConfigManager: """配置管理类,负责加载和管理各种配置""" @staticmethod def load_json_config(config_path: str) -> Dict: """ 加载JSON格式的配置文件 Args: config_path: JSON配置文件路径 Returns: 加载的配置字典 """ try: with open(config_path, 'r', encoding='utf-8') as f: return json.load(f) except Exception as e: print(f"加载配置文件 {config_path} 失败: {str(e)}") return {} @staticmethod def load_yaml_config(config_path: str) -> Dict: """ 加载YAML格式的配置文件 Args: config_path: YAML配置文件路径 Returns: 加载的配置字典 """ try: with open(config_path, 'r', encoding='utf-8') as f: return yaml.safe_load(f) except Exception as e: print(f"加载配置文件 {config_path} 失败: {str(e)}") return {} @staticmethod def save_json_config(config_path: str, config_data: Dict) -> bool: """ 保存配置到JSON文件 Args: config_path: 目标JSON文件路径 config_data: 要保存的配置数据 Returns: 是否保存成功 """ try: os.makedirs(os.path.dirname(config_path), exist_ok=True) with open(config_path, 'w', encoding='utf-8') as f: json.dump(config_data, f, indent=4, ensure_ascii=False) return True except Exception as e: print(f"保存配置到 {config_path} 失败: {str(e)}") return False # 默认仓库配置 DEFAULT_REPO_CONFIGS = [ { "product": "V10-SP3-2403", "base_url": "https://update.cs2c.com.cn/private_test/repo/V10/V10SP3-2403/os/adv/lic/", "architectures": ["x86_64", "aarch64", "loongarch64"], "repo_types": ["updates"] }, { "product": "V10-SP3", "base_url": "https://update.cs2c.com.cn/private_test/repo/V10/V10SP3/os/adv/lic/", "architectures": ["x86_64", "aarch64", "loongarch64"], "repo_types": ["updates"] }, { "product": "V10-SP2", "base_url": "https://update.cs2c.com.cn/private_test/repo/V10/V10SP2/os/adv/lic/", "architectures": ["x86_64", "aarch64"], "repo_types": ["updates"] }, { "product": "V10-SP1.1", "base_url": "https://update.cs2c.com.cn/private_test/repo/V10/V10SP1.1/os/adv/lic/", "architectures": ["x86_64", "aarch64", "mips64el", "loongarch64"], "repo_types": ["updates"] }, # 其他仓库配置可以通过配置文件加载... ]