导出SVN中修改过和新增的未提交的文件

#!/usr/bin/python
# coding=utf-8

import shutil,os

isCover = True
newName = ""

# needCheckDir = "G:\\G116Project\\gui" #需要检查的路径
needCheckDir = "C:\\file1" #需要检查的路径
createfile = "C:\\file2" #需要拷贝到的目录

#路径初始化
def pathInit(path):
	if path == "":
		path = ".\\img"
	else:
		findS = "\\" in path
		if not findS:
			path = ".\\" + path
	return path

#输入文件路径判断是否存在,如果不存在就创建
def findPathAndCreate(pathName):
	global createfile
	path = os.path.abspath(createfile)
	splitStr = pathName.split(":", 1)
	splitStr = os.path.dirname(splitStr[1])
	splitStr = splitStr.split("\\", -1)
	for x in splitStr:
		if x != "":
			path = path + "\\" + x
			if not os.path.exists(path):
				os.mkdir(path)		

def execCmd(cmd):  
    r = os.popen(cmd)  
    text = r.read()  
    r.close()  
    return text 

def findStrPath(path):
	strP = ""
	isPath = False
	attrBefore = None
	for attr in path:
		if attrBefore and attr == ":":
			isPath = True
			strP = attrBefore + attr
		elif isPath :
			if attr != " ":
				strP = strP + attr
			else:
				isPath = False
		attrBefore = attr
	return strP


#复制图片
def copyImg(_createfile):
	global isCover
	global needCheckDir
	fileNum = 0

	print("start copying files ... ...")

	copyList = []
	changeFileStr = getCmdInfo(needCheckDir)
	changeFileInfo = changeFileStr.split("\n")
	g = os.walk(needCheckDir, topdown=True)  
	for path,dir_list,file_list in g:
	    for file_name in file_list:
	    	if path == _createfile:
	    		continue

    		isChangeFile = False
    		pathName = os.path.join(path, file_name)
	    	for changeName in changeFileInfo:
	    		changeName = findStrPath(changeName)
	    		if changeName == pathName:
	    			isChangeFile = True
    				findPathAndCreate(pathName)
	    			break

	    	if isChangeFile:
	    		pathName2 = _createfile+pathName.split(":")[1]
	    		if pathName != pathName2:
	    			fileNum = fileNum + 1
    				shutil.copy(pathName, pathName2)
	    			copyList.append("copy:" + pathName + " To " + pathName2)
    		else:
    			print("unchanged file:" + pathName)
	print("\ncopy file info:")
	for x in copyList:
		print(x)
	endStr = "File successfully copied: "
	print(("\n"+endStr+_createfile+" , Total number of copied files: %d"+"\n")%(fileNum))

def getCmdInfo(path):
	cmd = "svn status " + path
	return execCmd(cmd)

if __name__ == '__main__': 
	createfile = pathInit(createfile)	    			
	copyImg(createfile)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值