av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

使用python檢查yaml配置文件是否符合要求

瀏覽:44日期:2022-07-30 16:54:09

我就廢話不多說了,大家還是直接看代碼吧!

# coding=utf-8 import loggingimport yamlimport osimport 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 loggingimport traceback import yamlimport osimport sysimport 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-(.*?).jar’, jar_ver) #txpacs的版本號 txpacs_version = jar_version.group(1) #docking-tools的版本號 dt_version = re.search(’DT_VERSIONS.*?'(.*?)'’,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_timestamp033[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.1033[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 編程
相關文章:
主站蜘蛛池模板: 在线国产小视频 | www亚洲精品 | 天天综合网天天综合色 | 日日摸天天添天天添破 | 国产资源在线视频 | 精品视频一区二区三区 | 中文字幕一区二区三区精彩视频 | 国产四区 | 一区二区三区国产精品 | 中文字幕一区二区三区四区 | 中午字幕在线观看 | 成人中文字幕在线 | 在线免费观看毛片 | 国产成人aⅴ | www视频在线观看 | 深夜福利亚洲 | 亚洲欧美日韩精品 | 亚洲三级免费看 | 人人九九精 | 在线看无码的免费网站 | 日韩欧美在 | 国产一二区视频 | 国产情侣久久 | 午夜三级视频 | 精品一区二区视频 | 久久99国产精品久久99果冻传媒 | 亚洲欧美一区二区三区国产精品 | 日本在线一二 | 国产一区二区麻豆 | 99久久成人 | 国产精品视频999 | 国产日韩精品一区 | 亚洲一区二区三区福利 | 99精品国产一区二区青青牛奶 | 亚洲第一网站 | 国产99小视频 | 在线看亚洲 | 日韩欧美亚洲 | 日本久久福利 | 国产亚洲一区二区三区在线 | 欧美国产亚洲一区二区 |