Initial commit
This commit is contained in:
12
scripts/utils/__init__.py
Normal file
12
scripts/utils/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
"""
|
||||
JADE Benchmark 辅助工具
|
||||
配置加载、文件处理等辅助功能
|
||||
"""
|
||||
from .config_loader import load_config, get_vm_config, get_network_config
|
||||
|
||||
__all__ = [
|
||||
'load_config',
|
||||
'get_vm_config',
|
||||
'get_network_config'
|
||||
]
|
||||
|
||||
51
scripts/utils/config_loader.py
Normal file
51
scripts/utils/config_loader.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
配置文件加载器
|
||||
"""
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user