首页 > 代码库 > python3 实现对比conf 文件差异
python3 实现对比conf 文件差异
用法: ./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))
微信小额赞赏
本文出自 “净空蓝星” 博客,请务必保留此出处http://jingkonglanxing.blog.51cto.com/1152128/1886471
python3 实现对比conf 文件差异
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。