-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfig_manager.py
More file actions
25 lines (21 loc) · 963 Bytes
/
config_manager.py
File metadata and controls
25 lines (21 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import yaml
import os
from typing import Dict, Any
class ConfigManager:
def __init__(self, config_path: str = "config.yaml"):
self.config_path = config_path
self.config = self._load_config()
def _load_config(self) -> Dict[str, Any]:
"""加载配置文件"""
try:
if not os.path.exists(self.config_path):
raise FileNotFoundError(f"Configuration file not found: {self.config_path}")
with open(self.config_path, 'r', encoding='utf-8') as f:
return yaml.safe_load(f)
except Exception as e:
raise RuntimeError(f"Failed to load configuration: {str(e)}")
def get_service_config(self, service: str) -> Dict[str, Any]:
"""获取指定服务的配置"""
if not self.config or service not in self.config:
raise ValueError(f"Configuration for service '{service}' not found")
return self.config[service]