码迷,mamicode.com
首页 > 编程语言 > 详细

配置比对脚本(python)

时间:2016-12-09 08:34:25      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:imp   evel   mysq   inf   split   code   isp   tar   技术   

技术分享
# -*- coding: utf-8 -*-
from datetime import *
import MySQLdb
import sys
import time
import datetime
import json
import logging

logging.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)

标签:imp   evel   mysq   inf   split   code   isp   tar   技术   

原文地址:http://www.cnblogs.com/super-d2/p/6147953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!