发布时间:2019-09-26 07:25:30编辑:auto阅读(2432)
用法: ./conf.py nginx1.conf nginx2.conf > diff.html
conf.py
#!/usr/bin/python
import difflib
import sys
#### Usage: compare_nginx.conf.py filename1 filename2 >diff.html
try:
textfile1 = sys.argv[1]
textfile2 = sys.argv[2]
except Exception as e:
print("Error: %s" % e)
print("Usage: compare_nginx.conf.py filename1 filename2 >diff.html")
sys.exit()
def readfile(filename):
try:
fileHandle = open(filename, 'r',encoding='gbk')
text = fileHandle.read().splitlines()
fileHandle.close()
return text
except IOError as error:
print("Read file Error: %s" % error)
sys.exit()
if 'textfile1' =="" or 'textfile2'=="":
print("Usage: compare_nginx.conf.py filename1 filename2 diff.html")
sys.exit()
text1_lines = readfile(textfile1)
text2_lines = readfile(textfile2)
d = difflib.HtmlDiff()
print(d.make_file(text1_lines, text2_lines))
上一篇: python3基础学习(base64编码
下一篇: python3 购物车小程序
51126
50520
41138
37981
32446
29348
28220
23064
23032
21357
1392°
2086°
1741°
1668°
1958°
1743°
2415°
4072°
3951°
2823°