当前位置:网站首页>不同环境相同配置项的内容如何diff差异?
不同环境相同配置项的内容如何diff差异?
2022-07-04 21:58:00 【Wu_Candy】
Step1:分享背景
在工作中,我们用到的环境经常会有很多套,由于不同的环境使用的配置是不一样的,那么怎么能够对比所有不同环境的相同配置项各是什么内容呢?
Step2:Python代码实现
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
#指定java工程目录
dirpath="D:\java_project\entitystorage"
emails='[email protected]'
alldict={}
#获取所有文件里的key and value
def get_all_property(dirpath,env):
for root, dirs, files in os.walk(dirpath, topdown=False):
for fn in files:
fullpathfile=os.path.join(root, fn)
if(env in fullpathfile and "properties" in fullpathfile):
with open(fullpathfile,'r',encoding='utf-8') as ff:
print(ff)
for line in ff.readlines():
print(fullpathfile,line)
if(not line.startswith("#")):
line=line.replace("\n","")
if(len(line)>1):
if("=" in line):
kv=line.split("=")
get_all_properties(env, kv[0], kv[1])
else:
print("the "+str(fullpathfile) +"has an error!!!")
#将获取的key and value 内容放入字典
def get_all_properties(env,k,v):
if(env not in alldict.keys()):
alldict[env] = {}
alldict[env][k]=v
else:
alldict[env][k]=v
#在页面上展示不同环境的key 对应的值
def show_data_to_page(betadict,stagingdict,uatdict,proddict):
count=0
str1 = '<!DOCTYPE html> <html> <meta charset="utf-8"> <head> <style type="text/css"> table.gridtable {font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th {border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td {border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } </style> </head>';
str1 = str1 + '<body>'
str1 = str1 + ' <table class="gridtable">'
str1 = str1 + ' <tr> <th>key</th> <th>beta</th> <th>staging</th> <th>uat</th> <th>prod</th> <tr/> '
sorted_prod=sorted(proddict['prod'].items(), key=lambda d: d[0])
for pk,pv in sorted_prod:
count+=1
print(count,pk,pv)
if(pk in betadict['betamagic'].keys()):
try:
if(len(betadict['betamagic'][pk])>0):
bv=betadict['betamagic'][pk]
if(str(pv).lower()==str(bv).lower()):
bv="<p style='color:blue'><B>"+bv+"</B>"
else:
bv = "None"
except:
bv="None"
else:
bv="None"
if (pk in stagingdict['staging'].keys()):
try:
if (len(stagingdict['staging'][pk]) > 0):
sv = stagingdict['staging'][pk]
if (str(pv).lower() == str(sv).lower()):
sv = "<p style='color:blue'><B>" + sv + "</B>"
else:
sv = "None"
except:
sv = "None"
else:
sv = "None"
if (pk in uatdict['uat'].keys()):
try:
if (len(uatdict['uat'][pk]) > 0):
uv = uatdict['uat'][pk]
if (str(pv).lower() == str(uv).lower()):
uv = "<p style='color:blue'><B>" + uv + "</B>"
else:
uv = "None"
except:
uv = "None"
else:
uv = "None"
str1+='<tr> <td>' + str(count)+" . "+ pk + '</td> <td>' + bv + '</td> <td>' + sv + '</td> <td>' + uv + '</td> <td>' + pv + '</td> <tr/>'
str1 = str1 + ' </table>'
str1 = str1 + '</body> </html>'
str1=str1.replace("None","<p style='color:green'><B>None</B>")
send_mail(emails, 'diff the properties', str1)
def send_mail(receivers, title, content):
sender = '[email protected]'
mailto = receivers.split(",")
try:
msg = MIMEMultipart()
msg['Subject'] = title
to_user = ",".join(mailto)
print("receivers...", to_user)
msg['to'] = to_user
msg['From'] = sender
body = MIMEText(content, _subtype='html', _charset='utf-8')
msg.attach(body)
smtp = smtplib.SMTP('smtp.officexxx.com', 587)
smtp.starttls()
print("sending")
smtp.login("[email protected]", "testkyjrsdxz")
smtp.sendmail(sender, mailto, msg.as_string())
print("send")
smtp.quit()
except smtplib.SMTPException as e:
print(e)
if __name__ == '__main__':
get_all_property(dirpath,"betamagic")
betadict=alldict
print(betadict)
alldict={}
print("***")
get_all_property(dirpath,"staging")
stagingdict = alldict
print(stagingdict)
alldict = {}
get_all_property(dirpath,"uat")
uatdict = alldict
print(uatdict)
alldict = {}
get_all_property(dirpath,"prod")
proddict = alldict
print(proddict)
show_data_to_page(betadict,stagingdict,uatdict,proddict)
Step3:邮件效果图展示
备注说明:
1. 图中红色表示live环境有对应项,但是其他环境没有的。
2. 图中蓝色表示非live环境与live配置相同的。
end
边栏推荐
- Force buckle 2_ 1480. Dynamic sum of one-dimensional array
- 什么是商业智能(BI),就看这篇文章足够了
- gtest从一无所知到熟练运用(1)gtest安装
- 赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
- With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
- Open3d surface normal vector calculation
- New intersectionobserver usage notes
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- php短视频源码,点赞时会有大拇指动画飘起
- el-tree结合el-table,树形添加修改操作
猜你喜欢

Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel

VS2019 C# release下断点调试

B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条

TCP protocol three times handshake process

From repvgg to mobileone, including mobileone code

HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙

KDD2022 | 什么特征进行交互才是有效的?

Locust性能测试 —— 环境搭建及使用

国产数据库乱象

DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
随机推荐
好用app推荐:扫描二维码、扫描条形码并查看历史
复数在数论、几何中的用途 - 曹则贤
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
MongoDB中的索引操作总结
HDU - 2859 Phalanx(DP)
力扣2_1480. 一维数组的动态和
WebGIS框架---kalrry
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
抖音实战~评论数量同步更新
283. 移动零-c与语言辅助数组法
淘宝商品评价api接口(item_review-获得淘宝商品评论API接口),天猫商品评论API接口
服装企业为什么要谈信息化?
从RepVgg到MobileOne,含mobileone的代码
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
1807. Replace the parentheses in the string
PMO:比较25种分子优化方法的样本效率
时空预测3-graph transformer
ACM Multimedia 2022 | 视觉语言预训练模型中社会偏见的反事实衡量和消除
【Acwing】第58场周赛 题解
Spatiotemporal prediction 3-graph transformer