82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
|
|
#!/usr/bin/env python
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
检查配置文件中的全局参数
|
|||
|
|
"""
|
|||
|
|
import json
|
|||
|
|
from pathlib import Path
|
|||
|
|
from config_model import AppConfig
|
|||
|
|
|
|||
|
|
print("=" * 80)
|
|||
|
|
print("检查配置文件中的全局参数")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
# 检查 default.json
|
|||
|
|
default_config_path = Path(__file__).parent / "default.json"
|
|||
|
|
if default_config_path.exists():
|
|||
|
|
print(f"\n✅ 找到配置文件: {default_config_path}")
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
config = AppConfig.load(default_config_path)
|
|||
|
|
|
|||
|
|
print("\n配置对象信息:")
|
|||
|
|
print(f" - 有 globalParameters 属性: {hasattr(config, 'globalParameters')}")
|
|||
|
|
|
|||
|
|
if hasattr(config, 'globalParameters'):
|
|||
|
|
print(f" - globalParameters 不为空: {config.globalParameters is not None}")
|
|||
|
|
|
|||
|
|
if config.globalParameters:
|
|||
|
|
print(f" - 有 parameters 属性: {hasattr(config.globalParameters, 'parameters')}")
|
|||
|
|
|
|||
|
|
if hasattr(config.globalParameters, 'parameters'):
|
|||
|
|
params = config.globalParameters.parameters
|
|||
|
|
print(f" - parameters 不为空: {params is not None}")
|
|||
|
|
|
|||
|
|
if params:
|
|||
|
|
print(f"\n全局参数内容:")
|
|||
|
|
for key, value in params.items():
|
|||
|
|
print(f" {key}: {value}")
|
|||
|
|
else:
|
|||
|
|
print("\n⚠️ parameters 为空")
|
|||
|
|
else:
|
|||
|
|
print("\n⚠️ globalParameters 没有 parameters 属性")
|
|||
|
|
else:
|
|||
|
|
print("\n⚠️ globalParameters 为 None")
|
|||
|
|
else:
|
|||
|
|
print("\n⚠️ 配置对象没有 globalParameters 属性")
|
|||
|
|
|
|||
|
|
# 直接读取 JSON 文件查看原始内容
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("原始 JSON 文件内容(globalParameters 部分):")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
with open(default_config_path, 'r', encoding='utf-8') as f:
|
|||
|
|
raw_json = json.load(f)
|
|||
|
|
|
|||
|
|
if 'globalParameters' in raw_json:
|
|||
|
|
print(json.dumps(raw_json['globalParameters'], ensure_ascii=False, indent=2))
|
|||
|
|
else:
|
|||
|
|
print("⚠️ JSON 文件中没有 globalParameters 字段")
|
|||
|
|
print("\n建议添加以下内容到配置文件:")
|
|||
|
|
print("""
|
|||
|
|
{
|
|||
|
|
"globalParameters": {
|
|||
|
|
"parameters": {
|
|||
|
|
"runin_date": "2025-12-10",
|
|||
|
|
"operator_name": "操作员姓名",
|
|||
|
|
"power_end_part_no": "零件编号",
|
|||
|
|
"motor_speed_rpm": "980"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
""")
|
|||
|
|
|
|||
|
|
except Exception as e:
|
|||
|
|
print(f"\n❌ 加载配置失败: {e}")
|
|||
|
|
import traceback
|
|||
|
|
traceback.print_exc()
|
|||
|
|
else:
|
|||
|
|
print(f"\n❌ 配置文件不存在: {default_config_path}")
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|