python diff

import sys,os
import filecmp
def testdiff(leftdir,rightdir):
    rf = filecmp.dircmp(leftdir,rightdir)
    _cmpdir(rf)
delete_files = []
copy_files = []
def _cmpdir(r):
    global delete_files,copy_files
    delete_files += [os.path.join(r.left,l) for l in r.left_only  if not l.startswith('.') ]
    copy_files += [os.path.join(r.left,l)+' '+os.path.join(r.right,l )for l in r.right_only if not l.startswith('.')]
    copy_files += [os.path.join(r.left,l)+' '+os.path.join(r.right,l) for l in r.diff_files if not l.startswith('.')]
    for sd in r.subdirs:
        if sd.find(".svn")==-1 :
            testdiff(os.path.join(r.left,sd),os.path.join(r.right,sd))
            print os.path.join(r.left,sd)
            print os.path.join(r.right,sd)
        else:
            pass

    return delete_files,copy_files
def printcopyfile(copyfile):
    global delete_files,copy_files
    for log in copy_files:
        output(log,"copylist")

def output(log,type):
    txtlog = log
    recordfile = os.path.join(sys.path[0]+'/'+type)
    try:
        fp = open(recordfile , "a+")
	print >>fp , txtlog
	fp.close()		
    except:
        pass 
def main():
    if len(sys.argv)>=3:
        testdiff(sys.argv[1],sys.argv[2])
    else:
        print "argv error"
    printcopyfile(copy_files)
    print delete_files
    print copy_files 
if __name__ == "__main__":
    main()

介绍请看 http://blog.csdn.net/csapr1987/article/details/7637933

生成copylist文件,


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值