首页 > 代码库 > 配置比对脚本(python)

配置比对脚本(python)

技术分享
# -*- coding: utf-8 -*-from datetime import *import MySQLdbimport sysimport timeimport datetimeimport jsonimport logginglogging.basicConfig(level=logging.INFO,                format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s,                datefmt=%a, %d %b %Y %H:%M:%S,                filename=tb_test004.log,                filemode=w)console = logging.StreamHandler()console.setLevel(logging.INFO)formatter = logging.Formatter(%(name)-12s: %(levelname)-8s %(message)s)console.setFormatter(formatter)logging.getLogger(‘‘).addHandler(console)def process():    dict1 = {}    file1 = open("newlogic52.txt")    while 1:        line = file1.readline()        if not line:           break        arr_line = line.split(=, 1 );        if arr_line != None and len(arr_line) == 2:            #logging.info(arr_line[0])            #logging.info(arr_line[1])            key = arr_line[0]            value = arr_line[1]            dict1[key] = value        else:            continue        logging.info("-------------------------")    dict2 = {}    file2 = open("oldlogic52.txt")    while 1:        line = file2.readline()        if not line:           break        arr_line = line.split(=, 1 );        if arr_line != None and len(arr_line) == 2:            #logging.info(arr_line[0])            #logging.info(arr_line[1])            key = arr_line[0]            value = arr_line[1]            dict2[key] = value        else:            continue    f = file("hello3.txt","w+")    logging.info("************************")    sume = 0    for key1 in dict1:        #logging.info(key1)        #logging.info(dict1[key1])        for key2 in dict2:            # logging.info(key2)            # logging.info(dict2[key2])            if key1.strip() == key2.strip() and dict1[key1].strip() != dict2[key2].strip():                li1 = "new key:%s , value: %s \n" % (key1,dict1[key1])                #logging.info(li1)                li2 = "old key:%s , value: %s \n" % (key2,dict2[key2])                #logging.info(li2)            if key1.strip() == key2.strip() and dict1[key1].strip() == dict2[key2].strip():                sume = sume + 1            if key1.strip() == key2.strip() and dict1[key1].strip() == dict2[key2].strip():                li1 = "%s=%s\n" % (key1.strip(),dict1[key1].strip())                f.writelines(li1)    f.close()        dict3 = {}    file3 = open("hello3.txt")    while 1:        line = file3.readline()        if not line:           break        arr_line = line.split(=, 1 );        if arr_line != None and len(arr_line) == 2:            #logging.info(arr_line[0])            #logging.info(arr_line[1])            key = arr_line[0]            value = arr_line[1]            dict3[key] = value        else:            continue    for key2 in dict2:        # logging.info(key2)        # logging.info(dict3[key2])        if dict3[key2] == None:            logging.info(key2)    logging.info("@@@@@@@@@@@@@@@@@@@@@@@@@@")    logging.info(sume)    logging.info("new %s" % len(dict1))    logging.info("old %s" % len(dict2))    logging.info("same %s" % len(dict3))if __name__ == "__main__":   process()
View Code

 

配置比对脚本(python)