我就废话不多说了,大家还是直接看代码吧!
# coding=utf-8
import logging
import yaml
import os
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
# 获取当前目录的路径
cur_dir = os.path.abspath('.')
def check_dt_pacsscp(config):
"""
用来检查文件配置是否正确
"""
#将配置config.yaml配置文件以字典方式读取
dts_method = config['service']['method']
dts_dup_check = config['service']['pacsscp_dup_check_off']
dts_interval = config['scheduler']['interval']
#判断对接方式是否是pacsscp
if dts_method == 'pacsscp':
if dts_dup_check == True and dts_interval == 3:
return True
else:
return False
else:
#打印error级别的错误
print "\033[31m Error:method not is pacsscp!!!\033[0m"
return False
if __name__ == "__main__":
# 加载yaml配置
config_yaml = os.path.join(cur_dir, 'config.yaml')
with open(config_yaml, 'rt') as f:
config = yaml.safe_load(f.read())
#dt相关路径和配置
dt_path = config['path']['docking-toolbox']
dt_config_path = os.path.join(dt_path, 'config.yaml')
with open(dt_config_path, 'rt') as f:
dt_config = yaml.safe_load(f.read())
if check_dt_pacsscp(dt_config):
print (u"\033[32m 校验通过~\033[0m")
else:
print (u'\033[32m 校验未通过, 请检查配置!\033[0m ')
以下是用正则获取不是yaml配置文件的
# coding=utf-8
"""
作业要求, 完善check_txpacs_version函数
"""
import logging
import traceback
import yaml
import os
import sys
import re
reload(sys)
sys.setdefaultencoding("utf-8")
# 获取当前目录的路径
cur_dir = os.path.abspath('.')
def check_txpacs_version(config, constant):
"""
高难度
校验txpacs版本, 若版本<1.4, 则回调中不能出现received_start_timestamp和received_end_timestamp这两个参数,
若不合法打印error级别的提示;
校验txpacs的自动清理功能是否合法: 若dt版本<1.3.8, 则不做要求,
若dt版本>=1.3.8, 则要求txpacs版本必须为1.5.1及以上版本, 且txpacs配置的clean_date需配置为正整数
(docking-toolbox的版本号可以从文件'docking-toolbox/toolbox/utils/constant.py'中读取),
若不合法打印error级别的提示.
根据以上结果, 返回返回值.
:param config: txpacs的配置
:param constant: docking-toolbox/toolbox/utils/constant.py文件内容
:return: True: 通过
False: 不通过
"""
# 获取txpacs的版本号
jar_file = os.listdir(txpacs_path)
jar_file.sort(reverse=True)
jar_ver = jar_file[0]
jar_version = re.search('txpacs-(.*"(.*"',constant).group(1)
#打开txpacs的配置文件
with open(txpacs_config_path, 'rt') as f:
txpacs_file = f.read()
#判断txpacs的版本号是否小于1.4
if txpacs_version < '1.4':
#判断received_start_timestamp" and "received_end_timestamp"两个参数是否出现在txpacs配置文件中
if "received_start_timestamp" and "received_end_timestamp" not in txpacs_file:
return True
else:
print "\033[31m Error:当前的txpacs版本号是txpacs-%s ,不应该存在received_start_timestamp和received_end_timestamp\033[0m"%txpacs_version
return False
#如果txpacs版本号大于等于1.4
else:
#判断DT版本是否大于1.3.8
if dt_version >= '1.3.8':
if txpacs_version >= '1.5.1':
if config['store']['clean_date'] > 0:
return True
else:
print "\033[31m Error:txpacs配置文件中clean_date应为正整数 \033[0m"
return False
else:
print "\033[31m Error:当前DT版本大于1.3.8,txpacs版本必须大于等于1.5.1\033[0m"
return False
else:
return True
if __name__ == "__main__":
# 加载yaml配置
config_yaml = os.path.join(cur_dir, 'config.yaml')
with open(config_yaml, 'rt') as f:
config = yaml.safe_load(f.read())
# txpacs相关路径和配置
txpacs_path = config['path']['txpacs']
txpacs_config_path = os.path.join(txpacs_path, 'conf.yml')
with open(txpacs_config_path, 'rt') as f:
txpacs_config = yaml.safe_load(f.read())
# dt相关路径和配置
dt_path = config['path']['docking-toolbox']
dt_constant_path = os.path.join(dt_path, 'toolbox', 'utils', 'constant.py')
with open(dt_constant_path, 'rt') as f:
dt_constant = f.read()
if check_txpacs_version(txpacs_config, dt_constant):
print (u"\033[32m 校验通过~\033[0m")
else:
print (u'\033[32m 校验未通过, 请检查配置! \033[0m')
以上这篇使用python检查yaml配置文件是否符合要求就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
python,yaml,配置文件
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“使用python检查yaml配置文件是否符合要求”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
2025年10月25日
2025年10月25日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]