增加logid

#str2file
import os


def checkrepeat(srclist,checkstr):
    if not srclist:
        return -1
    if len(checkstr) == 0:
        return -1
    for i in srclist:
        i = i.strip()
        checkstr = checkstr.strip()
        if checkstr == i:
            return 1
    return 0


def str2file(strlist,input_file):
    if not os.path.isfile(input_file):
        print "The input file is not exist,Please check it!"
        return -1
    if not strlist:
        print "You Can not create the new logid,Please check it!"
        return -1
    file = open(input_file,"r")
    contentlist = file.readlines()
    file.close()
    flag1  = False
    flag2  = False
    count  = 0
    for i in contentlist:
        pos = i.find("TLOG_FFFF")
        if pos >= 0:
            for j in strlist:
                #print "j = ",j
                ret = checkrepeat(contentlist,j)
                #print "############ret = ",ret
                if ret == 1:
                    count += 1
                    continue;
                if j != str[len(strlist)-1]:
                    contentlist.insert(contentlist.index(i),j)
                    flag1 = True
                else:
                    contentlist.insert(contentlist.index(i),j+'\n')
                    flag2 = True
        if flag1 or flag2:
            break
    
    content = ''.join(contentlist)
    file = open(input_file,"w")
    file.write(content)
    file.close()


    if flag1 or flag2:
        print "Add the logid successfully!"
    else:
        print "Add the logid faild,Because of it have " +str(count)+" repeat logids,Please check it!"
    return 0




if __name__ == "__main__":
    file = open("D:\Python_Learning\code.txt","r")  
    logstr = file.readlines()
    logfilename = r"D:\Python_Learning\logid.h"
    if not os.path.isfile(logfilename):
        print ("The logid.h is not exist")
    ret = str2file(logstr,logfilename)
    if ret != 0:
        print ("Add logdid faild ")
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值