当前位置:网站首页>How diff are the contents of the same configuration item in different environments?
How diff are the contents of the same configuration item in different environments?
2022-07-04 22:22:00 【Wu_ Candy】
Step1: Share the background
At work , The environment we use often has many sets , Because different environments use different configurations , So how can we compare the same configuration items of all different environments ?
Step2:Python Code implementation
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
# Appoint java Project directory
dirpath="D:\java_project\entitystorage"
emails='[email protected]'
alldict={}
# Get all files 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!!!")
# To obtain the key and value Put the content into the dictionary
def get_all_properties(env,k,v):
if(env not in alldict.keys()):
alldict[env] = {}
alldict[env][k]=v
else:
alldict[env][k]=v
# Show different environments on the page key Corresponding value
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: E-mail rendering
Remarks :
1. Red in the figure indicates live Environment has corresponding items , But not in other environments .
2. Blue in the figure indicates non live Environment and live Same configuration .
end
边栏推荐
- 时空预测3-graph transformer
- 湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
- 2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
- 微服务--开篇
- Bizchart+slider to realize grouping histogram
- 面试必备 LeetCode 链表算法题汇总,全程干货!
- B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
- # 2156. 查找给定哈希值的子串-后序遍历
- From repvgg to mobileone, including mobileone code
- Shell 脚本实现应用服务日志入库 Mysql
猜你喜欢
Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
什么是商业智能(BI),就看这篇文章足够了
[advanced C language] array & pointer & array written test questions
HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
Huawei Nova 10 series released Huawei application market to build a solid application security firewall
Common open source codeless testing tools
Concurrent network modular reading notes transfer
复数在数论、几何中的用途 - 曹则贤
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
Convolutional neural network model -- lenet network structure and code implementation
随机推荐
电话加密,中间4为****代替
Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
PostgreSQL JOIN实践及原理
sqlserver对数据进行加密、解密
Interview question 01.08 Zero matrix
力扣98:验证二叉搜索树
Force buckle 3_ 383. Ransom letter
力扣_回文数
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
Solana链上应用Crema因黑客攻击停运
HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
力扣3_383. 赎金信
Machine learning notes mutual information
Spatiotemporal prediction 3-graph transformer
好用app推荐:扫描二维码、扫描条形码并查看历史
并列图的画法,多排多列
Interview question 01.01 Determine whether the character is unique
Domestic database chaos
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7