125 lines
3.5 KiB
Python
125 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
验证所有修改是否正确
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
|
|
def verify_config_file():
|
|
"""验证配置文件"""
|
|
print("验证配置文件 default.json")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
with open("default.json", 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
|
|
measurement = config.get('influx', {}).get('measurement', '')
|
|
|
|
if measurement == "Breaker":
|
|
print("OK measurement配置正确: Breaker")
|
|
else:
|
|
print(f"ERROR measurement配置错误: {measurement}")
|
|
|
|
return measurement == "Breaker"
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 读取配置文件失败: {e}")
|
|
return False
|
|
|
|
def verify_ui_config():
|
|
"""验证UI配置"""
|
|
print("\n验证UI监控器配置")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
with open("ui_main.py", 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 检查关键配置
|
|
checks = [
|
|
("measurement.*Breaker", "measurement默认值为Breaker"),
|
|
("load_status", "使用load_status字段"),
|
|
("status_field.*load_status", "status_field配置为load_status")
|
|
]
|
|
|
|
all_ok = True
|
|
for pattern, description in checks:
|
|
if pattern.replace(".*", "") in content:
|
|
print(f"OK {description}")
|
|
else:
|
|
print(f"ERROR 缺少 {description}")
|
|
all_ok = False
|
|
|
|
return all_ok
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 读取ui_main.py失败: {e}")
|
|
return False
|
|
|
|
def verify_test_script():
|
|
"""验证测试脚本"""
|
|
print("\n验证测试脚本 quick_test_data.py")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
with open("quick_test_data.py", 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 检查关键配置
|
|
checks = [
|
|
("measurement.*Breaker", "measurement默认值为Breaker"),
|
|
("load_status", "使用load_status字段"),
|
|
]
|
|
|
|
all_ok = True
|
|
for pattern, description in checks:
|
|
if pattern.replace(".*", "") in content:
|
|
print(f"OK {description}")
|
|
else:
|
|
print(f"ERROR 缺少 {description}")
|
|
all_ok = False
|
|
|
|
return all_ok
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 读取quick_test_data.py失败: {e}")
|
|
return False
|
|
|
|
def main():
|
|
print("验证配置修改")
|
|
print("=" * 40)
|
|
print("检查项目:")
|
|
print("1. datatype: Breaker")
|
|
print("2. field: load_status")
|
|
print("=" * 40)
|
|
|
|
# 验证各个组件
|
|
config_ok = verify_config_file()
|
|
ui_ok = verify_ui_config()
|
|
test_ok = verify_test_script()
|
|
|
|
print("\n" + "=" * 40)
|
|
print("验证总结:")
|
|
|
|
if config_ok and ui_ok and test_ok:
|
|
print("SUCCESS 所有配置修改正确!")
|
|
print("\n可以进行测试:")
|
|
print("1. 重启程序: python main.py")
|
|
print("2. 创建工单并进入等待状态")
|
|
print("3. 执行: echo 3 | python quick_test_data.py")
|
|
print("4. 观察监控器是否检测到 Breaker.load_status 变化")
|
|
else:
|
|
print("ERROR 存在配置问题,请检查上述错误")
|
|
|
|
if not config_ok:
|
|
print("- 配置文件问题")
|
|
if not ui_ok:
|
|
print("- UI配置问题")
|
|
if not test_ok:
|
|
print("- 测试脚本问题")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|