- 将配置相关类移动到model模块 - 实现依赖注入容器管理各组件依赖关系 - 重构配置加载逻辑支持多层级键值查找 - 更新主应用入口支持命令行参数解析 - 统一日志输出格式替换原有打印语句 - 引入钻井实时数据模型简化数据处理 - 移除硬编码字段映射改用动态配置方式 - 优化数据库写入逻辑基于新的数据模型
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from urllib.parse import urlparse
|
|
|
|
from model import TdengineConfig
|
|
|
|
|
|
def parse_taos_url(jdbc_url):
|
|
if not jdbc_url:
|
|
return "", ""
|
|
raw = str(jdbc_url).strip()
|
|
if raw.lower().startswith("jdbc:taos-rs://"):
|
|
raw = "http://" + raw[len("jdbc:TAOS-RS://") :]
|
|
elif "://" not in raw:
|
|
raw = "http://" + raw
|
|
parsed = urlparse(raw)
|
|
base_url = f"{parsed.scheme or 'http'}://{parsed.hostname or '127.0.0.1'}:{parsed.port or 6041}"
|
|
database = (parsed.path or "").strip("/")
|
|
return base_url, database
|
|
|
|
|
|
def load_tdengine_config(cfg_or_app, default_device_code="GJ-304-0088"):
|
|
config = getattr(cfg_or_app, "tdengine", None)
|
|
if isinstance(config, TdengineConfig):
|
|
url = config.url
|
|
_, db_from_url = parse_taos_url(url)
|
|
if config.database:
|
|
return config
|
|
return TdengineConfig(
|
|
url=config.url,
|
|
username=config.username,
|
|
password=config.password,
|
|
database=db_from_url,
|
|
stable=config.stable,
|
|
device_code=config.device_code or default_device_code,
|
|
pool_size=config.pool_size,
|
|
timeout=config.timeout,
|
|
)
|
|
_, db_from_url = parse_taos_url("")
|
|
return TdengineConfig(database=db_from_url, device_code=default_device_code)
|
|
|
|
|
|
TDengineConfig = TdengineConfig
|