Files
sci-gui-agent-benchmark/scripts/utils/config_loader.py
2026-01-12 18:30:12 +08:00

52 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
配置文件加载器
"""
import json
import os
def load_config(config_path=None):
"""
加载配置文件
Args:
config_path: 配置文件路径默认在项目根目录的config.json
Returns:
dict: 配置字典
"""
if config_path is None:
# 查找项目根目录的config.json
current_dir = os.path.dirname(os.path.abspath(__file__))
scripts_dir = os.path.dirname(current_dir) # scripts/
project_root = os.path.dirname(scripts_dir) # Jade-BenchMark-MVP/
config_path = os.path.join(project_root, "config.json")
if not os.path.exists(config_path):
raise FileNotFoundError(f"配置文件不存在: {config_path}")
with open(config_path, 'r', encoding='utf-8') as f:
return json.load(f)
def get_vm_config(config=None):
"""获取VM配置"""
if config is None:
config = load_config()
return config.get('vmware', {})
def get_network_config(config=None):
"""获取网络配置"""
if config is None:
config = load_config()
return config.get('network', {})
if __name__ == "__main__":
# 测试配置加载
config = load_config()
print("配置加载成功:")
print(json.dumps(config, indent=2, ensure_ascii=False))